Submission #52902

# Submission time Handle Problem Language Result Execution time Memory
52902 2018-06-27T06:57:56 Z szawinis Garage (IOI09_garage) C++17
100 / 100
4 ms 868 KB
#include <bits/stdc++.h>
using namespace std;

int n, m, nxt = 1, r[101], slot[2001], w[2001];
long long ans;
queue<int> wait;
priority_queue<int, vector<int>, greater<int> > avail;
int main() {
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i++) scanf("%d", &r[i]), avail.push(i);
	for(int i = 1; i <= m; i++) scanf("%d", &w[i]);
	for(int i = 1; i <= 2*m; i++) {
		int x;
		scanf("%d", &x);
		if(x > 0) {
			if(wait.empty() && !avail.empty()) slot[x] = avail.top(), avail.pop();
			else wait.push(x);
		} else {
			x *= -1;
			ans += r[slot[x]]*w[x];
			avail.push(slot[x]);
			slot[x] = 0;
			if(!wait.empty()) {
				slot[wait.front()] = avail.top();
				avail.pop();
				wait.pop();
			}
		}
	}
	printf("%lld", ans);
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
garage.cpp:10:48: 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("%d", &r[i]), avail.push(i);
                              ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
garage.cpp:11:35: 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("%d", &w[i]);
                              ~~~~~^~~~~~~~~~~~~
garage.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &x);
   ~~~~~^~~~~~~~~~
# 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 420 KB Output is correct
4 Correct 3 ms 440 KB Output is correct
5 Correct 2 ms 496 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 2 ms 656 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 2 ms 656 KB Output is correct
10 Correct 2 ms 656 KB Output is correct
11 Correct 3 ms 764 KB Output is correct
12 Correct 2 ms 764 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 3 ms 816 KB Output is correct
15 Correct 3 ms 816 KB Output is correct
16 Correct 3 ms 816 KB Output is correct
17 Correct 3 ms 816 KB Output is correct
18 Correct 4 ms 816 KB Output is correct
19 Correct 3 ms 816 KB Output is correct
20 Correct 4 ms 868 KB Output is correct