Guest User

Untitled

a guest
Dec 11th, 2021
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.62 KB | None | 0 0
  1. // Super Idol的笑容
  2. //    都没你的甜
  3. //  八月正午的阳光
  4. //    都没你耀眼
  5. //  热爱105°C的你
  6. // 滴滴清纯的蒸馏水
  7.  
  8. #include <bits/stdc++.h>
  9. #include <ext/pb_ds/assoc_container.hpp>
  10. #include <ext/pb_ds/tree_policy.hpp>
  11. #include <ext/rope>
  12. using namespace std;
  13. using namespace __gnu_pbds;
  14. using namespace __gnu_cxx;
  15. #define ll long long
  16. #define ii pair<ll,ll>
  17. #define iii pair<ii,ll>
  18. #define fi first
  19. #define se second
  20. #define endl '\n'
  21. #define debug(x) cout << #x << ": " << x << endl
  22.  
  23. #define pub push_back
  24. #define pob pop_back
  25. #define puf push_front
  26. #define pof pop_front
  27. #define lb lower_bound
  28. #define ub upper_bound
  29.  
  30. #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
  31. #define all(x) (x).begin(),(x).end()
  32. #define sz(x) (int)(x).size()
  33.  
  34. #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
  35. //change less to less_equal for non distinct pbds, but erase will bug
  36.  
  37. mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
  38.  
  39. int n,k;
  40. ii arr[2005];
  41. ll w[2005];
  42. ll d[2005];
  43.  
  44. ii memo[2005][2005];
  45. ii dp(int i,int j){
  46.     if (i==n) return {0,0};
  47.     if (memo[i][j]!=ii(-1,-1)) return memo[i][j];
  48.    
  49.     ii res=dp(i+1,j);
  50.     if (j<d[i]){
  51.         ii temp=dp(i+1,j+1);
  52.         temp.fi++,temp.se+=w[i];
  53.         res=max(res,temp);
  54.     }
  55.    
  56.     return memo[i][j]=res;
  57. }
  58.  
  59. vector<ii> ans;
  60. void search(int i,int j,ll num,ll tot){
  61.     if (i==n){
  62.         if (ii(num,tot)<ii(0,0)) ans.pub({num,tot});
  63.         return;
  64.     }
  65.    
  66.     if (dp(i,j)<ii(num,tot)) return;
  67.    
  68.     search(i+1,j,num,tot);
  69.     if (sz(ans)==k) return;
  70.     if (j<d[i]) search(i+1,j+1,num-1,tot-w[i]);
  71. }
  72.  
  73. bool smaller(ll num,ll tot){
  74.     ans.clear();
  75.     search(0,0,num,tot);
  76.    
  77.     return sz(ans)<k;
  78. }
  79.  
  80. int main(){
  81.     ios::sync_with_stdio(0);
  82.     cin.tie(0);
  83.     cout.tie(0);
  84.     cin.exceptions(ios::badbit | ios::failbit);
  85.    
  86.     cin>>n>>k;
  87.    
  88.     const int pad=1e9;
  89.     rep(x,0,n) cin>>arr[x].fi>>arr[x].se;
  90.     sort(arr,arr+n,[](ii i,ii j){
  91.         return i.se<j.se;
  92.     });
  93.    
  94.     rep(x,0,n) tie(w[x],d[x])=arr[x];
  95.     rep(x,0,n) w[x]=pad-w[x];
  96.    
  97.     memset(memo,-1,sizeof(memo));
  98.    
  99.     ll hi=2e16,lo=-1,mi;
  100.     ll mxw=2e9*2000;
  101.    
  102.     while (hi-lo>1){
  103.         mi=hi+lo>>1;
  104.        
  105.         ll num=mi/mxw,tot=mi%mxw;
  106.         //cout<<"bsta: "<<num<<" "<<tot<<endl;
  107.         if (smaller(num,tot)) hi=mi;
  108.         else lo=mi;
  109.     }
  110.    
  111.     ll num=hi/mxw,tot=hi%mxw;
  112.     //cout<<"debug: "<<num<<" "<<tot<<endl;
  113.    
  114.     ans.clear();
  115.     search(0,0,num,tot);
  116.    
  117.     for (auto &it:ans) it={num-it.fi,tot-it.se};
  118.    
  119.     sort(all(ans));
  120.     reverse(all(ans));
  121.    
  122.     while (sz(ans)<k) ans.pub({num,tot});
  123.    
  124.     for (auto &it:ans){
  125.         cout<<it.fi<<" "<<it.fi*pad-it.se<<endl;
  126.     }
  127. }
  128.  
Advertisement
Add Comment
Please, Sign In to add comment