Submission #866268

# Submission time Handle Problem Language Result Execution time Memory
866268 2023-10-25T16:43:09 Z lomta Garage (IOI09_garage) C++17
100 / 100
3 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
queue<int> q;
set<int> st;
main(){
	
	int n;cin>>n;
	int m;cin>>m;	
	vector<int> v1(n);
	for(int i=0;i<n;i++){
		
		cin>>v1[i];
		st.insert(i);
	
	}
	
	vector<int> v(m);
	for(int i=0;i<m;i++){
		cin>>v[i];
	}
	
	int ans=0;
	
	m*=2;
	map<int,int> mp;
	while(m--){
		int x;cin>>x;
		
		if(x>0){
			x--;
			q.push(x);
			if(st.size()==0){
				continue;
			}
			else{
				int k=*st.begin();
				
				auto l=st.find(k);
				st.erase(l);
				int kk=q.front();
				q.pop();
				
				ans+=v1[k]*v[kk];
				
				mp[kk]=k;
					
				//cout<<"k:"<<v[kk]<<" "<<k<<endl;
			}
		}
		else{
			x++;
			int out=mp[abs(x)];
			st.insert(out);
			if(q.size()>0){
				int kk=q.front();
				q.pop();
				int k=*st.begin();
				auto l=st.find(k);
				st.erase(l);
				
				ans+=v1[k]*v[kk];
				
				mp[kk]=k;
			}
		}
		//cout<<"ans:"<<ans<<endl;
	}
	cout<<ans<<endl;
	
	
	
	
	
}

Compilation message

garage.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    6 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 2 ms 344 KB Output is correct
20 Correct 3 ms 348 KB Output is correct