Submission #167822

#TimeUsernameProblemLanguageResultExecution timeMemory
167822juggernautDivide and conquer (IZhO14_divide)C++14
17 / 100
51 ms3196 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; main(){ scanf("%lld",&n); for(i=1;i<=n;i++)scanf("%lld%lld%lld",&a[i].x,&a[i].g,&a[i].d); l=r=1; x=a[1].x; g=a[1].g; d=a[1].d; while(r<=n&&l<=n){ if(r<n&&d+a[r+1].d>=a[r+1].x-x){ r++; d+=a[r].d; g+=a[r].g; mx=max(mx,g); }else{ g-=a[l].g; d-=a[l].d; l++; x=a[l].x; } } l=r=n; x=a[n].x; g=a[n].g; d=a[n].d; while(r>0&&l>0){ if(l>0&&d+a[l-1].d>=x-a[l-1].x){ l--; d+=a[l].d; g+=a[l].g; mx=max(mx,g); }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:11:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1;i<=n;i++)scanf("%lld%lld%lld",&a[i].x,&a[i].g,&a[i].d);
                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...