Advertisement
tepyotin2

Card Selection 7/10

Dec 9th, 2023 (edited)
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     ios_base::sync_with_stdio(0), cin.tie(0);
  7.     // freopen("selection.in", "r", stdin);
  8.     int n, t;
  9.     cin >> n >> t;
  10.     int card[n];
  11.     for(int i=0; i<n; i++){
  12.         cin >> card[i];
  13.         // cout << card[i] << '\n';
  14.     }
  15.     // cout << "HI" << '\n';
  16.     for(int i=0; i<t; i++){
  17.         int mx = 0;
  18.         int pos = 0;
  19.         // cout << "HI2" << '\n';
  20.         for(int j=0; j<n; j++){
  21.             // cout << "HI2" << '\n';
  22.             if(card[j]>mx){
  23.                 mx = card[j];
  24.                 pos = j;
  25.             }
  26.             // cout << "card[j]: " << card[j] << ", mx: " << mx << ", pos: " << pos+1 << '\n';
  27.         }
  28.         card[pos] = 0;
  29.         cout << pos+1 << '\n';
  30.         // cout << pos+1 << '\n';
  31.         int add = mx/(n-1);
  32.         for(int x=0; x<n; x++){
  33.             // cout << card[x] << '\n';
  34.             if(x!=pos){
  35.                 card[x]+=add;
  36.             }
  37.             // cout << card[x] << '\n';
  38.         }
  39.         int mdval = mx%(n-1);
  40.         // cout << "=====" << '\n';
  41.         for(int y = 0; y<n; y++){
  42.             if(y!=pos){
  43.                 card[y]+=1;
  44.                 mdval--;
  45.             }
  46.             if(mdval==0){
  47.                 break;
  48.             }
  49.         }
  50.         // cout << "======" << '\n';
  51.         // int addv = mx/(n-1);
  52.         // for(int x=0; x<n; x++){
  53.         //     card[x] += addv;
  54.         //     cout << card[x] << '\n';
  55.         // }
  56.     }
  57.     // cout << "pos: " << pos << '\n';
  58.     // for(int i=0; i<t; i++){
  59.     //     // card[pos] = 0;
  60.     //     int mx = 0;
  61.     //     int pos = 0;
  62.     //     for(int j=0; j<n; i++){
  63.     //         // if(card[i]>mx){
  64.     //         //     mx = card[i];
  65.     //         //     pos = i;
  66.     //         // }
  67.     //     }
  68.     //     card[pos] = 0;
  69.     //     cout << pos+1 << '\n';
  70.     // }
  71. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement