답안 #109226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109226 2019-05-05T15:23:12 Z amiratou Garage (IOI09_garage) C++14
100 / 100
5 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int r[102],w[2001],asign[2001];
set<int> myset;
int main(){
	boost;
	int n,m,a;
	cin>>n>>m;
	for (int i = 0; i < n; ++i)
		cin>>r[i],myset.insert(i);
	for (int i = 0; i < m; ++i)
		cin>>w[i];
	ll ans=0LL;
	//debug(2*m);
	queue<int> q;
	for (int i = 0; i < 2*m; ++i)
	{
		//debug(ans);
		cin>>a;
		//debug(a);
		if(a<0){
			myset.insert(asign[(-a)-1]);
			//continue;
		}
		while(!myset.empty()&&!q.empty()){
			auto it=myset.begin();
			asign[q.front()-1]=*it;
			ans+=w[q.front()-1]*(r[*it]);
			myset.erase(it);
			q.pop();
		}
		if(a<0)continue;
		if(myset.empty()){
			q.push(a);
			//debug(q.size());
			continue;
		}
		auto it=myset.begin();
		asign[a-1]=*it;
		ans+=w[a-1]*(r[*it]);
		myset.erase(it);
	}
	cout<<ans;
	return 0;
}
//long long
//array bounds
//special cases
//binary search
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 384 KB Output is correct