Submission #773087

# Submission time Handle Problem Language Result Execution time Memory
773087 2023-07-04T14:57:04 Z NK_ Hotel (CEOI11_hot) C++17
100 / 100
585 ms 52984 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define f first
#define s second
#define mp make_pair
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)


using ll = long long;
using pi = pair<int, int>;
template<class T> using V = vector<T>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, M, O; cin >> N >> M >> O;

	V<pi> A(N); for(auto& x : A) cin >> x.f >> x.s;
	V<pi> B(M); for(auto& x : B) cin >> x.f >> x.s;

	sort(all(A));
	sort(rall(B));

	set<pi> S; for(int i = 0; i < N; i++) S.insert(mp(A[i].s, i));

	V<int> P;
	for(int i = 0; i < M; i++) {
		auto it = S.lower_bound(mp(B[i].s, -1));
		if (it == end(S)) continue;
		int j = (*it).s;
		// cout << i << " " << j << endl;
		P.push_back(B[i].f - A[j].f);
		S.erase(it);
	}	

	sort(rall(P));

	ll ans = 0;
	for(int i = 0; i < min(O, sz(P)); i++) ans += max(0, P[i]);
	cout << ans << nl;

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 3184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 5232 KB Output is correct
2 Correct 41 ms 6540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 13940 KB Output is correct
2 Correct 89 ms 11092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 378 ms 27556 KB Output is correct
2 Correct 468 ms 43020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 33796 KB Output is correct
2 Correct 475 ms 52984 KB Output is correct
3 Correct 585 ms 50100 KB Output is correct