Submission #1062289

#TimeUsernameProblemLanguageResultExecution timeMemory
1062289BraulinhoGarage (IOI09_garage)C++14
100 / 100
1 ms2508 KiB
#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 timeMemoryGrader output
Fetching results...