Submission #168012

# Submission time Handle Problem Language Result Execution time Memory
168012 2019-12-11T07:25:33 Z GioChkhaidze Divide and conquer (IZhO14_divide) C++14
100 / 100
55 ms 5288 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
ll n,x[N],g[N],d[N],M[N],ans;
main () {
	scanf("%lld",&n);
	
	for (int i=1; i<=n; i++) {
		scanf("%lld%lld%lld",&x[i],&g[i],&d[i]);
		g[i]+=g[i-1];
		d[i]+=d[i-1];
		M[i]=d[i]-x[i];
	}
	
	M[n+1]=-1e18;
	for (int i=n; i>=1; i--)
		M[i]=max(M[i],M[i+1]);
		
	for (int i=1; i<=n; i++) {
		ll c=d[i-1]-x[i],l=i,r=n,mid,res;
		
		while (l<=r) {
			mid=(l+r)/2;
			if (c<=M[mid]) { res=mid; l=mid+1; }
						else r=mid-1;
		}
		
		ans=max(ans,g[res]-g[i-1]);
	}
	
	printf("%lld\n",ans);
}

Compilation message

divide.cpp:6:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
divide.cpp: In function 'int main()':
divide.cpp:7:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
  ~~~~~^~~~~~~~~~~
divide.cpp:10:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld",&x[i],&g[i],&d[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:29:20: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ans=max(ans,g[res]-g[i-1]);
               ~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 396 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 508 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 6 ms 888 KB Output is correct
4 Correct 23 ms 2936 KB Output is correct
5 Correct 27 ms 3192 KB Output is correct
6 Correct 55 ms 4984 KB Output is correct
7 Correct 41 ms 4856 KB Output is correct
8 Correct 41 ms 4848 KB Output is correct
9 Correct 39 ms 4984 KB Output is correct
10 Correct 40 ms 4984 KB Output is correct
11 Correct 46 ms 5288 KB Output is correct
12 Correct 48 ms 5240 KB Output is correct