Submission #1029102

# Submission time Handle Problem Language Result Execution time Memory
1029102 2024-07-20T12:25:56 Z Nurislam Schools (IZhO13_school) C++17
100 / 100
99 ms 13268 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>  
#define int long long

template <class F, class _S>
bool chmin(F &u, const _S &v){
	bool flag = false;
	if ( u > v ){
		u = v; flag |= true;
	}
	return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
	bool flag = false;
	if ( u < v ){
		u = v; flag |= true;
	}
	return flag;
}
const int N = 2e5+5, inf = 1e18, mod = 1e9+7;

void solve() {
	int n, m, s;
	cin >> n >> m >> s;
	vector<int> a(n), b(n), idx(n);
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}
	for(int i = 0; i < n; i++)idx[i] = i;
	auto cp = [&](int &x,int &y) -> bool{
		return (a[x] - b[x]) > (a[y] - b[y]);
	};
	sort(all(idx), cp);
	//for(auto i:idx)cout << i << '\n';
	priority_queue<int> q;
	int pre[n]{}, suf[n+1]{};
	for(int i = 0; i < n; i++){
		pre[i] = (i?pre[i-1]:0);
		q.push(-a[idx[i]]);
		pre[i] += a[idx[i]];
		while(q.size() > m){
			pre[i]+=q.top();q.pop();
		}
	}
	while(q.size())q.pop();
	for(int i = n-1; i>=0; i--){
		suf[i] = suf[i+1];
		q.push(-b[idx[i]]);
		suf[i] += b[idx[i]];
		while(q.size() > s){
			suf[i]+=q.top();q.pop();
		}
	}
	//for(auto i:pre)cout << i << ' ';
	//cout << '\n';
	//for(auto i:suf)cout << i << ' ';
	//cout << '\n';
	int ans = 0;
	for(int i = 0; i < n-s; i++)chmax(ans, pre[i]+suf[i+1]);
	cout << ans << '\n';
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int tt = 1;
	//cin >> tt;
	while(tt--){
		solve();
	}
}
 
 
 
 
 
 
 
 
 
 
 
 
 

Compilation message

school.cpp: In function 'void solve()':
school.cpp:53:18: 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]
   53 |   while(q.size() > m){
      |         ~~~~~~~~~^~~
school.cpp:62:18: 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]
   62 |   while(q.size() > s){
      |         ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 600 KB Output is correct
13 Correct 12 ms 2260 KB Output is correct
14 Correct 30 ms 3828 KB Output is correct
15 Correct 42 ms 6740 KB Output is correct
16 Correct 53 ms 9412 KB Output is correct
17 Correct 81 ms 9936 KB Output is correct
18 Correct 80 ms 10960 KB Output is correct
19 Correct 99 ms 11728 KB Output is correct
20 Correct 98 ms 13268 KB Output is correct