제출 #1224726

#제출 시각아이디문제언어결과실행 시간메모리
1224726IBMGGarage (IOI09_garage)C++20
100 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; #define ffor(i,o,f) for(int i = o; i < f; i++) #define bfor(i,f,o) for(int i = f; i >= o; i--) #define pb push_back #define all(a) (a).begin(), (a).end() #define F first #define S second #define PI acos(-1) #define endl '\n' typedef long long ll; typedef long double ld; typedef pair < ll, ll > pll; typedef vector < ll > vll; const int INF = int(1e9 + 7); const int MOD = 998244353; const double EPS = double(1e-9); const int TAM = 200005; int main() //IBMG { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("","r",stdin); //freopen("","w",stdout); ll n, m, a, ans = 0; vll oc(105, -1); vll r, w; queue<ll> q; r.pb(0); w.pb(0); cin >> n >> m; ffor(i, 0, n) cin >> a, r.pb(a); ffor(i, 0, m) cin >> a, w.pb(a); ffor(i, 0, 2*m){ cin >> a; if(a > 0){ bool ok = false; ffor(j, 1, n+1){ if(oc[j] == -1) oc[j] = a, ok = true, ans += r[j]*w[a]; if(ok) break; } if(!ok) q.push(a); } else{ a *= -1; bool ok = false; ffor(j, 1, n+1){ if(oc[j] == a) oc[j] = -1, ok = true; if(ok) break; } } ffor(j, 1, n+1){ if (q.empty()) break; if (oc[j] == -1) oc[j] = q.front(), ans += r[j]*w[q.front()], q.pop(); } } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...