Submission #167749

#TimeUsernameProblemLanguageResultExecution timeMemory
167749daniyar03Divide and conquer (IZhO14_divide)C++14
0 / 100
2 ms376 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,gold[100001],drive[100001],mx,m; main(){ freopen("divide.in","r",stdin); freopen("divide.out","w",stdout); 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; for(i=1;i<=n;i++){ l=i; r=n; while(l<r){ m=(l+r+1)>>1; if(drive[m]-drive[i-1]>=a[m].x-a[i].x+1)l=m; else r=m-1; } mx=max(mx,gold[l]-gold[i-1]); } cout<<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:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("divide.in","r",stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:11:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("divide.out","w",stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
divide.cpp:13:92: 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),gold[i]=gold[i-1]+a[i].g,drive[i]=drive[i-1]+a[i].d;
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...