Submission #249443

#TimeUsernameProblemLanguageResultExecution timeMemory
249443shenxyCake 3 (JOI19_cake3)C++11
24 / 100
4073 ms6556 KiB
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
using namespace std;
typedef pair<long long, long long> ii;
int main() {
	int N, M;
	scanf("%d %d", &N, &M);
	ii CV[N];
	long long ans, bans = -1000000000000000000LL;
	for (int i = 0; i < N; ++i) scanf("%lld %lld", &CV[i].second, &CV[i].first);
	sort(CV, CV + N);
	for (int i = 0; i <= N - M; ++i) {
		priority_queue< long long, vector<long long>, greater<long long> > pq;
		ans = 0;
		for (int j = i; j < i + M; ++j) pq.push(CV[j].second), ans += CV[j].second;
		bans = max(bans, ans + 2 * CV[i].first - 2 * CV[i + M - 1].first);
		for (int j = i + M; j < N; ++j) {
			if (CV[j].second > pq.top()) {
				ans += CV[j].second - pq.top();
				pq.pop();
				pq.push(CV[j].second);
			}
			bans = max(bans, ans + 2 * CV[i].first - 2 * CV[j].first);
		}
	}
	printf("%lld", bans);
	return 0;
}

Compilation message (stderr)

cake3.cpp: In function 'int main()':
cake3.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~~
cake3.cpp:13:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < N; ++i) scanf("%lld %lld", &CV[i].second, &CV[i].first);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...