# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1062289 | Braulinho | Garage (IOI09_garage) | C++14 | 1 ms | 2508 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;
#define ll long long
const int mod = 998244353;
const int maxn=200005;
int n,m,R[maxn],W[maxn],c[maxn];
bool activador[maxn];
queue<int> q;
void solve(){
cin >> n >> m;
for(int i = 1; i <= n; i++) {
cin >> R[i];
}
for(int i=1;i<=m;i++) {
cin >> W[i];
}
int ans =0;
for(int i = 1; i <= 2 * m; i++) {
int a;
cin >> a;
if(a > 0) {
q.push(a);
} else{
activador[-a] = true;
for(int i = 1; i <= n; i++) {
if(c[i] == -a) {
c[i]=0;
}
}
}
while(!q.empty()){
int p = 0;
for(int i = n; i >= 1; i--) {
if(!c[i]) {
p = i;
}
}
if(!p) {
break;
}
int u = q.front();
q.pop();
ans += W[u] * R[p];
if(!activador[u]) {
c[p]=u;
}
}
}
cout << ans << endl;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(10);
int t = 1;
while(t--) {
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |