# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
397591 | ak2006 | Garage (IOI09_garage) | C++14 | 3 ms | 332 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;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
int n,m;
cin>>n>>m;
vi r(n + 1),w(m + 1),ans(m + 1);
vb taken(n + 1,false);
vi pos(m + 1,-1);
for (int i = 1;i<=n;i++)cin>>r[i];
for (int i = 1;i<=m;i++)cin>>w[i];
int x = 2 * m;
queue<int>q;
while (x--){
int i;
cin>>i;
if (i < 0){
i = -i;
taken[pos[i]] = 0;
while (!q.empty()){
int cur = q.front();
int index = -1;
for (int j = 1;j<=n;j++){
if (!taken[j]){index = j;break;}
}
if (index == -1)break;
pos[cur] = index;
ans[cur] = r[index] * w[cur];
taken[index] = 1;
q.pop();
}
}
else{
for (int j = 1;j<=n;j++){
if (!taken[j]){pos[i] = j;taken[j] = 1;ans[i] = r[j] * w[i];break;}
}
if (pos[i] == -1)
q.push(i);
}
}
ll tot = 0;
for (int i = 1;i<=m;i++)tot += (ll)ans[i];
cout<<tot;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |