Submission #313289

# Submission time Handle Problem Language Result Execution time Memory
313289 2020-10-15T16:29:16 Z vitkishloh228 Schools (IZhO13_school) C++14
20 / 100
392 ms 20580 KB
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#define int long long
using namespace std;
int32_t main() {
	int n, m, s;
	cin >> n >> m >> s;
	vector<int> M(n), S(n);
	vector<pair<int, int>> ar;
	for (int i = 0; i < n; ++i) {
		cin >> M[i] >> S[i];
		ar.push_back({ M[i] - S[i],i });
	}
	sort(ar.rbegin(), ar.rend());
	//reverse(ar.begin(), ar.end());
	vector<int> pr(n), suf(n+1);
	priority_queue<int> q;
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		int pos = ar[i].second;
		if (q.size() < m) {
			sum += M[pos];
			q.push(M[pos]);
			pr[i] = sum;
			continue;
		}
		if (q.top() < M[pos]) {
			sum -= q.top();
			q.pop();
			sum += M[pos];
			q.push(M[pos]);
		}
		pr[i] = sum;
	}
	sum = 0;
	priority_queue<int> q1;
	for (int i = n-1; i >=0; --i) {
		int pos = ar[i].second;
		if (q1.size() < s) {
			sum += S[pos];
			q1.push(S[pos]);
			suf[i] = sum;
			continue;
		}
		if (q1.top() < S[pos]) {
			sum -= q1.top();
			q1.pop();
			sum += S[pos];
			q1.push(S[pos]);
		}
		suf[i] = sum;
	}
	int ans = suf[0];
	for (int i = 0; i < n; ++i) {
		ans = max(ans, pr[i] + suf[i + 1]);
	}
	cout << ans;
}

Compilation message

school.cpp: In function 'int32_t main()':
school.cpp:23:16: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |   if (q.size() < m) {
      |       ~~~~~~~~~^~~
school.cpp:41:17: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   41 |   if (q1.size() < s) {
      |       ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Correct 0 ms 256 KB Output is correct
4 Incorrect 1 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 6 ms 640 KB Output isn't correct
8 Correct 6 ms 640 KB Output is correct
9 Incorrect 6 ms 640 KB Output isn't correct
10 Incorrect 6 ms 640 KB Output isn't correct
11 Incorrect 6 ms 640 KB Output isn't correct
12 Incorrect 7 ms 640 KB Output isn't correct
13 Incorrect 45 ms 2924 KB Output isn't correct
14 Incorrect 98 ms 5360 KB Output isn't correct
15 Incorrect 198 ms 9696 KB Output isn't correct
16 Correct 227 ms 14272 KB Output is correct
17 Incorrect 294 ms 15712 KB Output isn't correct
18 Incorrect 317 ms 16892 KB Output isn't correct
19 Incorrect 346 ms 18144 KB Output isn't correct
20 Incorrect 392 ms 20580 KB Output isn't correct