# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
342551 | marvenlee | Garage (IOI09_garage) | C++14 | 3 ms | 364 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;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef string str;
typedef vector<ll> vl;
typedef vector< vector<ll> > vvl;
typedef vector<ii> vii;
typedef vector< vector<ii> > vvii;
typedef vector<iii> viii;
typedef vector< vector<iii> > vviii;
typedef vector<str> vs;
typedef vector< vector<str> > vvs;
typedef long double ld;
//typelower_bounddef priority_queue<long long> pq;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
#define elif else if
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define FOR(i,v) for(auto i:v)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repn(i,a,b) for(int i=(a);i<=(b);i++)
#define repin(i,a,b,x) for(int i=(a);i<(b);i+=x)
#define repnin(i,a,b,x) for(int i=(a);i<=(b);i+=x)
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define fbo find_by_order
#define ook order_of_key
// if else int i = (number <0) ? 1:0 - if (number <0) i=1 else 0
const ll MOD = 1e9 + 7;
const ll INF = 1e9;
const ld EPS = 1e-9;
int main()
{
int n,m;
cin >> n >> m;
int rate[n];
rep(i,0,n){
cin >> rate[i];
}
set<int> slot;
rep(i,0,n) slot.insert(i);
int weight[m];
rep(i,0,m) cin >> weight[i];
queue<int> waiting;
int st[2001]={0};
ll ans=0;
rep(i,0,2*m){
int ev;
cin >> ev;
if(ev>0){
ev--;
waiting.push(ev);
if(slot.empty()) continue;
ev = waiting.front();
waiting.pop();
int use= *slot.begin();
ans += rate[use]*weight[ev];
slot.erase(slot.begin());
st[ev]=use;
//cout <<"Use" << st[ev] << " ";
}
else {
ev++;
ev*=-1;
//cout << "HI" << st[ev] << " ";
slot.insert(st[ev]);
if(!waiting.empty()){
ev = waiting.front();
waiting.pop();
int use= *slot.begin();
ans += rate[use]*weight[ev];
slot.erase(slot.begin());
st[ev]=use;
}
}
//cout << ans << " ";
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |