# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887875 | JakobZorz | Garage (IOI09_garage) | C++17 | 1 ms | 492 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<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second
void solve(){
int n,m;
cin>>n>>m;
vector<int>r(n);
for(int&i:r)
cin>>i;
vector<int>w(m);
for(int&i:w)
cin>>i;
vector<int>e(2*m);
for(int&i:e)
cin>>i;
int res=0;
vector<int>parked(n,-1);
int timer=0;
queue<int>q;
for(int event:e){
if(event>0){
event--;
bool par=false;
for(int i=0;i<n;i++){
if(parked[i]==-1){
parked[i]=event;
par=true;
break;
}
}
if(!par)
q.push(event);
}else{
event=-event-1;
for(int i=0;i<n;i++){
if(parked[i]==event){
parked[i]=-1;
res+=r[i]*w[event];
if(q.size()){
parked[i]=q.front();
q.pop();
}
}
}
}
timer++;
}
cout<<res<<"\n";
}
int main(){
ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
//freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
int t=1;//cin>>t;
while(t--)solve();
return 0;
}
/*
3 4
2
3
5
200
100
300
800
3
2
-3
1
4
-4
-2
-1
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |