Submission #207324

# Submission time Handle Problem Language Result Execution time Memory
207324 2020-03-07T07:58:52 Z DodgeBallMan Garage (IOI09_garage) C++14
100 / 100
6 ms 376 KB
#include <bits/stdc++.h>
 
#define long long long
 
using namespace std;
 
const int N = 2e3+5;
 
int n, m, pos[N];
long r[N], w[N];
queue<int> Q;
priority_queue<int, vector<int>, greater<int> > PQ;
 
int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++) scanf("%lld", r+i), PQ.emplace(i);
    for(int i = 1; i <= m; i++) scanf("%lld", w+i);
 
    long ans = 0;
    for(int i = 1, a; i <= 2 * m; i++) {
        scanf("%d", &a);
        if(a > 0) Q.emplace(a);
        else {
            int garage = pos[-a];
            PQ.emplace(garage);
        }
        while(!Q.empty() && !PQ.empty()) {
            int now = Q.front(); Q.pop();
            int garage = PQ.top(); PQ.pop();
            pos[now] = garage;
            ans += r[garage] * w[now];
        }
    }
    printf("%lld\n", ans);
 
    return 0;
}

Compilation message

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