Submission #106175

#TimeUsernameProblemLanguageResultExecution timeMemory
106175mzhaoCake 3 (JOI19_cake3)C++11
24 / 100
234 ms640 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define D(x...) printf(x)
#else
#define D(x...)
#endif

#define MN 200100
#define x first
#define y second

using ll = long long;

int N, M;
pair<ll, ll> A[MN];
ll ans = -1e17;

bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
	if (a.y == b.y) return a.x > b.x;
	return a.y > b.y;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> M;
	assert(N <= 2000);
	for (int i = 0; i < N; i++) {
		cin >> A[i].x >> A[i].y;
	}
	sort(A, A+N, cmp);
	for (int i = M-1; i < N; i++) {
		multiset<ll> cur;
		ll tot = 0;
		for (int j = i; j >= 0; j--) {
			tot += A[j].x;
			cur.insert(A[j].x);
			if (cur.size() > M) {
				tot -= *cur.begin();
				cur.erase(cur.begin());
			}
			if (cur.size() == M) {
				ans = max(ans, tot-2*(A[j].y-A[i].y));
			}
		}
	}
	cout << ans << "\n";
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:39:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (cur.size() > M) {
        ~~~~~~~~~~~^~~
cake3.cpp:43:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (cur.size() == M) {
        ~~~~~~~~~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...