제출 #384962

#제출 시각아이디문제언어결과실행 시간메모리
384962knightron0Garage (IOI09_garage)C++14
100 / 100
2 ms492 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fr first #define sc second #define clr(a, x) memset(a, x, sizeof(a)) #define dbg(x) cout<<"("<<#x<<"): "<<x<<endl; #define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl; #define all(v) v.begin(), v.end() #define lcm(a, b) (a * b)/__gcd(a, b) #define int long long int #define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl; #define endl '\n' #define float long double const int MOD = 1e9 + 7; const int INF = 2e15; const int MAXN = 1e5 + 5; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n, m; cin>>n>>m; int a[n+2]; for(int i= 1;i<=n;i++){ cin>>a[i]; } int w[m+3]; for(int i= 1;i<=m;i++){ cin>>w[i]; } vector<int> v; for(int i= 1;i<=2*m;i++){ int x; cin>>x; v.pb(x); } int curr[n+2]; clr(curr, -1); queue<int> q; int ans = 0; for(int i: v){ if(i < 0){ i = abs(i); int y = 0; for(int j = 1;j<=n;j++){ if(curr[j] == i){ y = j; break; } } curr[y] = -1; if(!q.empty()){ int x = q.front(); q.pop(); curr[y] = x; ans += a[y]*w[x]; } } else { bool found = false; for(int j=1;j<=n;j++){ if(curr[j] == -1){ found = true; curr[j] = i; ans += a[j]*w[i]; break; } } if(found == false){ q.push(i); } } } cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...