Submission #41578

#TimeUsernameProblemLanguageResultExecution timeMemory
41578szawinisArt Exhibition (JOI18_art)C++14
100 / 100
341 ms16700 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5+1;

int n;
pair<ll, ll> vec[N];
priority_queue<ll, vector<ll>, greater<ll> > pq;
ll ans, sum[N];
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		ll a, b;
		scanf("%lld %lld", &a, &b);
		vec[i] = {a, b};
	}
	sort(vec+1, vec+n+1);
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + vec[i].second;
	for(int i = 1; i <= n; i++) {
		pq.push(sum[i-1] - vec[i].first);
		ans = max(sum[i] - vec[i].first - pq.top(), ans);
	}
	printf("%lld", ans);
}

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:11:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
art.cpp:14:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &a, &b);
                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...