# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
292433 | Ruba_K | Garage (IOI09_garage) | C++14 | 2 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1 ;
#define ll long long
int main()
{ios_base::sync_with_stdio(false);cin.tie(0);
int n , m ;
cin >> n >> m ;
int cost[n + 1] , cars[m + 1];
set<int>av;
for(int i = 1 ; i <= n ; i ++){
cin >> cost[i];
av.insert(i);
}
for(int i = 1 ; i <= m ; i ++)
cin >> cars[i];
ll ans = 0 ;
queue<int>q ;
map<int , int >mp ;
for(int i = 0 ; i < m * 2 ; i ++){
int a ;
cin >> a ;
if(a < 0){
av.insert(mp[-a]);
int b = *av.begin();
if(q.size()){
int f = q.front();
q.pop();
ans += cost[b] * 1ll * cars[f];
av.erase(b);
mp[f] = b ;
}
}
else{
q.push(a);
if(av.empty())
continue ;
int b = *av.begin();
int f = q.front();
q.pop();
ans += 1ll * cost[b] * cars[f];
av.erase(b);
mp[f] = b ;
}
}
cout << ans ;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |