답안 #1104245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104245 2024-10-23T09:56:24 Z melody_rules Garage (IOI09_garage) C++17
100 / 100
2 ms 508 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

signed main() {
  int n=0;
  int m=0;
  int a=0;
  int b=0;
  int i=0;
  
  cin>>n>>m;
  vector<int> vec(n); //Price
  vector<int> veco(m); //Weight
  
  queue<int> q; //Queue
  vector<pair<int, int>> stat(m, {-1, -1});
  
  set<pair<int, int>> s;
  
  for(i=0;i<n;i++) {
    cin>>a;
    vec.at(i) = a;
    
    s.insert({i, a});
  }
  
  for(i=0;i<m;i++) {
    cin>>a;
    veco.at(i) = a;
  }
  
  for(i=0;i<(2*m);i++) {
	cin>>a;
    
    if(a > 0) {
      if(s.empty())
        q.push(a);
      
      else {
        auto it = s.begin();
        
        b += veco.at(a-1)*((*it).second);
        
        stat.at(a-1) = (*it);
        s.erase(it);
      }
    }
    
    else {
      a *= -1;
      
      if(!q.empty()) {
        stat.at(q.front()-1) = stat.at(a-1);
        
        b += veco.at(q.front() - 1)*(stat.at(q.front() - 1).second);
        
        q.pop();
      }
      
      else
      s.insert(stat.at(a-1));
      
      stat.at(a-1) = {-1, -1};
    }
  }
  
  cout<<b<<endl;
  
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 436 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 508 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 2 ms 336 KB Output is correct
17 Correct 2 ms 496 KB Output is correct
18 Correct 2 ms 336 KB Output is correct
19 Correct 2 ms 336 KB Output is correct
20 Correct 2 ms 456 KB Output is correct