19192022-12-10 14:37:26kdbRészekre (40)cpp11Time limit exceeded 18/40583ms3516 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);

    ll n, db= 0, s = 0;
    cin >> n;
    vector<int>vec(n + 1);
    for (size_t i = 0; i < n; i++)
    {
        cin >> vec[i];
        s += vec[i];
    }

    while (s>0)
    {
        ll l = n + 1;
        auto it = max_element(vec.begin(), vec.begin() + l);
        l = distance(vec.begin(), it);
        s -= vec[l];
        vec[l] = 0;
        while (it!=vec.begin())
        {
            it = max_element(vec.begin(), vec.begin() + l);
            l = distance(vec.begin(), it);
            s -= vec[l];
            vec[l] = 0;
        }
        db++;
    }
    cout << db << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base18/40
1Accepted0/03ms1824 KiB
2Time limit exceeded0/0560ms1800 KiB
3Accepted2/22ms2228 KiB
4Accepted2/22ms2324 KiB
5Accepted2/23ms2524 KiB
6Accepted3/34ms2612 KiB
7Accepted3/314ms2748 KiB
8Accepted3/334ms3088 KiB
9Accepted3/3128ms3440 KiB
10Time limit exceeded0/3583ms3020 KiB
11Time limit exceeded0/3558ms3516 KiB
12Time limit exceeded0/3561ms3244 KiB
13Time limit exceeded0/4522ms3344 KiB
14Time limit exceeded0/4573ms3412 KiB
15Time limit exceeded0/5565ms3380 KiB