답안 #474088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
474088 2021-09-16T20:55:27 Z ValiAntonie Garage (IOI09_garage) C++14
100 / 100
2 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

int n,mr,i,x,m[2001],j,ok,indice;
queue <int> Q;
long long suma;
pair<int,int> v[101];

int main()
{
    cin>>n>>mr;
    for(i=1;i<=n;i++)
        cin>>v[i].first;
    for(i=1;i<=mr;i++)
        cin>>m[i];
    for(i=1;i<=2*mr;i++){
        cin>>x;
        if(x > 0){
            ok = 0;
            for(j=1;j<=n;j++){
                if(!v[j].second){
                    suma += 1LL * m[x] * v[j].first;
                    v[j].second = x;
                    ok = 1;
                    break;
                }
            }
            if(!ok)
                Q.push(x);
        }
        else{
            indice = 0;
            for(j=1;j<=n;j++){
                if(v[j].second == -x){
                    indice = j;
                    v[j].second = 0;
                    break;
                }
            }
            if(Q.empty()==false){
                suma += 1LL * m[Q.front()] * v[indice].first;
                v[indice].second = Q.front();
                Q.pop();
            }
        }
    }
    cout << suma;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 292 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 288 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 2 ms 204 KB Output is correct