Submission #287380

# Submission time Handle Problem Language Result Execution time Memory
287380 2020-08-31T16:34:04 Z Namnamseo Garage (IOI09_garage) C++17
100 / 100
2 ms 384 KB
#include <cstdio>
#include <cstdlib>

int sc[2010];
int ww[2010];
int place[2010];
int who  [2010];
int n,m;

int queue[2010];
int h,t;

int main()
{
    int income=0;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; ++i) scanf("%d",sc+i);
    for(int i=1; i<=m; ++i) scanf("%d",ww+i);
    int a;
    int filled=0;
    for(int _=1; _<=2*m; ++_){
        scanf("%d",&a);
        if(a>0){
            queue[h++]=a;
        } else {
            a=-a;
            who[place[a]]=0;
            place[a]=0;
            --filled;
        }
        while(filled<n && t<h){
            int i;
            for(i=1; i<=n; ++i){
                if(who[i]==0) break;
            }
            who[i]=queue[t];
            place[queue[t]]=i;
            income += sc[i]*ww[who[i]];
            ++filled; ++t;
        }
    }
    printf("%d\n",income);
    return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   16 |     scanf("%d%d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~
garage.cpp:17:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |     for(int i=1; i<=n; ++i) scanf("%d",sc+i);
      |                             ~~~~~^~~~~~~~~~~
garage.cpp:18:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     for(int i=1; i<=m; ++i) scanf("%d",ww+i);
      |                             ~~~~~^~~~~~~~~~~
garage.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   22 |         scanf("%d",&a);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 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 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct