Submission #141367

# Submission time Handle Problem Language Result Execution time Memory
141367 2019-08-07T15:25:44 Z ansol4328 Garage (IOI09_garage) C++11
100 / 100
3 ms 380 KB
#include<stdio.h>
 
int n, m, s[102], w[2002];
int sum, q[2002], r=0, f=0, check[102], num[2002];
 
int main()
{
    int i, j, k;
    scanf("%d",&n);
    scanf("%d",&m);
    for(i=1 ; i<=n ; i++) scanf("%d",&s[i]);
    for(i=1 ; i<=m ; i++) scanf("%d",&w[i]);
    for(i=1 ; i<=m*2 ; i++)
    {
        scanf("%d",&k);
        if(k>0)
        {
            for(j=1 ; j<=n ; j++) if(check[j]==0) break;
            if(j>n) q[++r]=k;
            else check[j]=k, num[k]=j, sum+=(w[k]*s[j]);
        }
        else if(k<0)
        {
            k*=-1;
            check[num[k]]=0;
            if(f<r)
            {
                f++;
                for(j=1 ; j<=n ; j++) if(check[j]==0) break;
                check[j]=q[f], num[q[f]]=j, sum+=(w[q[f]]*s[j]);
            }
        }
    }
    printf("%d",sum);
    return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
garage.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&m);
     ~~~~~^~~~~~~~~
garage.cpp:11:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1 ; i<=n ; i++) scanf("%d",&s[i]);
                           ~~~~~^~~~~~~~~~~~
garage.cpp:12:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(i=1 ; i<=m ; i++) scanf("%d",&w[i]);
                           ~~~~~^~~~~~~~~~~~
garage.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&k);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct