Submission #310932

# Submission time Handle Problem Language Result Execution time Memory
310932 2020-10-08T15:35:43 Z Benmath Garage (IOI09_garage) C++14
100 / 100
4 ms 512 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    long long int a[n+1];
    long long int b[m+1];
    int vis[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
        vis[i]=0;
    }
    int d1[m+1];
    for(int i=1;i<=m;i++){
        cin>>b[i];
        d1[i]=-1;
    }
    
    long long int sum=0;
    queue<long long int >q;
    for(int i=0;i<(2*m);i++){
        int x;
        cin>>x;
        if(x>0){
            q.push(x);
            
        }else{
            x=abs(x);
            vis[d1[x]]--;
            d1[x]=-1;
        }
        if(!q.empty()){
            int a1=q.front();
            int brojac=0;
            for(int j=1;j<=n;j++){
                if(vis[j]==0 and brojac==0){
                    brojac++;
                    sum=sum+a[j]*b[a1];
                    vis[j]++;
                    d1[a1]=j;
                }
            }
            if(brojac!=0){
            q.pop();
            }
        }
    }
    cout<<sum;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 512 KB Output is correct
20 Correct 4 ms 384 KB Output is correct