Submission #1151595

#TimeUsernameProblemLanguageResultExecution timeMemory
1151595RafiullahBikeparking (EGOI24_bikeparking)C++20
100 / 100
25 ms4936 KiB
#include<bits/stdc++.h> // #include <ext/pb_ds/tree_policy.hpp> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; #define int long long const int N = 5e5 + 5; const int mod = 1e9 + 7; const int mod1 = 998244353; const int LG = 20; // #define s(i) (*s.find_by_order(i)) // Warning : Read this line. int power(int b,int e){ if(e<=0)return 1; int o = power(b,e>>1); o *= o, o %= mod1; if(e % 2)o *= b, o %= mod1; return o; } int n; int cal(vector<int> a,vector<int> b){ int i = 1; int j = 1; int ans = 0; while(j <= n and i <= n){ int e = min(a[i],b[j]); if(i < j)ans += e; else if(i > j)ans -= e; a[i] -= e, b[j] -= e; if(a[i] == 0) i ++; if(b[j] == 0) j ++; } return ans; } void solve(){ cin >> n; vector<int> a(n + 1), b(n + 1); for(int i = 1 ; i <= n ; i ++)cin >> a[i]; for(int i = 1 ; i <= n ; i ++)cin >> b[i]; int S = 0;int ans = 0; int med = 0; for(int i = 1 ; i <= n ; i ++){ int e = min(S, b[i]); S -= e; b[i] -= e; ans += e; int t = min(b[i], med); b[i] -= t, med -= t; t = min(b[i], a[i]); med += t, b[i] -= t, a[i] -= t; S += a[i]; ans -= b[i]; } cout << ans << '\n'; } signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int t = 1; // cin >> t; while(t --){ solve(); } }
#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...