본문 바로가기

Algorithm/BAEKJOON

[BOJ] 15702번 중간고사 채점 (C++)

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
반응형