-
Problem - C - Codeforces
codeforces.com
풀이
tutorial 봤음
Educational Codeforces Round 120 Editorial - Codeforces
codeforces.com
1234567891011121314151617181920212223242526272829303132333435363738#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<int, int> 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;}cs'코드포스' 카테고리의 다른 글
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