제출 #113097

#제출 시각아이디문제언어결과실행 시간메모리
113097popovicirobertGarage (IOI09_garage)C++14
100 / 100
3 ms436 KiB
#include <bits/stdc++.h> #define lsb(x) (x & (-x)) #define ll long long #define ull unsigned long long // 217 // 44 using namespace std; int main() { //ifstream cin("A.in"); //ofstream cout("A.out"); int i, n, m; ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; vector <int> space(n + 1), car(m + 1); for(i = 1; i <= n; i++) { cin >> space[i]; } for(i = 1; i <= m; i++) { cin >> car[i]; } queue < pair <int, int> > a, b; for(i = 1; i <= 2 * m; i++) { int id; cin >> id; if(id > 0) { a.push({id, i}); } else { b.push({-id, i}); } } set <int> act; for(i = 1; i <= n; i++) { act.insert(i); } vector <int> where(m + 1); ll ans = 0; for(i = 1; i <= 2 * m && a.size(); i++) { if(act.size() > 0) { if(b.size() == 0 || (b.size() && a.front().second < b.front().second)) { auto pos = *act.begin(); act.erase(act.begin()); ans += 1LL * car[a.front().first] * space[pos]; where[a.front().first] = pos; a.pop(); } else { act.insert(where[b.front().first]); b.pop(); } } else { act.insert(where[b.front().first]); b.pop(); } } cout << ans; //cin.close(); //cout.close(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...