Cod sursa(job #1943542)

Utilizator MaligMamaliga cu smantana Malig Data 28 martie 2017 17:37:43
Problema Ghiozdan Scor 54
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.63 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;
ifstream in("ghiozdan.in");
ofstream out("ghiozdan.out");

const int NMax = 2e4 + 5;
const int GMax = 75e3 + 5;
const int valMax = 200 + 5;
typedef long long ll;

int N,G,nrVal;
int dp[2][GMax],valori[GMax];
unsigned char pr[valMax][GMax];

int main()
{
    in>>N>>G;
    valori[++nrVal] = 0;
    int mx = 0, mn = 0;
    for (int i=1;i<=N;++i) {
        int greutate;
        in>>greutate;

        int temp = nrVal;
        for (int j=1;j<=temp;++j) {
            int val = valori[j] + greutate;
            if (val > G) {
                continue;
            }

            if (dp[0][val] == 0) {
                valori[++nrVal] = val;
                dp[1][val] = dp[0][valori[j]] + 1;
                //pr[greutate][val] =
            }
            else {
                dp[1][val] = dp[0][val];
                if (dp[1][val] > dp[0][valori[j]] + 1) {
                    dp[1][val] = dp[0][valori[j]] + 1;
                }
            }
        }

        for (int j=1;j<=nrVal;++j) {
            dp[0][valori[j]] = dp[1][valori[j]];

            if (mx < valori[j]) {
                mx = valori[j];
                mn = dp[0][valori[j]];
            }
            else if (mx == valori[j] && mn > dp[0][valori[j]]) {
                mn = dp[0][valori[j]];
            }
        }
    }

    out<<mx<<' '<<mn<<'\n';
    /*
    do {
        out<<(mx - pr[mx])<<'\n';
        mx = pr[mx];
    }
    while (mx != 0);
    //*/

    in.close();out.close();
    return 0;
}