Submission #74655

#TimeUsernameProblemLanguageResultExecution timeMemory
74655arman_ferdousGarage (IOI09_garage)C++17
100 / 100
4 ms888 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int n, m, r[110], w[2010], arr[110];

int main() {
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%d", &r[i]);
	for(int i = 1; i <= m; i++)
		scanf("%d", &w[i]);
	ll ans = 0;
	int Q = m + m;
	queue<int> q;
	while(Q--) {
		int id; scanf("%d", &id);
		if(id < 0) { 
			id = -id;
			for(int i = 1; i <= n; i++) if(arr[i] == id) {
				arr[i] = 0;
				if(!q.empty()) {
					arr[i] = q.front();
					ans += 1ll * w[arr[i]] * r[i];
					q.pop();
				} break;
			}
		}
		else {
			for(int i = 1; i <= n; i++) if(arr[i] == 0) {
				arr[i] = id; id = 0; 
				ans += 1ll * w[arr[i]] * r[i]; break;
			}
			if(id) q.push(id);
		}
	} printf("%lld\n", ans);
	return 0;
}

Compilation message (stderr)

garage.cpp: In function 'int main()':
garage.cpp:8: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:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &r[i]);
   ~~~~~^~~~~~~~~~~~~
garage.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &w[i]);
   ~~~~~^~~~~~~~~~~~~
garage.cpp:17:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int id; scanf("%d", &id);
           ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...