Submission #542417

#TimeUsernameProblemLanguageResultExecution timeMemory
542417AJ00Garage (IOI09_garage)C++14
65 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int rate[100],par[100],weight[2001],alloted[2001],n; deque<int> waiting; int find(int x,int y){ if (x == par[x]){ par[x] = x+1; return x; } if (x == n-1){ waiting.push_back(y); return -1; } return find(par[x],y); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int t=1,m,x,cur; // cin >> t; while (t--){ cin >> n >> m; for (int i = 0; i < n; i++){ cin >> rate[i]; par[i] = i; } for (int i = 1; i <= m; i++){ cin >> weight[i]; } int ans = 0; for (int i = 0; i < 2*m; i++){ cin >> x; //x--; if (x < 0){ x = abs(x); par[alloted[x]] = alloted[x]; if (!waiting.empty()){ cur = waiting.front(); alloted[cur] = alloted[x]; waiting.pop_front(); ans += (weight[cur]*rate[alloted[cur]]); } } else { cur = find(0,x); if (cur == -1){ continue; } alloted[x] = cur; ans += (weight[x]*rate[cur]); } } cout << ans << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...