# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
754290 |
2023-06-07T12:19:18 Z |
TimDee |
Garage (IOI09_garage) |
C++17 |
|
1 ms |
340 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define forn(i,n) for(int i=0;i<n;++i)
#define pi pair<int,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vii(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
const int inf=1e18;
void solve() {
int n,m; cin>>n>>m;
vii(t,n);
vii(w,m);
vector<int> pos(m,-1);
set<int> s;
forn(i,n) s.insert(i);
int ans=0;
queue<int> q;
forn(i,2*m) {
int x; cin>>x;
if (x>0) {
--x;
if (s.size()) {
auto y=*s.begin(); s.erase(s.begin());
pos[x]=y;
ans+=w[x]*t[y];
} else {
q.push(x);
}
} else {
x*=-1;
--x;
s.insert(pos[x]);
while (q.size() && s.size()) {
auto x=q.front(); q.pop();
auto y=*s.begin(); s.erase(s.begin());
pos[x]=y;
ans+=w[x]*t[y];
}
}
}
cout<<ans<<'\n';
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 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 |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |