Submission #1113370

#TimeUsernameProblemLanguageResultExecution timeMemory
1113370NonozeBikeparking (EGOI24_bikeparking)C++17
100 / 100
527 ms13104 KiB
#include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define cmin(a, b) a=min(a, b) #define cmax(a, b) a=max(a, b) #define fi first #define se second #define pb push_back #define mp make_pair #define int long long void solve(); signed main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; } int n, m, q; vector<int> a, b; int calc(int x) { int empl=0, ans=-x; auto ta=a, tb=b; for (int i=0; i<n; i++) { if (tb[i]<x) { x-=tb[i]; continue; } tb[i]-=x, x=0; while (tb[i]) { while (!ta[empl]) empl++; int nb=min(tb[i], ta[empl]); if (empl<i) ans+=nb; else if (empl>i) ans-=nb; ta[empl]-=nb, tb[i]-=nb; } } return ans; } void solve() { cin >> n; a.resize(n), b.resize(n); for (auto &u: a) cin >> u; for (auto &u: b) cin >> u; int sm=0; for (auto u: b) sm+=u; int l=0, r=sm, ans=LLONG_MIN; int cnt=0; while (l<=r) { int mid1=l+(r-l)/3, mid2=l+2*(r-l)/3; int c1=calc(mid1), c2=calc(mid2); if (c1>c2) { r=mid2-1; cmax(ans, c1); } else { l=mid1+1; cmax(ans, c2); } } cout << ans << endl; }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:58:6: warning: unused variable 'cnt' [-Wunused-variable]
   58 |  int cnt=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...