Submission #733919

# Submission time Handle Problem Language Result Execution time Memory
733919 2023-05-01T11:59:11 Z vjudge1 Garage (IOI09_garage) C++17
100 / 100
2 ms 212 KB
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
int main() {
	int t, n, m, ans, i, z,j, x, r, p, s, y;
	
	cin >> n >> m;
	
	ll a[n + 2], b[m + 2], c[m + 2];
	ans = 0;
	
	priority_queue < ll , vector < ll > , greater< ll >> pq;
	for ( i = 1; i <= n; i ++) {
		cin >> a[i];
		pq.push(i);
	}
	for ( i = 1; i <= m; i ++) {
		cin >> b[i];
	}
	queue < ll > q;
	for ( i = 1; i <= 2 * m; i ++) {
		cin >> x;
		
		if ( x < 0) {
			r = -x;
			pq.push(c[r]);
		}
		else {
			if ( pq.empty()) {
				q.push(x);
				continue;
			}
			p = pq.top();
			pq.pop();
			c[x] = p;
			ans += (a[p] * b[x]);
		}
		if ( !pq.empty() && !q.empty()) {
			x = q.front();
			q.pop();
			p = pq.top();
			pq.pop();
			c[x] = p;
			ans += (a[p] * b[x]);
		}
	}
	cout << ans << endl;
	
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:6:6: warning: unused variable 't' [-Wunused-variable]
    6 |  int t, n, m, ans, i, z,j, x, r, p, s, y;
      |      ^
garage.cpp:6:23: warning: unused variable 'z' [-Wunused-variable]
    6 |  int t, n, m, ans, i, z,j, x, r, p, s, y;
      |                       ^
garage.cpp:6:25: warning: unused variable 'j' [-Wunused-variable]
    6 |  int t, n, m, ans, i, z,j, x, r, p, s, y;
      |                         ^
garage.cpp:6:37: warning: unused variable 's' [-Wunused-variable]
    6 |  int t, n, m, ans, i, z,j, x, r, p, s, y;
      |                                     ^
garage.cpp:6:40: warning: unused variable 'y' [-Wunused-variable]
    6 |  int t, n, m, ans, i, z,j, x, r, p, s, y;
      |                                        ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 212 KB Output is correct
20 Correct 2 ms 212 KB Output is correct