Submission #331766

#TimeUsernameProblemLanguageResultExecution timeMemory
331766daniel920712Art Exhibition (JOI18_art)C++14
100 / 100
241 ms24832 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <algorithm> #include <set> #include <map> #include <queue> using namespace std; struct A { long long x,y; }all[500005]; long long add[500005]={0}; bool F(A a,A b) { return a.x<b.x; } int main() { long long N,ans=0,i,j,big=-1e18; scanf("%lld",&N); for(i=0;i<N;i++) scanf("%lld %lld",&all[i].x,&all[i].y); sort(all,all+N,F); for(i=0;i<N;i++) add[i+1]=add[i]+all[i].y; for(i=N-1;i>=0;i--) { big=max(big,add[i+1]-all[i].x); ans=max(ans,all[i].x-add[i]+big); //printf("%lld %lld\n",i,big); } /*for(i=0;i<N;i++) { for(j=i;j<N;j++) { //printf("%lld %lld %lld %lld\n",i,j,) ans=max(ans,add[j+1]-add[i]-(all[j].x-all[i].x)); } }*/ printf("%lld\n",ans); return 0; }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:23:25: warning: unused variable 'j' [-Wunused-variable]
   23 |     long long N,ans=0,i,j,big=-1e18;
      |                         ^
art.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
art.cpp:25:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     for(i=0;i<N;i++) scanf("%lld %lld",&all[i].x,&all[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...