# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
291828 | 2020-09-05T20:29:19 Z | Kastanda | Sails (IOI07_sails) | C++11 | 46 ms | 2568 KB |
// M #include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100005; int n, H[N], K[N], C[N]; inline bool Solve(int md) { memset(C, 0, sizeof(C)); for (int i = 1; i <= n; i ++) C[H[i] - K[i] + 1] ++, C[H[i] + 1] --; for (int i = 1; i < N; i ++) C[i] += C[i - 1]; ll LeftOver = 0; for (int i = N - 1; i; i --) { int tmp = min(LeftOver, (ll)md - C[i]); LeftOver -= tmp; C[i] += tmp; assert(C[i] <= md); } return !LeftOver; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i ++) scanf("%d%d", &H[i], &K[i]); int le = 0, ri = N, md; while (ri - le > 1) { md = (le + ri) >> 1; if (Solve(md)) ri = md; else le = md; } // How to do it with ri you ask? I don't know either ... Solve(ri); int ptr = 1; for (int i = N - 1; i; i --) if (C[i] == ri) { while (ptr < i && C[ptr] == ri) ptr ++; if (ptr >= i) break; C[i] --; C[ptr] ++; } ll tot = 0; for (int i = 1; i < N; i ++) tot += (ll)C[i] * (C[i] - 1) / 2; printf("%lld\n", tot); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 768 KB | Output is correct |
2 | Correct | 10 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 768 KB | Output is correct |
2 | Correct | 10 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 768 KB | Output is correct |
2 | Correct | 10 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 768 KB | Output is correct |
2 | Correct | 10 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 768 KB | Output is correct |
2 | Correct | 11 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 896 KB | Output is correct |
2 | Correct | 20 ms | 1300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 21 ms | 1280 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 32 ms | 1664 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 2216 KB | Output is correct |
2 | Correct | 37 ms | 2296 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 2500 KB | Output is correct |
2 | Correct | 36 ms | 2168 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 46 ms | 2568 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |