Submission #260165

#TimeUsernameProblemLanguageResultExecution timeMemory
260165jdhColouring a rectangle (eJOI19_colouring)C++17
0 / 100
134 ms7672 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; vector<ll> cost1(n+m-1),cost2(n+m-1); for(int i = 0; i < n+m-1; ++i) cin >> cost1[i]; for(int i = 0; i < n+m-1; ++i) cin >> cost2[i]; ll p1 = 0,p2 = 0,i1 = 0,i2 = 0; int x = 0,y = m-1; for(int i = 0; i < n+m-1; ++i){ if((x+y)&1) i1 += cost1[i]; else p1 += cost1[i]; if(y > 0) --y; else ++x; } x = 0,y = 0; for(int i = 0; i < n+m-1; ++i){ if((x+y)&1) i2 += cost2[i]; else p2 += cost2[i]; if(x < n-1) ++x; else ++y; } ll ans = 0; if(p1 <= p2){ ans += p1; if(m == n){ if((n%2 == 0) and cost1[0] + cost1[n+m-2] > cost2[n-1]){ ans += cost2[n-1] - cost1[0] - cost1[n+m-2]; } } else{ if((m%2 == 0) and cost1[0] > cost2[m-1]){ ans += cost2[m-1] - cost1[0]; } if((n%2 == 0) and cost1[n+m-2] > cost2[n-1]){ ans += cost2[n-1] - cost1[n+m-2]; } } } else{ ans += p2; if(m == n){ if(cost2[0] + cost2[n+m-2] > cost1[n-1]){ ans += cost1[n-1] - cost2[0] - cost2[n+m-1]; } } else{ if(cost2[0] > cost1[m-1]){ ans += cost1[m-1] - cost2[0]; } if(((n+m)%2 == 0) and cost2[n+m-2] > cost1[n-1]){ ans += cost1[n-1] - cost2[n+m-2]; } } } if(i1 <= i2){ ans += i1; if(m == n){ if((n%2 == 1) and cost1[0] + cost1[n+m-2] > cost2[n-1]){ ans += cost2[n-1] - cost1[0] - cost1[n+m-2]; } } else{ if((m%2 == 1) and cost1[0] > cost2[m-1]){ ans += cost2[m-1] - cost1[0]; } if((n%2 == 1) and cost1[n+m-2] > cost2[n-1]){ ans += cost2[n-1] - cost1[n+m-2]; } } } else{ ans += i2; if(m != n){ if(((n+m)%2 == 1) and cost2[n+m-2] > cost1[n-1]){ ans += cost1[n-1] - cost2[n+m-2]; } } } cout << ans; return 0; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...