답안 #286188

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
286188 2020-08-30T08:11:30 Z shrek12357 학교 설립 (IZhO13_school) C++14
20 / 100
753 ms 28996 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;

int main() {
	int n, m, s;
	cin >> n >> s >> m;
	vector<pair<long long, long long>> music;
	vector<pair<long long, long long>> nums;
	multiset<pair<long long, long long>> left;
	for (int i = 0; i < n; i++) {
		long long a, b;
		cin >> a >> b;
		nums.push_back({ a, b });
		music.push_back({ b, a });
		left.insert({ -1*b, a });
	}
	sort(nums.begin(), nums.end());
	sort(music.begin(), music.end());
	int curIdx = n - m - 1;
	//int bigIdx = n - 1;
	long long ans = 0;
	for(int i = nums.size() - 1; i >= 0; i--){
		if (s <= 0) {
			while (m > 0) {
				ans += -1 * left.begin()->first;
				left.erase(left.begin());
				m--;
			}
			break;
		}
		if (curIdx >= 0 && nums[i].second < music[curIdx].first) {
			s--;
			ans += nums[i].first;
		}
		else {
			long long num1 = nums[i].first;
			if (i - s >= 0) {
				num1 -= nums[i - s].first;
			}
			long long num2 = nums[i].second;
			if (curIdx >= 0) {
				num2 -= music[curIdx].first;
			}
			if (num1 > num2) {
				curIdx--;
				s--;
				ans += nums[i].first;
			}
			else {
				ans += nums[i].second;
				m--;
			}
		}
		left.erase(left.find({ nums[i].second * -1, nums[i].first }));
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Incorrect 0 ms 256 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 7 ms 896 KB Output isn't correct
8 Incorrect 8 ms 896 KB Output isn't correct
9 Incorrect 8 ms 896 KB Output isn't correct
10 Incorrect 8 ms 896 KB Output isn't correct
11 Incorrect 9 ms 896 KB Output isn't correct
12 Incorrect 8 ms 896 KB Output isn't correct
13 Incorrect 68 ms 3944 KB Output isn't correct
14 Incorrect 150 ms 7760 KB Output isn't correct
15 Correct 330 ms 15360 KB Output is correct
16 Incorrect 487 ms 17220 KB Output isn't correct
17 Incorrect 549 ms 21132 KB Output isn't correct
18 Incorrect 589 ms 22980 KB Output isn't correct
19 Incorrect 656 ms 24772 KB Output isn't correct
20 Incorrect 753 ms 28996 KB Output isn't correct