Submission #197670

#TimeUsernameProblemLanguageResultExecution timeMemory
197670SakamotooGarage (IOI09_garage)C++14
100 / 100
6 ms376 KiB
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree < long long , null_type , less<long long> , rb_tree_tag , tree_order_statistics_node_update > ordered_set; #define mp make_pair #define fi first #define se second //mt19937 rng(time(NULL)); //int mt19937_64 rng(time(NULL)); //Long Long //shuffle(a.begin(),a.end(),rng); //shuffle //rng(); //random int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; int c[n+1]; for(int i=1; i<=n; i++){ cin>>c[i]; } int s[n+1]; memset(s,0,sizeof s); int w[m+1]; for(int i=1; i<=m; i++){ cin>>w[i]; } long long val=0; queue<int> q; for(int i=1; i<=2*m; i++){ int x; cin>>x; if(x<0){ x=-x; int j; for(j=1; j<=n; j++){ if(s[j]==x) { s[j]=0; break; } } if(!q.empty()){ s[j]=q.front(); val+=c[j]*w[s[j]]; q.pop(); } }else { // cout<<"tolol"<<endl; int j; for(j=1; j<=n; j++){ if(s[j]==0){ break; } } if(j==n+1) q.push(x); else { s[j]=x; // cout<<j<<endl; val+=c[j]*w[x]; } } // cout<<val<<endl; } cout<<val<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...