Thursday, June 19, 2014

codechef SAD - gift rift solution

codechef SAD - gift rift: http://www.codechef.com/problems/SAD

codechef SAD - gift rift editorial: http://discuss.codechef.com/questions/1591/sad-editorial

codechef SAD - gift rift solution: http://ideone.com/ZxgVo4


#include <iostream>
#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std;

int a[105][105];

int main() {
    int r, c, mi, ma, cnt;
    scanf("%d%d", &r, &c);
    for(int i=0; i<r; i++) for(int j=0; j<c; j++) scanf("%d", &a[i][j]);
    for(int i=0; i<r; i++) {
        mi=INT_MAX, ma=INT_MIN;
        for(int j=0; j<c; j++) {
            mi=min(mi, a[i][j]);
        }
        for(int j=0; j<c; j++) {
            if(a[i][j]==mi) {
                cnt=0;
                for(int k=0; k<r; k++) if(mi>=a[k][j]) cnt++;
                if(cnt==r) {printf("%d", mi); return 0;}
            }
        }
    }
    printf("GUESS");
    return 0;
}

note: try this input
2 3
1 1 1
2 2 2

No comments:

Post a Comment