# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
793726 | 2023-07-26T05:59:37 Z | 반딧불(#10057) | Triangle Collection (CCO23_day2problem3) | C++17 | 312 ms | 388 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, q; ll arr[200002]; ll val[200002]; void solve(){ set<int> st; ll ans = 0; for(int i=1; i<=n; i++){ val[i] = arr[i]; if(val[i]) st.insert(i); } for(int i=1; i<=n; i++){ while(val[i] >= 2){ if(st.empty() || *st.begin() >= 2*i || (*st.begin() == i && val[i] == 2 && ((int)st.size() == 1 || *next(st.begin()) >= 2*i))) break; int x = i, y = *st.begin(); if(y==i && val[i]==2) y = *next(st.begin()); ll k; if(x==y) k = val[x] / 3; else k = min(val[x] / 2, val[y]); ans += k; val[x] -= k*2, val[y] -= k; if(!val[x]) st.erase(x); if(!val[y]) st.erase(y); } } printf("%lld\n", ans); } int main(){ scanf("%d %d", &n, &q); for(int i=1; i<=n; i++) scanf("%lld", &arr[i]); while(q--){ int x; ll v; scanf("%d %lld", &x, &v); arr[x] += v; solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 7 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 7 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 312 ms | 388 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 250 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 7 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |