Submission #1094829

# Submission time Handle Problem Language Result Execution time Memory
1094829 2024-09-30T16:04:56 Z salmon Garage (IOI09_garage) C++14
100 / 100
1 ms 348 KB
#include <bits/stdc++.h>
using namespace std;

int N;
int M;
int R[110];
set<int> sat;
int inv[2110];
int tim[110];
int W[2100];
int x;
queue<int> q;

int main(){

    scanf(" %d",&N);
    scanf(" %d",&M);

    for(int i = 0; i < N; i++){
        scanf(" %d",&R[i]);
        sat.insert(i);
    }

    for(int i = 1; i <= M; i++){
        inv[i] = -1;
        scanf(" %d",&W[i]);
    }

    long long int ans = 0;

    for(int i = 0; i < M * 2; i ++){
        scanf(" %d",&x);

        if(x < 0){
            x = -x;
            sat.insert(inv[x]);
            ans += R[inv[x]] * W[x];
            if(!q.empty()){
                x = q.front();
                q.pop();
            }
            else x = -1;
        }

        if(x > 0){
            if(sat.empty()){
                q.push(x);
                continue;
            }
            int l = *sat.begin();
            sat.erase(sat.begin());
            tim[l] = i;
            inv[x] = l;
        }
    }

    printf("%lld",ans);
}

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",&N);
      |     ~~~~~^~~~~~~~~~
garage.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf(" %d",&M);
      |     ~~~~~^~~~~~~~~~
garage.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf(" %d",&R[i]);
      |         ~~~~~^~~~~~~~~~~~~
garage.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         scanf(" %d",&W[i]);
      |         ~~~~~^~~~~~~~~~~~~
garage.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf(" %d",&x);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct