Submission #733919

#TimeUsernameProblemLanguageResultExecution timeMemory
733919vjudge1Garage (IOI09_garage)C++17
100 / 100
2 ms212 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...