# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
91048 | 2018-12-26T04:00:09 Z | YottaByte | Divide and conquer (IZhO14_divide) | C++14 | 56 ms | 14724 KB |
#include <stdio.h> using namespace std; const int N = 1e5 + 1; #define ll 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("%d", &n); for(int i = 1; i <= n; i++) scanf("%d %d %d", &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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 416 KB | Output is correct |
4 | Correct | 2 ms | 416 KB | Output is correct |
5 | Correct | 2 ms | 416 KB | Output is correct |
6 | Correct | 2 ms | 488 KB | Output is correct |
7 | Correct | 2 ms | 568 KB | Output is correct |
8 | Correct | 2 ms | 568 KB | Output is correct |
9 | Correct | 2 ms | 568 KB | Output is correct |
10 | Correct | 2 ms | 568 KB | Output is correct |
11 | Correct | 1 ms | 568 KB | Output is correct |
12 | Correct | 1 ms | 568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 568 KB | Output is correct |
2 | Correct | 2 ms | 656 KB | Output is correct |
3 | Incorrect | 2 ms | 656 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 688 KB | Output is correct |
2 | Correct | 4 ms | 880 KB | Output is correct |
3 | Correct | 5 ms | 1128 KB | Output is correct |
4 | Correct | 20 ms | 2560 KB | Output is correct |
5 | Correct | 25 ms | 3912 KB | Output is correct |
6 | Correct | 52 ms | 7568 KB | Output is correct |
7 | Correct | 36 ms | 9496 KB | Output is correct |
8 | Correct | 37 ms | 11324 KB | Output is correct |
9 | Correct | 36 ms | 12996 KB | Output is correct |
10 | Incorrect | 56 ms | 14724 KB | Output isn't correct |
11 | Halted | 0 ms | 0 KB | - |