Submission #292433

# Submission time Handle Problem Language Result Execution time Memory
292433 2020-09-06T23:41:37 Z Ruba_K Garage (IOI09_garage) C++14
100 / 100
2 ms 512 KB
#include <bits/stdc++.h>

using namespace std;
const int N = 5e5 + 1 ;

#define ll long long



int main()
{ios_base::sync_with_stdio(false);cin.tie(0);

   int n , m ;
   cin >> n >> m ;
   int cost[n + 1] , cars[m + 1];
   set<int>av;


   for(int i = 1 ; i <= n ; i ++){
    cin >> cost[i];
    av.insert(i);
   }

   for(int i = 1 ; i <= m ; i ++)
    cin >> cars[i];

   ll ans = 0 ;
   queue<int>q ;
   map<int , int >mp ;
   for(int i = 0 ; i < m * 2 ; i ++){
        int a ;
        cin >> a ;
        if(a < 0){
            av.insert(mp[-a]);
            int b = *av.begin();
            if(q.size()){
                int f = q.front();
                q.pop();
                ans += cost[b] * 1ll * cars[f];
                av.erase(b);
                mp[f] = b ;
            }
            }
        else{
            q.push(a);
            if(av.empty())
                continue ;


            int b = *av.begin();
            int f = q.front();
            q.pop();
            ans += 1ll * cost[b] * cars[f];

            av.erase(b);
            mp[f] = b ;
        }

   }

   cout << ans ;


    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 392 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct