Submission #1062289

# Submission time Handle Problem Language Result Execution time Memory
1062289 2024-08-17T01:38:26 Z Braulinho Garage (IOI09_garage) C++14
100 / 100
1 ms 2508 KB
#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
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2508 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct