154862025-02-19 21:32:20TakacsAndrasBájital (80 pont)cpp17Wrong answer 8/80101ms2796 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int n,x; cin >> n >> x;
    vector<int> a(n);
    for (int &x : a) cin >> x;
    sort(a.begin(), a.end());
    vector<pair<int,int>> pr(n+1);
    for (int i = n-1; i >= 0; i--) pr[i] = {pr[i+1].first+a[i]/x,pr[i+1].second+a[i]%x};
    int l = 0, h = 1e15;
    while (l+1 < h) {
        int m = (l+h)/2, sum = pr[0].second, cnt = 0;
        for (int i = 0; i < n; i++) {
            if (sum < m) {
                sum -= a[i]%x;
                sum += a[i];
            }
            else if (sum+a[i] >= m) {
                cnt = pr[i+1].first+(m-sum > 0 ? (a[i]-(m-sum))/x : 0);
                //cout << i << ' ' << m << ' ' << l << ' ' << h << ' ' << sum << ' ' << cnt << '\n';
                if (cnt >= m) break;
                else cnt = 0;
            }
        }
        if (cnt == 0) h = m;
        else l = m;
    }
    cout << l;
}
SubtaskSumTestVerdictTimeMemory
base8/80
1Accepted0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms508 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/22ms316 KiB
7Wrong answer0/43ms316 KiB
8Wrong answer0/43ms508 KiB
9Wrong answer0/2101ms2728 KiB
10Wrong answer0/286ms2736 KiB
11Wrong answer0/282ms2728 KiB
12Wrong answer0/281ms2612 KiB
13Wrong answer0/290ms2740 KiB
14Wrong answer0/287ms2616 KiB
15Wrong answer0/286ms2732 KiB
16Wrong answer0/285ms2732 KiB
17Wrong answer0/286ms2728 KiB
18Wrong answer0/286ms2612 KiB
19Wrong answer0/281ms2796 KiB
20Wrong answer0/281ms2620 KiB
21Wrong answer0/279ms2604 KiB
22Wrong answer0/279ms2616 KiB
23Wrong answer0/41ms316 KiB
24Wrong answer0/41ms316 KiB
25Wrong answer0/41ms316 KiB
26Accepted4/471ms2736 KiB
27Wrong answer0/478ms2736 KiB
28Wrong answer0/475ms2612 KiB
29Wrong answer0/475ms2764 KiB
30Accepted2/274ms2760 KiB
31Accepted2/275ms2728 KiB
32Wrong answer0/296ms2616 KiB
33Wrong answer0/293ms2740 KiB