Submission #1151587

#TimeUsernameProblemLanguageResultExecution timeMemory
1151587RafiullahBikeparking (EGOI24_bikeparking)C++20
25 / 100
26 ms7492 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), p(n + 1); for(int i = 1 ; i <= n ; i ++)cin >> a[i]; for(int i = 1 ; i <= n ; i ++)cin >> b[i], p[i] = p[i - 1] + b[i]; int S = 0; int r = 2; int ans = 0; for(int i = 1 ; i < n ; i ++){ r = max(r, i + 1); while(r <= n and a[i] > 0){ int e = min(a[i], b[r]); a[i] -= e, b[r] -= e; if(b[r] == 0)r ++; ans += e; } } for(int i = 1 ; i <= n ; i++){ int o = min(a[i],b[i]); a[i] -= o, b[i] -= o; 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...