제출 #647829

#제출 시각아이디문제언어결과실행 시간메모리
647829ymmGarage (IOI09_garage)C++17
100 / 100
2 ms340 KiB
#include <bits/stdc++.h> #define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x) #define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x) typedef long long ll; typedef std::pair<int, int> pii; typedef std::pair<ll , ll > pll; using namespace std; const int N = 2010; int occupied_by[N]; int rate[N]; int weight[N]; queue<int> que; pii events[2*N]; int n, m; int first_free() { Loop (i,0,n) if (occupied_by[i] == -1) return i; return -1; } void leave(int x) { Loop (i,0,n) if (occupied_by[i] == x) occupied_by[i] = -1; } int main() { cin.tie(0) -> sync_with_stdio(false); cin >> n >> m; Loop (i,0,n) cin >> rate[i]; Loop (i,0,m) cin >> weight[i]; Loop (i,0,2*m) { int x; cin >> x; if (x>0) --x; events[i] = {i, x}; } sort(events, events+2*m); memset(occupied_by, -1, sizeof(occupied_by)); int ans = 0; Loop (i,0,2*m) { int x = events[i].second; if (x >= 0) que.push(x); else leave(~x); while (que.size() && first_free() != -1) { int p = first_free(); int c = que.front(); que.pop(); occupied_by[p] = c; ans += rate[p] * weight[c]; } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...