# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
663389 |
2022-11-26T21:24:04 Z |
esomer |
Garage (IOI09_garage) |
C++17 |
|
1 ms |
340 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int MOD = 1e9 + 7;
void solve(){
int n, m; cin >> n >> m;
vector<int> v(n); for(auto &i : v) cin >> i;
vector<int> w(m); for(auto &i : w) cin >> i;
ll ans = 0;
queue<int> q;
vector<int> spaces(n, -1);
for(int i = 0; i < 2 * m; i++){
int x; cin >> x;
if(x > 0){
x--;
bool placed = 0;
for(int j = 0; j < n; j++){
if(spaces[j] == -1){
ans += w[x] * v[j];
placed = 1;
spaces[j] = x;
break;
}
}
if(!placed) q.push(x);
}else{
x = abs(x) - 1;
for(int j = 0; j < n; j++){
if(spaces[j] == x){
if(q.size() > 0){
spaces[j] = q.front(); q.pop();
ans += w[spaces[j]] * v[j];
}else spaces[j] = -1;
}
}
}
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("inpt.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
//int tt; cin >> tt;
int tt = 1;
for(int t = 1; t <= tt; t++){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |