Submission #134418

# Submission time Handle Problem Language Result Execution time Memory
134418 2019-07-22T16:30:21 Z sheismad Garage (IOI09_garage) C++14
100 / 100
3 ms 380 KB
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

int const MAXN = 101,MAXM = 2001;
int park[MAXN];

int main() {
	//freopen("input.txt","r",stdin);
	
	int n,m,weight[MAXM],price[MAXN],car;
	long long ans = 0;
	queue<int> q;
	scanf("%d %d\n",&n,&m);
	for (int i=0;i<n;i++) scanf("%d",&price[i]);
	for (int i=0;i<m;i++) scanf("%d",&weight[i]);
	
	int j,mini = 0;
	for (int i=0;i<m*2;i++) {
		scanf("%d",&car);
		j = 0;
		//arrive
		if (car>0) {
			while (park[j] && j<n) j++;
			//there is an empty space
			if (j<n) {
				if (q.empty()) {
					park[j] = car; ans += price[j]*weight[car-1];
				}
				else {
					q.push(car); park[j] = q.front(); ans += price[j]*weight[q.front()-1]; q.pop(); 
				}
			} // there is not
			else q.push(car);
		} //departure
		else {
			car *= -1;
			while (park[j]!=car) j++;
			park[j] = 0;
			if (!q.empty()) {
				park[j] = q.front();
				ans += price[j]*weight[q.front()-1];
				q.pop();
			}	
		}
	}
	
	cout << ans;	
	return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:20:8: warning: unused variable 'mini' [-Wunused-variable]
  int j,mini = 0;
        ^~~~
garage.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d\n",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~~~
garage.cpp:17:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=0;i<n;i++) scanf("%d",&price[i]);
                        ~~~~~^~~~~~~~~~~~~~~~
garage.cpp:18:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i=0;i<m;i++) scanf("%d",&weight[i]);
                        ~~~~~^~~~~~~~~~~~~~~~~
garage.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&car);
   ~~~~~^~~~~~~~~~~
# 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 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 276 KB Output is correct
9 Correct 2 ms 252 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 3 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