Advertisement
tepyotin2

Yet Another Tournament

Jun 20th, 2025
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int t;
  6.  
  7. int main(){
  8.     //freopen("anothertournament.in", "r", stdin);
  9.    
  10.     cin >> t;
  11.     int n, m;
  12.     while(t--){
  13.         cin >> n >> m;
  14.         vector<int> og(n);
  15.         vector<int> sorted(n);
  16.         for(int i=0; i<n; i++){
  17.             cin >> og[i];
  18.             sorted[i] = og[i];
  19.         }
  20.         sort(sorted.begin(), sorted.end());
  21.         int sum = 0;
  22.         int mxv = 0;
  23.         int wins = 0;
  24.         for(int i=0; i<n; i++){
  25.             sum+=sorted[i];
  26.             if(sum>m){
  27.                 sum-=sorted[i];
  28.                 break;
  29.             }else{
  30.                 mxv = sorted[i];
  31.                 wins++;
  32.             }
  33.         }
  34.         if(wins == n){
  35.             cout << 1 << '\n';
  36.             continue;
  37.         }
  38.         //cout << "wins: " << wins << ", mxv: " << mxv << '\n';
  39.         if((sum-mxv)+og[wins]<=m){
  40.             cout << n-wins << '\n';
  41.         }else{
  42.             cout << (n-wins)+1 << '\n';
  43.         }
  44.     }
  45.    
  46.     return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement