# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
151069 | youssefbou62 | Garage (IOI09_garage) | C++14 | 5 ms | 416 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab (int x ) { return (x>0?x:-x); }
const int N = 1e4+5 ;
int w[N],rates[105],pos[105];
ll ans ;
int main(){
int n , m ;
cin >> n >> m ;
for(int i = 1 ; i <= n ; i++ )cin >> rates[i];
for(int i = 1 ; i <= m ; i++ )cin >> w[i] ;
int ans = 0 ;
queue<int> q;
for(int t = 0 ; t < 2*m ; t ++ ){
int c , car ;
cin >> c ;
car = abs(c) ;
if( c > 0){
int P = -1 ;
for(int i = 1 ; i <= n ; i++ ){
if( !pos[i] ){
P = i ;
break ;
}
}
if( P == -1 )q.push(c);
else pos[P] = c,ans += (w[c]*rates[P])*1LL;
}else{
for(int i = 1 ; i <= n ; i++ ){
if( pos[i] == car ){
pos[i] = 0 ;
break ;
}
}
int P = -1 ;
for(int i = 1 ; i <= n ; i++ ){
if( !pos[i] ){
P = i ;
break ;
}
}
if( !q.empty() && P != -1 ){
pos[P]=q.front();
ans += (w[q.front()]*rates[P])*1LL;
q.pop() ;
}
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |