Advertisement
deushiro

Untitled

Nov 30th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <bitset>
  9.  
  10. using namespace std;
  11.  
  12. typedef long long ll;
  13. typedef double d;
  14. vector<bool> flag;
  15.  
  16.  
  17. struct robot{
  18.     int a, b, c;
  19. };
  20.  
  21. bool operator <(robot a, robot b){
  22.     if(a.a == b.a){
  23.         if(a.b == b.b){
  24.             return a.c < b.c;
  25.         }
  26.         return a.b < b.b;
  27.     }
  28.     return a.a >= b.a;
  29. }
  30.  
  31. int main() {
  32.     ios_base::sync_with_stdio(false);
  33.     cin.tie(0);
  34.     cout.tie(0);
  35.     int n;
  36.     cin >> n;
  37.     vector<robot> a;
  38.     vector<int> ans(n);
  39.     vector<robot> last;
  40.     for(int i = 0; i < n; ++i){
  41.         int d, w;
  42.         cin >> d >> w;
  43.         --d;
  44.         a.push_back({w, d, i});
  45.     }
  46.     flag.resize(n, false);
  47.     sort(a.begin(), a.end());
  48.     //int res = 0;
  49.     for(int i = 0; i < n; ++i){
  50.         int m = a[i].b;
  51.         while(flag[m] && m > -1){
  52.             --m;
  53.         }
  54.         if(m < 0){
  55.             last.push_back(a[i]);
  56.         }
  57.         else{
  58.             flag[m] = true;
  59.             ans[a[i].c] = m + 1;
  60.         }
  61.     }/*
  62.     int i = 0;
  63.     while(last.size() > 0 && i < n){
  64.         if(!used[i]){
  65.             ans[last[i].c] = i + 1;
  66.             res += last[i].a;
  67.             last.pop_back();
  68.         }
  69.         ++i;
  70.     }
  71.     cout << res << endl;
  72.     for(int i = 0; i < ans.size(); ++i){
  73.         cout << ans[i] << " ";
  74.     }
  75.     cout << endl;*/
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement