Advertisement
Oscar2019

OoO

May 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define SORT(x) sort(x.begin(), x.end())
  5. #define ff first
  6. #define ss second
  7. typedef vector<int> vi;
  8. typedef long long ll;
  9. typedef vector<ll> vl;
  10. typedef pair<int, int> pii;
  11. typedef vector<pii> vii;
  12. typedef pair<ll, ll> pll;
  13. typedef vector<pll> vll;
  14. inline ll LSB(ll x){return x & (-x);}
  15.  
  16. int main(){
  17.     ll n , k;
  18.     cin >> n >> k;
  19.     vector<pair<ll, pll>> vet(n);
  20.     vector<pair<ll, pll>> res(n);
  21.     ll pa = 0, pb = 0;
  22.     vl ta(n+1, 0), tb(n+1, 0);
  23.     int ia = 0, ib = 0;
  24.     int uia = 0, uib = 0;
  25.     for(int i = 0; i < n; ++i){
  26.         auto&p = vet[i];
  27.         cin >> p.ss.ff >> p.ss.ss;
  28.         p.ff = i;
  29.     }
  30.     sort(vet.begin(), vet.end(), [](pair<ll, pll>&a,pair<ll, pll>&b){if(a.ss.ff == b.ss.ff)return a.ff < a.ff; return a.ss < b.ss;});
  31.     for(int i = 0; i < n; ++i){
  32.         auto&p = vet[i];
  33.         auto&q = p.ss;
  34.         while( ia < uia && ta[ia] <= q.ff){
  35.             pa--;
  36.             ia++;
  37.         }
  38.         while( ib < uib && tb[ib] <= q.ff){
  39.             pb--;
  40.             ib++;
  41.         }
  42.         if(pa <= pb){
  43.             if(pa == 0){
  44.                 ta[uia] = q.ff;
  45.             } else{
  46.                 ta[uia] = ta[uia-1];
  47.             }
  48.             ta[uia] = ta[uia] + q.ss;
  49.             res[p.ff] = {p.ff, {'A', ta[uia]}};
  50.             ++pa;
  51.             uia++;
  52.         } else{
  53.             if(pb == 0){
  54.                 tb[uib] = q.ff;
  55.             } else{
  56.                 tb[uib] = tb[uib-1];
  57.             }
  58.             tb[uib] = tb[uib] + q.ss * k;
  59.             res[p.ff] = {p.ff, {'B', tb[uib]}};
  60.             ++pb;
  61.             uib++;
  62.         }
  63.     }
  64.     for(int i = 0; i < n; ++i){
  65.         cout << (char)res[i].ss.ff << ' ' << res[i].ss.ss << '\n';
  66.     }
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement