Advertisement
Zeinab_Hamdy

Untitled

Apr 19th, 2024
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define nl "\n"
  4. #define cnl cout << nl;
  5. #define fi first
  6. #define se second
  7. #define pb push_back
  8. #define ll long long
  9. #define ull unsigned ll
  10. #define RV return void
  11. #define sz(x) int(x.size())
  12. #define all(v) v.begin(), v.end()
  13. #define rall(v) v.rbegin(), v.rend()
  14. #define fixed(n) fixed << setprecision(n)
  15. #define cin(v) for(auto&x:v) cin >> i;
  16. #define cout(v) for(auto&x:v) cout << i << " ";
  17. void files(){
  18.     #ifndef ONLINE_JUDGE
  19.        freopen("input.txt", "r", stdin);
  20.        freopen("output.txt", "w", stdout);
  21.     #endif
  22. }
  23.  
  24.  
  25. void solve( int test ){
  26.  
  27.     int n ;
  28.     cin >> n ;
  29.     vector < pair < ll , ll> > p;
  30.     vector < pair < ll , pair < ll , ll > > > v(n);
  31.     for(int i =0 ; i < n ; i++){
  32.         cin >> v[i].fi >> v[i].se.fi >> v[i].se.se;
  33.         ll mx= max({v[i].fi , v[i].se.fi , v[i].se.se})
  34.         , sum = v[i].fi + v[i].se.fi + v[i].se.se - mx;
  35.         p.pb({sum , mx });
  36.     }
  37.  
  38.     sort(all(p) , [&] ( auto a , auto b){
  39.         if(a.fi == b.fi) {
  40.             return a.se < b.se;
  41.         }
  42.         return a.fi < b.fi;
  43.     });
  44.     auto lwr=[&]( ll sum ){
  45.         int l=0 ,r =n-1 , best =0;
  46.         while(l <= r ){
  47.             int mid = r- (r-l)/2;
  48.             if(p[mid].fi + 2 <= sum){
  49.                 best = mid;
  50.                 l=mid+1;
  51.             }else{
  52.                 r=mid-1;
  53.             }
  54.         }
  55.         return best;
  56.     };
  57.    
  58.     for(int i =0 ; i < n ;i++){
  59.         ll sum = v[i].fi + v[i].se.fi + v[i].se.se;
  60.         cout << lwr(sum) << " ";
  61.     }
  62.    
  63.    
  64.  
  65. }
  66.  
  67.  
  68. int main(){
  69.     ios_base::sync_with_stdio(false);
  70.     cin.tie(nullptr);
  71.     cout.tie(nullptr);
  72.                            
  73.     //  files();
  74.     int testCase=1;
  75.         // cin >> testCase ;
  76.     for(int i=1 ; i <= testCase ; i++){
  77.         solve(i);
  78.     }
  79.  
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement