Submission #47012

#TimeUsernameProblemLanguageResultExecution timeMemory
47012leejseoArt Exhibition (JOI18_art)C++98
100 / 100
351 ms239072 KiB
#include <stdio.h>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
#define MAXN 500005
typedef long long lld;
typedef pair<lld, lld> pll;
lld S[MAXN], X[MAXN], Y[MAXN], ans;
vector<pll> U;
int N;
int main(void){
	scanf("%d", &N);
	lld a, b;
	for (int i=0; i<N; i++){
		scanf("%lld%lld", &a, &b);
		U.push_back(make_pair(a, b));
	}
	sort(U.begin(), U.end());
	for (int i=0; i<N; i++){
		S[i+1] = S[i] + U[i].second;
	}
	Y[0] = -(U[0].first);
	for (int i=1; i<=N; i++){
		X[i] = S[i] - U[i-1].first;
		if (i != N) Y[i] = min(Y[i-1], S[i]-U[i].first);
	}
	for (int i=0; i<N; i++) ans = max(ans, X[i+1]-Y[i]);
	printf("%lld", ans);
}

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:13:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
art.cpp:16:8: 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...