Submission #542721

# Submission time Handle Problem Language Result Execution time Memory
542721 2022-03-27T17:01:19 Z CaroLinda Hotel (CEOI11_hot) C++14
100 / 100
518 ms 40660 KB
#include <bits/stdc++.h>

#define pii pair<int,int> 
#define pb push_back
#define ll long long
#define mk make_pair
#define lp(i,a,b) for(int i = a ; i < b; i++ )
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()

const int MAXN = 5e5+10 ;

using namespace std ;

int N , M , O ;
pair<int,int> vet[MAXN] ;
vector<int> freq[MAXN] ;
multiset<int> global ;

int main(){
	ios_base::sync_with_stdio(false );
	cin.tie(0) ;

	cin >> N >> M >> O ;
	for(int i = 1 ; i <= N ; i++ ){
		cin >> vet[i].second >> vet[i].first ;
	}
	sort(vet+1, vet+1+N ) ;
	for(int i = 1 , x , y ; i <= M ; i++ ){
		cin >> x >> y ;
		int it = lower_bound(vet+1, vet+1+N, make_pair(y, -1))-vet ;
		if(it <= N ) freq[it].push_back(x) ;
	}

	vector<int> ans ;

	for(int i = 1 ; i <= N ; i++ ){

		for(auto e : freq[i] ) global.insert(e) ;
		if(!global.empty()){
			ans.push_back( *prev(global.end())-vet[i].second ) ;
			global.erase( prev(global.end()) ) ;
		}
	}

	sort(all(ans)) ;
	reverse(all(ans)) ;

	ll res = 0 ;

	for(int i = 0 ; i < min(O, sz(ans) ) ; i++ )
		res += max(0, ans[i]) ;

	cout << res << "\n" ;

}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 11988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11988 KB Output is correct
2 Correct 6 ms 12024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 12500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 14488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 16308 KB Output is correct
2 Correct 45 ms 14904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 23728 KB Output is correct
2 Correct 161 ms 22232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 35344 KB Output is correct
2 Correct 435 ms 39300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 404 ms 39248 KB Output is correct
2 Correct 424 ms 40660 KB Output is correct
3 Correct 518 ms 39084 KB Output is correct