Submission #91049

# Submission time Handle Problem Language Result Execution time Memory
91049 2018-12-26T04:02:27 Z YottaByte Divide and conquer (IZhO14_divide) C++14
17 / 100
51 ms 2980 KB
#include <stdio.h>
using namespace std;

const int N = 1e5 + 1;

#define ll long long
#define int long long
#define ok puts("OK");
int n, x[N], g[N], e[N];

inline bool check(ll mid)
{
	int l = 1, r = 1;
	
	ll genergy = e[l];
	ll lenergy = 0;
	ll ggold = g[l];
	while(l <= r)
	{
		lenergy = x[r] - x[l];
		//printf("Gold: %lld NeedG: %lld EnergyL: %lld EnergyG: %lld L: %d R: %d",
		              //ggold,       mid,        lenergy,      genergy,  l,    r);
		//puts("");
		if(lenergy <= genergy && ggold >= mid)
			return true;
		if(l == n && r == n) return false;
		if(lenergy <= genergy && r < n)
		{
			r++;
			ggold += g[r];
			genergy += e[r];
		}
		else
		{
			ggold -= g[l];
			genergy -= e[l];
			l++;
		}
	}
	return false;
}

main()
{
	ll maxg = 0;
	scanf("%lld", &n);
	for(int i = 1; i <= n; i++)
		scanf("%lld %lld %lld", &x[i], &g[i], &e[i]), maxg += g[i];
	
	ll l = 0, r = maxg + 1;
	while(r - l > 1)
	{
		ll mid = l + r >> 1ll;
		if(check(mid)) l = mid;
		else r = mid;
		//puts("");
	}
	
	printf("%lld", l);
}
/*
4
0 5 1
1 7 2
4 4 1
7 15 1

2
0 4 1
3 5 1
*/

Compilation message

divide.cpp:43:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
divide.cpp: In function 'int main()':
divide.cpp:53:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   ll mid = l + r >> 1ll;
            ~~^~~
divide.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
divide.cpp:48:47: 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], &e[i]), maxg += g[i];
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 372 KB Output is correct
3 Correct 2 ms 408 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 484 KB Output is correct
8 Correct 2 ms 484 KB Output is correct
9 Correct 2 ms 484 KB Output is correct
10 Correct 2 ms 484 KB Output is correct
11 Correct 2 ms 484 KB Output is correct
12 Correct 2 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 560 KB Output is correct
2 Correct 2 ms 560 KB Output is correct
3 Incorrect 2 ms 620 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 620 KB Output is correct
2 Correct 4 ms 748 KB Output is correct
3 Correct 5 ms 748 KB Output is correct
4 Correct 19 ms 1772 KB Output is correct
5 Correct 24 ms 1772 KB Output is correct
6 Correct 50 ms 2980 KB Output is correct
7 Correct 34 ms 2980 KB Output is correct
8 Correct 36 ms 2980 KB Output is correct
9 Correct 34 ms 2980 KB Output is correct
10 Incorrect 51 ms 2980 KB Output isn't correct
11 Halted 0 ms 0 KB -