# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
717713 |
2023-04-02T11:16:04 Z |
AndrijaM |
Garage (IOI09_garage) |
C++14 |
|
3 ms |
368 KB |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long ans=0;
long long n,m;
cin>>n>>m;
long long cpp[n];
map<long long,long long>l;
bool vis[n];
for(long long i=0;i<n;i++)
{
cin>>cpp[i];
vis[i]=false;
}
long long mass[m];
for(long long i=0;i<m;i++)
{
cin>>mass[i];
}
long long idx;
queue<long long>Q;
for(long long i=0;i<2*m;i++)
{
cin>>idx;
if(idx>0)
{
idx--;
bool ok=false;
for(long long pos=0;pos<n;pos++)
{
if(vis[pos]==false)
{
ans+=cpp[pos]*mass[idx];
l[idx]=pos;
vis[pos]=true;
ok=true;
break;
}
}
if(!ok)
{
Q.push(idx);
}
}
else
{
idx*=(-1);
idx--;
if(Q.size()>0)
{
ans+=cpp[l[idx]]*mass[Q.front()];
l[Q.front()]=l[idx];
Q.pop();
}
else
{
vis[l[idx]]=false;
}
}
}
cout<<ans<<endl;
return 0;
}
# |
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 |
0 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 |
0 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 |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
3 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
368 KB |
Output is correct |