Submission #384962

# Submission time Handle Problem Language Result Execution time Memory
384962 2021-04-02T18:28:45 Z knightron0 Garage (IOI09_garage) C++14
100 / 100
2 ms 492 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
#define clr(a, x) memset(a, x, sizeof(a))
#define dbg(x) cout<<"("<<#x<<"): "<<x<<endl;
#define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl;
#define all(v) v.begin(), v.end()
#define lcm(a, b) (a * b)/__gcd(a, b)
#define int long long int
#define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl;
#define endl '\n'
#define float long double

const int MOD = 1e9 + 7;
const int INF = 2e15;
const int MAXN = 1e5 + 5;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif
	int n, m;
	cin>>n>>m;
	int a[n+2];
	for(int i= 1;i<=n;i++){
		cin>>a[i];
	}    
	int w[m+3];
	for(int i= 1;i<=m;i++){
		cin>>w[i];
	}
	vector<int> v;
	for(int i= 1;i<=2*m;i++){
		int x;
		cin>>x;
		v.pb(x);
	}	
	int curr[n+2];
	clr(curr, -1);
	queue<int> q;
	int ans = 0;
	for(int i: v){
		if(i < 0){
			i = abs(i);
			int y = 0;
			for(int j = 1;j<=n;j++){
				if(curr[j] == i){
					y = j;
					break;
				}
			}
			curr[y] = -1;
			if(!q.empty()){
				int x = q.front();
				q.pop();
				curr[y] = x;
				ans += a[y]*w[x];
			}
		} else {
			bool found = false;
			for(int j=1;j<=n;j++){
				if(curr[j] == -1){
					found = true;
					curr[j] = i; 
					ans += a[j]*w[i];
					break;
				} 
			}
			if(found == false){
				q.push(i);
			}
		}
	}
	cout<<ans<<endl;
    return 0;
}



# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 2 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct