Submission #42090

#TimeUsernameProblemLanguageResultExecution timeMemory
42090nonocutArt Exhibition (JOI18_art)C++14
100 / 100
280 ms87280 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<ll,ll> #define X first #define Y second const int maxn = 5e5 + 5; const ll inf = 1e18; int n,m; pii p[maxn], a[maxn]; int main() { int i,j; ll ans = 0; scanf("%d",&n); for(i=0;i<n;i++) scanf("%lld%lld",&p[i].X,&p[i].Y); sort(p,p+n); for(i=0;i<n;i++) { if(p[i].X!=p[i+1].X) a[m++] = p[i]; else p[i+1].Y += p[i].Y; } ll sum = 0, mx = -inf; for(i=0;i<m;i++) { mx = max(mx, a[i].X - sum); sum += a[i].Y; ans = max(ans, sum - a[i].X + mx); } printf("%lld",ans); }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:12:11: warning: unused variable 'j' [-Wunused-variable]
     int i,j;
           ^
art.cpp:14:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
art.cpp:15:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=0;i<n;i++) scanf("%lld%lld",&p[i].X,&p[i].Y);
                                                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...