페이지

2456번: 나는 학급회장이다

https://www.acmicpc.net/problem/2456


$O(n)$


#include<cstdio>
#include<algorithm>
using namespace std;
int n, r, c;
pair<intint> p[3];
int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        for (int j = 0, x; j < 3; j++) scanf("%d", &x), p[j].first += x, p[j].second += x*x;
    if (p[1] > p[0]) r = 1;
    else if (p[1] == p[0]) c++;
    if (p[2] > p[r]) r = 2, c = 0;
    else if (p[2] == p[r]) c++;
    printf("%d %d", c ? 0 : r + 1, p[r].first);
    return 0;
}

댓글 없음 :

댓글 쓰기