답안 #377133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377133 2021-03-13T03:34:43 Z kevinxiehk Garage (IOI09_garage) C++17
100 / 100
3 ms 364 KB
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,cnt=0,t;cin>>n>>m;
    long long rev=0;
    int rate[n+5],park[n+5],weight[m+5];
    queue<int>q;
    for(int i=0;i<=n;i++)park[i]=-1;
    for(int i=0;i<n;i++)cin>>rate[i];
    for(int i=1;i<=m;i++)cin>>weight[i];
    for(int i=0;i<m*2;i++){
        cin>>t;
        if(t>0){
            if(cnt==n)q.push(t);
            else{
                int now=0;
                while(park[now]!=-1)now++;
                park[now]=t;
                rev+=rate[now]*weight[t];
                cnt++;
            }
        }
        else{
            t=-t;
            int now=0;
            while(park[now]!=t)now++;
            park[now]=-1;
            cnt--;
            if(!q.empty()){
                t=q.front();
                q.pop();
                park[now]=t;
                rev+=rate[now]*weight[t];
                cnt++;
            }
        }
    }
    cout<<rev<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 364 KB Output is correct
19 Correct 2 ms 364 KB Output is correct
20 Correct 3 ms 364 KB Output is correct