Submission #1293914

#TimeUsernameProblemLanguageResultExecution timeMemory
1293914eldaees131313Paprike (COI18_paprike)C++20
13 / 100
8 ms1092 KiB
////////////////////////////// Author:eldaee, coder_viper!!!!!!!!!!!!!!!!!!!!!!!!11
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define int long long
#define str string
#define vec vector
#define dou double
#define ld long double
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define YES cout << "YES" << '\n'
#define Yes cout << "Yes" << '\n'
#define NO cout << "NO" << '\n'
#define No cout << "No" << '\n'
#define gcd __gcd
#define all(x) x.begin(),x.end()
#define eldaee ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*


*/

using namespace std;

void solve() { 
    int n, k;
    cin >> n >> k;
    int h[100001];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    int x = 0;
    if (n <= 15) {
        int y = 1;
        for (int i = 0; i < n; i++) {
            y *= 2;
        }
        int mi = n - 1;
        for (int j = 0; j < y; j++) {
            int sm = 0;
            int c = 0;
            for (int i = 0; i < n; i++) {
                sm += h[i];
                if (sm > k) {
                    c++;
                    sm = h[i];
                }
            }
            if (sm <= k) {
                if (c < mi) {
                    mi = c;
                }
            }
        }
        x = mi;
    }
    else {
        int sm = 0;
        for (int i = 0; i < n; i++) {
            sm += h[i];
            if (sm > k) {
                x++;
                sm = h[i];
            }
        }
    }
    cout << x << '\n';
} 

signed main()
{
    eldaee
    
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...