# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
462302 | 2021-08-10T10:39:27 Z | bigo | Fountain (eJOI20_fountain) | C++14 | 418 ms | 7300 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long typedef pair<int, int> pii; int main() { int n, q; cin >> n >> q; vector<pii>vec(n); ll sum = 0; for (int i = 0; i < n; i++) { cin >> vec[i].first >> vec[i].second; sum += vec[i].second; } n++; sum += 1e9; vec.push_back({ 1e9,1e9 }); vector<int>sef(n+1); sef[n] = 0; for (int i = 0; i < n; i++) { sef[n - 1 - i] = sef[n - i] + vec[n - 1 - i].second; } vector<int>pref(n); pref[0] = vec[0].second; for (int i = 1; i < n; i++) { pref[i] = pref[i - 1] + vec[i].second; } vector<int>ans1; while (q--) { int r, c; cin >> r >> c; r--; int lo = r; int hi = n - 1; int mid; if (r == 0) { while (lo < hi) { mid = (lo + hi) / 2; if ((sum - sef[mid+1]) < c) { lo = mid + 1; } else if (c == (sum - sef[mid+1])) break; else { hi = mid; } } if ((sum - sef[mid + 1]) < c) mid++; } else { while (lo < hi) { mid = (lo + hi) / 2; if ((sum - pref[r - 1] - sef[mid+1]) < c) { lo = mid + 1; } else if (c == (sum - pref[r - 1] - sef[mid+1])) break; else { hi = mid; } } if ((sum - pref[r - 1] - sef[mid + 1]) < c) mid++; } if (mid == n - 1) mid = -1; ans1.push_back(mid+1); } for (int i = 0; i < ans1.size(); i++) { cout << ans1[i] << endl; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 369 ms | 6448 KB | Output is correct |
2 | Correct | 418 ms | 7300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 204 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |