Submission #601960

#TimeUsernameProblemLanguageResultExecution timeMemory
601960snokesDistributing Candies (IOI21_candies)C++17
3 / 100
5079 ms13224 KiB
#include <bits/stdc++.h> #include "candies.h" using namespace std; #ifdef LOCAL void print() {cerr << "]" << endl;} template<typename Head, typename... Tail> void print(Head H, Tail... T) {cerr << H; if(sizeof...(T)) cerr << ", "; print(T...);} template<typename T> ostream& operator << (ostream& os, vector<T> v) {os << "["; string sep = ""; for(auto& x : v) {os << sep << x; sep = ", ";} return os << "]";} template<typename A, typename B> ostream& operator << (ostream& os, pair<A, B> p) {return os << "(" << p.first << ", " << p.second << ")";} #define dbg(x...) cerr << "[" << #x << ": ", print(x); #else #define dbg(x...) 42; #endif // LOCAL #define vt vector #define sz(x) int((x).size()) #define ll long long #define pb push_back #define all(x) (x).begin(), (x).end() vt<int> distribute_candies(vt<int> C, vt<int> L, vt<int> R, vt<int> v) { int N = sz(C); int Q = sz(L); vt<int> ans(N); for(int i = 0; i < Q; i++) { for(int j = L[i]; j <= R[i]; j++) { if(v[i] > 0) { int new_val = min(C[j], ans[j] + v[i]); int take = new_val - ans[j]; ans[j] += take; } else if(v[i] < 0) { int new_val = max(0, ans[j] + v[i]); int take = ans[j] - new_val; ans[j] -= take; } } } return ans; } /* int main() { int N; cin >> N; vt<int> C(N); for(int i = 0; i < N; i++) cin >> C[i]; int Q; cin >> Q; vt<int> L(Q), R(Q), V(Q); for(int i = 0; i < Q; i++) cin >> L[i] >> R[i] >> V[i]; for(int x : distribute_candies(C, L, R, V)) cout << x << " "; cout << "\n"; } */ /* 3 10 15 13 2 0 2 20 0 1 -11 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...