제출 #79870

#제출 시각아이디문제언어결과실행 시간메모리
79870shoemakerjoGarage (IOI09_garage)C++14
100 / 100
3 ms1088 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int, int> int N, M; int rate[105]; int weight[10010]; int myspot[10010]; set<pii> curout; set<int> openspots; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> N >> M; for (int i = 1; i <= N; i++) { cin >> rate[i]; openspots.insert(i); } for (int i = 1; i <= M; i++) { cin >> weight[i]; } int ct = 0; int ans = 0; int cur; for (int i = 0; i < 2*M; i++) { cin >> cur; if (cur < 0) { cur *= -1; // openspots.insert(myspot[cur]); if (curout.size()) { pii val = *curout.begin(); curout.erase(curout.begin()); ans += weight[val.second] * rate[myspot[cur]]; myspot[val.second] = myspot[cur]; } else openspots.insert(myspot[cur]); } else { if (openspots.size()) { ans += weight[cur] * (rate[*openspots.begin()]); myspot[cur] = *openspots.begin(); openspots.erase(openspots.begin()); } else curout.insert(pii(++ct, cur)); } } // for (int i = 1; i <= M; i++) { // cout << i << " went to spot " << myspot[i] << endl; // } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...