Submission #720620

#TimeUsernameProblemLanguageResultExecution timeMemory
720620AnjaJGarage (IOI09_garage)C++14
100 / 100
2 ms364 KiB
#include <bits/stdc++.h> using namespace std; int ParkSp, Cars; int Rate[101]; int Weight[2001]; bool Taken[101] = {}; int takenSpace[2001] = {}; int takenSpaces = 0; int Profit = 0; queue <int> q; void enter(int car) { if(takenSpaces == ParkSp) return q.push(car); for(int i=1; i<=ParkSp; i++) { if(Taken[i]) continue; takenSpace[car] = i; Taken[i] = true; Profit+=Rate[i]*Weight[car]; takenSpaces++; return; } } void leave(int car) { takenSpaces--; Taken[takenSpace[car]] = false; takenSpace[car] = 0; while(takenSpaces < ParkSp && !q.empty()) { enter(q.front()); q.pop(); } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>ParkSp>>Cars; for(int i=1; i<=ParkSp; i++) { cin>>Rate[i]; } for(int i=1; i<=Cars; i++) { cin>>Weight[i]; } for(int i=1; i<=2*Cars; i++) { int car; cin>>car; if(car<0) leave(-car); else enter(car); } cout<<Profit; }
#Verdict Execution timeMemoryGrader output
Fetching results...