728x90
반응형
https://www.acmicpc.net/problem/15702
15702번: 중간고사 채점
이번 중간고사에는 총 N문제가 나왔고, 응시한 사람의 수는 M명이다. 각 문제의 배점과 각 사람의 결과가 주어졌을 때, 가장 높은 점수를 획득한 사람을 구하는 프로그램을 작성하시오.
www.acmicpc.net
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool compare(pair<int, int>& front, pair<int, int>& back)
{
if (front.second < back.second)
return front.second > back.second;
else if (front.second == back.second)
return front.first < back.first;
else return front.second > back.second;
}
int main() {
ios::sync_with_stdio(NULL);
cin.tie(NULL);
int n, m, k;
cin >> n >> m;
vector<int> s;
for(int i = 0; i < n; i++){
cin >> k;
s.push_back(k);
}
int sn;
char ox;
vector<pair<int, int>> w;
for(int i = 0; i < m; i++){
int score = 0;
cin >> sn;
for(int j = 0; j < n; j++){
cin >> ox;
if(ox == 'O')
score += s[j];
}
w.push_back({sn, score});
}
sort(w.begin(), w.end(), compare);
cout << w[0].first << " " << w[0].second;
return 0;
}
728x90
반응형
'Algorithm > BAEKJOON' 카테고리의 다른 글
[BOJ] 7662번 이중 우선순위 큐 (C++) (0) | 2021.12.31 |
---|---|
[BOJ] 2108번 통계학 (C++) (0) | 2021.12.30 |
[BOJ] 1018번 체스판 다시 칠하기 (C++) (0) | 2021.12.29 |
[BOJ] 10816번 숫자 카드 2 (C++) (0) | 2021.12.29 |
[BOJ] 11899번 괄호 끼워넣기 (C++) (0) | 2021.12.28 |