Advertisement
fahimkamal63

Row with minimum 1's

Jun 21st, 2019
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<climits>
  4. using namespace std;
  5.  
  6. int main(){
  7.     int t; scanf("%d", &t);
  8.     while(t--){
  9.         int n, m; scanf("%d %d", &n, &m);
  10.         int a[n][m], i,j;
  11.         int ans = INT_MAX, index = -1;
  12.         for(i = 0; i < n; i++){
  13.             int num = 0;
  14.             for(j = 0; j < m; j++){
  15.                 int k; scanf("%d", &k);
  16.                 if(k == 1) num++;
  17.             }
  18.             if(num < ans && num != 0){
  19.                 ans = num;
  20.                 index = i;
  21.             }
  22.         }
  23.         if(ans == 0) cout << "-1\n";
  24.         else cout << index << endl;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement