Submission #1058776

#TimeUsernameProblemLanguageResultExecution timeMemory
1058776Mr_HusanboyBikeparking (EGOI24_bikeparking)C++17
100 / 100
95 ms16884 KiB
//#pragma GCC optimize("Ofast,O3") //#pragma GCC target("avx,avx2") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debugger.cpp" #else #define debug(...) #endif template<class T> int len(T &a){ return a.size(); } using ll = long long; using pii = pair<int,int>; #define all(a) (a).begin(), (a).end() #define ff first #define ss second string fileio = ""; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD = 1e9 + 7; const int inf = 1e9; const ll infl = 1e18; const int maxn = 1e5 + 1; void yesno(bool ok){ cout << (ok ? "Yes\n" : "No\n"); } struct fenwick{ int n; vector<int> f; fenwick (int n) : n(n), f(n){}; void inc(int i, int val){ for(; i < n; i |= i + 1) f[i] += val; } int get(int i){ int res = 0; for(; i >= 0; i = (i & (i + 1)) - 1) res += f[i]; return res; } int get(int l, int r){ return get(r) - get(l - 1); } }; void solve(){ int n; cin >> n; vector<int> t(n), s(n); for(int i = 0; i < n; i ++) cin >> t[i]; for(int i = 0; i < n; i ++) cin >> s[i]; int ans = 0; set<int> rem; for(int i = 0; i < n; i ++) if(t[i]) rem.insert(i); for(int i = 0; i < n; i ++){ while(s[i]){ auto it = rem.lower_bound(i); if(it == rem.begin()) break; -- it; int add = min(t[*it], s[i]); s[i] -= add; t[*it] -= add; ans += add; if(t[*it] == 0) rem.erase(it); } } for(int i = 0; i < n; i ++){ s[i] -= t[i]; ans -= max(0, s[i]); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); auto start = chrono::high_resolution_clock::now(); #ifndef LOCAL if(fileio.size()){ freopen((fileio + ".in").c_str(), "r", stdin); freopen((fileio + ".out").c_str(), "w", stdout); } #endif int testcases = 1; #ifdef Tests cin >> testcases; #endif while(testcases --){ solve(); if(testcases) cout << '\n'; #ifdef LOCAL else cout << '\n'; cout << "_________________________" << endl; #endif } #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:92:10: warning: variable 'start' set but not used [-Wunused-but-set-variable]
   92 |     auto start = chrono::high_resolution_clock::now();
      |          ^~~~~
Main.cpp:95:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |         freopen((fileio + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:96:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |         freopen((fileio + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...