Submission #739218

#TimeUsernameProblemLanguageResultExecution timeMemory
739218UnforgettableplGarage (IOI09_garage)C++17
100 / 100
1 ms340 KiB
/* ID: samikgo1 TASK: LANG: C++ */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pii; #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() //#define f first //#define s second //#define x first //#define y second const int INF = INT32_MAX; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("measurement.in","r",stdin); // freopen("measurement.out","w",stdout); int n,m; cin >> n >> m; vector<ll> spaces(n); vector<ll> weights(m); vector<ll> events(2*m); set<ll> free_spaces; vector<ll> taken(m,-1); queue<ll> line; for(ll&i:spaces)cin>>i; for(ll&i:weights)cin>>i; for(ll&i:events)cin>>i; for (int i = 0; i < n; i++) { free_spaces.emplace(i); } ll ans = 0; for(ll&i:events){ if(i>0){ // Car cum if(!free_spaces.empty()){ taken[i-1]=*free_spaces.begin(); ans+=spaces[*free_spaces.begin()]*weights[i-1]; free_spaces.erase(free_spaces.begin()); } else { line.emplace(i-1); } } else { // Car go i = -i; // Convert to gud free_spaces.emplace(taken[i-1]); // Return // process queue if(!line.empty()){ taken[line.front()]=*free_spaces.begin(); ans+=spaces[*free_spaces.begin()]*weights[line.front()]; free_spaces.erase(free_spaces.begin()); line.pop(); } } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...