Submission #167826

#TimeUsernameProblemLanguageResultExecution timeMemory
167826juggernautDivide and conquer (IZhO14_divide)C++14
0 / 100
50 ms1528 KiB
#include<bits/stdc++.h> #define int long long int using namespace std; struct data{ int x,g,d; }; data a[100001]; int n,i,l,r,x,g,mx,d,cnt=1; main(){ scanf("%lld",&n); cin>>a[1].x>>a[1].g>>a[1].d; for(i=2;i<=n;i++) { scanf("%lld%lld%lld",&x,&g,&d); if(a[cnt].x + a[cnt].d >= x){ a[cnt].d+=d; a[cnt].g+=g; } else{ cnt++; a[cnt].x=x; a[cnt].d=d; a[cnt].g=g; } } n=cnt; l=r=n; x=a[n].x; g=0; d=0; while(l>0){ if(d+a[l].d>=a[r].x-a[l].x){ d+=a[l].d; g+=a[l].g; mx=max(mx,g); l--; }else{ g-=a[r].g; d-=a[r].d; r--; x=a[r].x; } } printf("%lld",mx); }

Compilation message (stderr)

divide.cpp:9:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
divide.cpp: In function 'int main()':
divide.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
divide.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld%lld",&x,&g,&d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...