제출 #1151557

#제출 시각아이디문제언어결과실행 시간메모리
1151557RafiullahBikeparking (EGOI24_bikeparking)C++20
25 / 100
35 ms9800 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 ans = cal(a,b); int o = 0; int i = n - 1; int j = n; while(i>0 and j > 0){ int e = min(a[i], b[j]); a[i] -= e, b[j] -= e; o += e; if(a[i] == 0)i --; if(b[j] == 0 and i < j - 1)j --; if(b[j] == 0 and i >= j - 1)i --, j --; } for(int i = 1 ; i <= n ; i ++){ int e = min(a[i],b[i]); a[i] -= e, b[i] -= e; } o += cal(a,b); cout << max(ans, o) << '\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...