๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ๐Ÿฃ: ๐’œ๐“๐‘”๐‘œ๐“‡๐’พ๐“‰๐’ฝ๐“‚/์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ ํ’€์ด

BOJ2456 : ๋‚˜๋Š” ํ•™๊ธ‰ํšŒ์žฅ์ด๋‹ค (Bronze1)

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
    int N;
    int score[1000][3];
    cin >> N;
    int total[3][3] = {0};
    for (int i = 0; i < N; i++)
    {
        cin >> score[i][0] >> score[i][1] >> score[i][2];
        if (score[i][0] == 1)
            total[0][0]++;
        if (score[i][0] == 2)
            total[0][1]++;
        if (score[i][0] == 3)
            total[0][2]++;
        if (score[i][1] == 1)
            total[1][0]++;
        if (score[i][1] == 2)
            total[1][1]++;
        if (score[i][1] == 3)
            total[1][2]++;
        if (score[i][2] == 1)
            total[2][0]++;
        if (score[i][2] == 2)
            total[2][1]++;
        if (score[i][2] == 3)
            total[2][2]++;
    }
    vector<int> totalscore = {total[0][0] + total[0][1] * 2 + total[0][2] * 3,
                              total[1][0] + 2 * total[1][1] + 3 * total[1][2],
                              total[2][0] + 2 * total[2][1] + 3 * total[2][2]};
    int maxPerson = 0;
    int flag = 0;
    //cout << totalscore[0] << totalscore[1] << totalscore[2] << "\n";
    for (int i = 1; i < 3; i++)
    {
        if (totalscore[maxPerson] == totalscore[i]) //์ด์ ์ด ๊ฐ™์œผ๋ฉด
        {
            if (total[maxPerson][2] < total[i][2]) //3์ ์ด ๋” ํฐ์• 
            {
                maxPerson = i;
                flag = 0;
            }
            else if (total[maxPerson][2] == total[i][2]) //3์ ๋„ ๊ฐ™์œผ๋ฉด
            {
                if (total[maxPerson][1] < total[i][1])
                {
                    maxPerson = i;
                    flag = 0;
                } //2์ ์ด ๋” ํฐ์• 

                else if (total[maxPerson][1] == total[i][1]) //๋‹ค๊ฐ™์œผ๋ฉด flag
                    flag = 1;
            }
        }
        if (totalscore[maxPerson] < totalscore[i])
        {
            maxPerson = i;
            flag = 0;
        }
    }
    if (flag)
        cout << 0 << " " << totalscore[maxPerson];
    else
        cout << maxPerson + 1 << " " << totalscore[maxPerson];
}