Submission #1114542

# Submission time Handle Problem Language Result Execution time Memory
1114542 2024-11-19T07:26:59 Z Tsagana Schools (IZhO13_school) C++14
75 / 100
88 ms 3492 KB
#include<bits/stdc++.h>

#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define lnl long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
#define sp << ' ' <<
#define nl << '\n'

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {return (a.F - a.S < b.F - b.S ? 1 : 0);}

void solve () {
	int n, m, s; cin >> n >> m >> s;
 
	vector<pair<int, int>> v(n);
	for (auto &i : v) cin >> i.F >> i.S;
	sort(all(v), cmp);
 
	int ans = 0;
	int sum = 0;
	pq<int> q;

	for (int i = 0; i < n; i++) {
		q.push(-v[i].S);
		sum += v[i].S;
		
		while (q.size() > s) {sum += q.top(); q.pop();}
		v[i].S = sum;
	}

	sum = 0;
	pq<int> ().swap(q);

	for (int i = n-1; i >= 0; i--) {
		q.push(-v[i].F);
		sum += v[i].F;
		while (q.size() > m) {sum += q.top(); q.pop();}

		ans = max(ans, sum + (i ? v[i-1].S : 0));
	}
 
	cout << ans;
}
int main() {IOS solve(); return 0;}

Compilation message

school.cpp: In function 'void solve()':
school.cpp:36:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |   while (q.size() > s) {sum += q.top(); q.pop();}
      |          ~~~~~~~~~^~~
school.cpp:46:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |   while (q.size() > m) {sum += q.top(); q.pop();}
      |          ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 3 ms 336 KB Output is correct
8 Correct 3 ms 336 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 336 KB Output is correct
11 Correct 3 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 11 ms 848 KB Output is correct
14 Correct 22 ms 1104 KB Output is correct
15 Correct 57 ms 1696 KB Output is correct
16 Incorrect 63 ms 3008 KB Output isn't correct
17 Incorrect 67 ms 2856 KB Output isn't correct
18 Incorrect 81 ms 3216 KB Output isn't correct
19 Incorrect 88 ms 3128 KB Output isn't correct
20 Incorrect 83 ms 3492 KB Output isn't correct