Cod sursa(job #2488747)

Utilizator tifui.alexandruTifui Ioan Alexandru tifui.alexandru Data 7 noiembrie 2019 16:28:27
Problema Zebughil Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("zebughil.in");
ofstream g("zebughil.out");

const int Nmax = 20;
int v[Nmax];
int n, G;
const double eps = 0.275;

int solve(){

    clock_t t = clock();
    int ans = n, no, sum;
    bool ok = true;

    while(ok and (double)(clock() - t) / CLOCKS_PER_SEC <= eps){

        sum = 0;
        no = 1;

        for(int i = 1; i <= n; ++i){

            if(1LL * sum + 1LL * v[i] <= 1LL * G)
                sum += v[i];
            else{

                sum = v[i];
                ++no;
            }
        }

        ans = min(ans,no);

        ok = next_permutation(v+1, v+n+1);
    }

    return ans;
}

int main(){

    for(int t = 1; t <= 3; ++t){

        f >> n >> G;
        for(int i = 1; i <= n; ++i)
            f >> v[i];
        g << solve() << '\n';
    }

    return 0;
}