# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534651 | devariaota | Garage (IOI09_garage) | C++17 | 2 ms | 364 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;
typedef long long ll;
typedef unsigned long ul;
typedef double dbl;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef map<ll, ll> mll;
typedef pair<string, ll> psl;
typedef map<string, ll> msl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef deque<ll> deq;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqm;
typedef priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> dij;
typedef priority_queue<ll> pq;
typedef string str;
const ll mod=1e9+9;
const ll maxn=2e5+1;
ll gcd(ll a, ll b) {
return a==0 ? b : gcd(a, b%a);
}
ll lcm(ll a, ll b) {
ll ans=a*b;
ans=ans/(gcd(a, b));
return ans;
}
#define ihacoy ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dh << endl;
#define co cout <<
#define udh cout << endl;
#define spa << " ";
#define ci cin >>
#define fi first
#define se second
#define sp << " " <<
#define tes while(t--)
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define gre greater<ll>()
#define sip return 0
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
int n, m, ans, q[4000], now, x;
queue<int> qu;
int main() {
ihacoy
ci n >> m;
vi cost(n+1), w(m+1), pinjam(m+1);
for(int i=1; i<=n; i++) ci cost[i];
for(int i=1; i<=m; i++) ci w[i];
pqm par;
for(int i=n; i>=1; i--) {
par.push(i);
}
for(int i=0; i<2*m; i++) {
ci x;
if(x>0) {
if(now<n) {
now++;
ans+=1LL*w[x]*cost[par.top()];
pinjam[x]=(int)par.top();
par.pop();
} else {
qu.push(x);
}
} else {
if(now<n || qu.empty()) {
now--;
par.push(pinjam[abs(x)]);
} else {
par.push(pinjam[abs(x)]);
ans+=1LL*w[qu.front()]*cost[par.top()];
pinjam[qu.front()]=(int)par.top();
par.pop();
qu.pop();
}
}
}
co ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |