[백준] 2822 점수 계산

0

백준

목록 보기
159/271
post-thumbnail

[백준] 2822 점수 계산

#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;


//점수 기준 내림차순 정렬
bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first > b.first;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	//<점수, 문제 번호>
	vector<pair<int, int>> score;
	for (int i = 0; i < 8; ++i) {
		int input;
		cin >> input;
		score.push_back({ input, i+1 });
	}
	sort(score.begin(), score.end(), cmp);

	int sum = 0;
	vector<int> num;
	for (int i = 0; i < 5; ++i) {
		sum += score[i].first;
		num.push_back(score[i].second);
	}

	cout << sum << "\n";

	sort(num.begin(), num.end());
	for (int i = 0; i < 5; ++i) {
		cout << num[i] << " ";
	}
	return 0;
}

profile
Be able to be vulnerable, in search of truth

0개의 댓글