Submission #569411

#TimeUsernameProblemLanguageResultExecution timeMemory
569411Aurora2005Garage (IOI09_garage)C++14
40 / 100
2 ms340 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int N,M; cin >> N >> M; vector<long long int> R(N); for(int i=0;i<N;i++) cin >> R[i]; vector<long long int> W(M); for(int i=0;i<M;i++) cin >> W[i]; priority_queue<int,vector<int>,greater<int>> que1; for(int i=0;i<N;i++) que1.push(i); queue<int> que2; vector<int> P(M); long long int ans = 0; for(int i=0;i<2*M;i++){ int C; cin >> C; if(C > 0){ C--; if(que1.size() == 0) que2.push(C); else{ int a = que1.top(); que1.pop(); ans += R[a]*W[C]; P[C] = a; } } else{ C++; C *= -1; int a = P[C]; que1.push(a); if(que2.size() > 0){ int b = que1.top(); int c = que2.front(); ans += R[b]*W[c]; que1.pop(); que2.pop(); } } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...