ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 1622-C
    코드포스 2021. 12. 29. 22:46
     

    Problem - C - Codeforces

     

    codeforces.com

     

     

    풀이

    tutorial 봤음

     

    Educational Codeforces Round 120 Editorial - Codeforces

     

    codeforces.com

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    #include <bits/stdc++.h>
    #define endl "\n"
    #define ooop(i, n) for(int i = 0; i < n; i++)
    #define loop(i, n) for(int i = 1; i <= n; i++)
    #define all(v) (v).begin(), (v).end()
     
    using namespace std;
    typedef long long ll;
    typedef pair<intint> pi;
    typedef pair<ll, ll> pl;
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        int t; cin >> t;
        while(t--){
            ll n, k; cin >> n >> k;
            vector<ll> a(n);
            for(auto& e: a) cin >> e;
            sort(all(a));
     
            vector<ll> p(n+1);
            loop(i, n) p[i] = p[i-1+ a[i-1];
     
            ll res = 1e15;
            for(ll y = 0; y < n; y++){
                ll x = ((y+1)*a[0]+p[n-y]-p[1]-k+y)/(y+1);
                if(x < 0) x = 0;
                res = min(res, x+y);
            }
            cout << res << endl;
     
        }
     
        return 0;

     

    '코드포스' 카테고리의 다른 글

    1307-D, *1900  (0) 2022.01.07
    1307-C, *1500  (0) 2022.01.07
    1623-C  (0) 2021.12.29
    1623-B  (0) 2021.12.29
    1622-B  (0) 2021.12.29

    댓글

Designed by Tistory.