Submission #446098

# Submission time Handle Problem Language Result Execution time Memory
446098 2021-07-20T22:33:27 Z aryan12 Schools (IZhO13_school) C++17
75 / 100
142 ms 10688 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first - a.second > b.first - b.second;
}

void Solve() {
	int n, m, s;
	cin >> n >> m >> s;
	vector<pair<int, int> > a(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin() + 1, a.end(), cmp);
	priority_queue<int, vector<int>, greater<int> > pq;
	int pref[n + 1];
	pref[0] = 0;
	int sum = 0;
	for(int i = 1; i <= n; i++) {
		pq.push(a[i].first);
		sum += a[i].first;
		//cout << "sum = " << sum << "\n";
		while(pq.size() > m) {
			int x = pq.top();
			pq.pop();
			sum -= x;
		}
		//cout << "sum = " << sum << "\n";
		pref[i] = sum;
	}
	while(!pq.empty()) {
		pq.pop();
	}
	int suf[n + 2];
	suf[n + 1] = 0;
	sum = 0;
	for(int i = n; i > 0; i--) {
		pq.push(a[i].second);
		sum += a[i].second;
		while(pq.size() > s) {
			int x = pq.top();
			pq.pop();
			sum -= x;
		}
		suf[i] = sum;
	}
	/*for(int i = 1; i <= n; i++) {
		cout << pref[i] << " ";
	}
	cout << "\n";
	for(int i = n; i > 0; i--) {
		cout << suf[i] << " ";
	}
	cout << "\n";*/
	int ans = 0;
	for(int i = m; i < n - s; i++) {
		ans = max(ans, pref[i] + suf[i + 1]);
	}
	cout << ans << "\n";
}

int32_t main() {
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}

Compilation message

school.cpp: In function 'void Solve()':
school.cpp:27:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   27 |   while(pq.size() > m) {
      |         ~~~~~~~~~~^~~
school.cpp:44:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   44 |   while(pq.size() > s) {
      |         ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Incorrect 2 ms 460 KB Output isn't correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 18 ms 1744 KB Output is correct
14 Correct 38 ms 3080 KB Output is correct
15 Correct 65 ms 5316 KB Output is correct
16 Incorrect 83 ms 8000 KB Output isn't correct
17 Correct 102 ms 8000 KB Output is correct
18 Correct 117 ms 8768 KB Output is correct
19 Correct 123 ms 9352 KB Output is correct
20 Correct 142 ms 10688 KB Output is correct