Submission #614118

# Submission time Handle Problem Language Result Execution time Memory
614118 2022-07-30T19:13:59 Z Icebear16 Garage (IOI09_garage) C++14
100 / 100
2 ms 356 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18//change to const int INF=1e18 if causing problem
const ll MOD=998244353;
const ll alt=1e10;
const ll inf=1e9+7;//Precalc is not a bad idea
//#define int ll
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define mod(a) (a+inf)%inf
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
/* run this program using the console pauser or add your own getch, system("pause") or input loop*/


int32_t main(){
	std::ios_base::sync_with_stdio(false);
//	cin.tie(0)->sync_with_stdio(0);
		int n,m;
		cin>>n>>m;
		set<int> s;
		map<int,int> mm;
		map<int,int> M;
		vector<int> a(n);
		vector<int> b(m);
		queue<int> q;
		s.clear(),mm.clear(),M.clear();
		for(int i=0;i<n;i++){
			cin>>a[i];
			M[i]=a[i];
			s.insert(i);
		}
		for(int i=0;i<m;i++){
			cin>>b[i];
		}
		int ans=0;
		for(int l=0;l<2*m;l++){
			int x;
			cin>>x;
			if(x>0){
				if(s.size()>0){
					int y=*s.begin();
					ans+=((M[y])*b[x-1]);
					mm[x]=y;
					s.erase(y);
				}else q.push(x);
			}else{
				x=abs(x);
				int y=mm[x];
				s.insert(y);
				if(!q.empty()){
					int a=q.front();q.pop();
					int y=*s.begin();
					ans+=((M[y])*b[a-1]);
					mm[a]=y;
					s.erase(y);
				}
			}
		}
		cout<<ans<<endl;
	return 0;
}
//Icebear16
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 356 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct