# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
291844 | 2020-09-05T20:56:15 Z | Kastanda | Sails (IOI07_sails) | C++11 | 1000 ms | 1784 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 ... ri = N; 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] ++; } vector < int > A; for (int i = 1; i < N; i ++) { vector < int > Tbo = {C[i]}; while (Tbo.size()) { if (!A.size() || A.back() >= Tbo.back()) { A.push_back(Tbo.back()); Tbo.pop_back(); continue; } int nd = (Tbo.back() - A.back() + 1) / 2; Tbo.back() -= nd; Tbo.push_back(A.back() + nd); A.pop_back(); } } assert((int)A.size() == N - 1); for (int i = 1; i < N; i ++) C[i] = A[i - 1]; /*for (int i = 1; i < N; i ++) assert(C[i] <= ri); bool Fail = 1; for (int i = 1; i < N; i ++) if (C[i] == ri) Fail = 0; assert(!Fail);*/ for (int i = 2; i < N; i ++) assert(C[i - 1] >= C[i]); 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 | 14 ms | 1404 KB | Output is correct |
2 | Correct | 14 ms | 1404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1404 KB | Output is correct |
2 | Correct | 14 ms | 1532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 1404 KB | Output is correct |
2 | Correct | 13 ms | 1404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 1404 KB | Output is correct |
2 | Correct | 51 ms | 1396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1053 ms | 888 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1086 ms | 1056 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 1656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1091 ms | 1272 KB | Time limit exceeded |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1089 ms | 1528 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1085 ms | 1528 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1087 ms | 1784 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |