Submission #1042160

#TimeUsernameProblemLanguageResultExecution timeMemory
1042160MinbaevDivide and conquer (IZhO14_divide)C++17
100 / 100
21 ms8028 KiB
#include<bits/stdc++.h> #define int long long int using namespace std; struct dta{ int x,g,d; }; dta a[100001]; int n,i,drive[100001],gold[100001],vec[100001],res,l,r,m; main(){ scanf("%lld",&n); for(i=1;i<=n;i++){ scanf("%lld%lld%lld",&a[i].x,&a[i].g,&a[i].d); gold[i]=gold[i-1]+a[i].g; drive[i]=drive[i-1]+a[i].d; vec[i]=drive[i]-a[i].x; } for(i=n-1;i>0;i--)vec[i]=max(vec[i],vec[i+1]); for(i=1;i<=n;i++){ l=i; r=n; while(l<r){ m=(l+r+1)>>1; if(vec[m]>=drive[i-1]-a[i].x)l=m; else r=m-1; } res=max(res,gold[r]-gold[i-1]); } printf("%lld",res); }

Compilation message (stderr)

divide.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | 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]
   10 |     scanf("%lld",&n);
      |     ~~~~~^~~~~~~~~~~
divide.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         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...