Submission #286184

# Submission time Handle Problem Language Result Execution time Memory
286184 2020-08-30T08:08:21 Z shrek12357 Schools (IZhO13_school) C++14
20 / 100
748 ms 22712 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<int, int>> music;
	vector<pair<int, int>> nums;
	multiset<pair<int, int>> left;
	for (int i = 0; i < n; i++) {
		int 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;
	int 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 {
			int num1 = nums[i].first;
			if (i - s >= 0) {
				num1 -= nums[i - s].first;
			}
			int 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Incorrect 1 ms 256 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 8 ms 768 KB Output isn't correct
8 Incorrect 8 ms 672 KB Output isn't correct
9 Incorrect 9 ms 640 KB Output isn't correct
10 Incorrect 10 ms 640 KB Output isn't correct
11 Incorrect 8 ms 768 KB Output isn't correct
12 Incorrect 8 ms 640 KB Output isn't correct
13 Incorrect 66 ms 3056 KB Output isn't correct
14 Incorrect 149 ms 6108 KB Output isn't correct
15 Correct 313 ms 11988 KB Output is correct
16 Incorrect 460 ms 13664 KB Output isn't correct
17 Incorrect 514 ms 16720 KB Output isn't correct
18 Incorrect 575 ms 18524 KB Output isn't correct
19 Incorrect 624 ms 19672 KB Output isn't correct
20 Incorrect 748 ms 22712 KB Output isn't correct