| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1243585 | nvc2k8 | Garage (IOI09_garage) | C++20 | 1 ms | 328 KiB |
#include <bits/stdc++.h>
#define TASK "akjdkasd"
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define all(C) C.begin(), C.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INT_LIM = 2147483647;
const ll LL_LIM = 9223372036854775807;
template <typename X> bool minimize(X &x, const X &y) {if (x>y){x = y; return true;}return false;}
template <typename X> bool maximize(X &x, const X &y) {if (x<y){x = y; return true;}return false;}
///------------------------------------------///
int n,m;
ll a[105], b[10005];
int f[105];
ll ans = 0;
void inp()
{
cin >> n >> m;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, m) cin >> b[i];
}
void solve()
{
queue<int> q;
FOR(t, 1, 2*m)
{
int x;
cin >> x;
if (x>0)
{
bool flag = true;
FOR(i, 1, n) if (f[i]==0)
{
f[i] = x;
ans+= a[i]*b[x];
flag = false;
break;
}
if (flag) q.push(x);
}
else
{
x = -x;
FOR(i, 1, n) if (f[i]==x)
{
f[i] = 0;
if (!q.empty())
{
ans+= a[i]*b[q.front()];
f[i] = q.front();
q.pop();
}
break;
}
}
}
cout << ans;
}
signed main()
{
///--------------------------///
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen(TASK".INP","r")!=NULL)
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
///--------------------------///
int NTEST = 1;
bool codeforces = 0;
if (codeforces) cin >> NTEST;
while (NTEST--)
{
inp();
solve();
}
return 0;
}
///------------------------------------------///
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
