Cod sursa(job #2393092)

Utilizator Alex18maiAlex Enache Alex18mai Data 30 martie 2019 19:47:14
Problema Ghiozdan Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.67 kb

//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>
#include <chrono>

using namespace std;

//#include <iostream>
#include <fstream>
ifstream cin ("ghiozdan.in");ofstream cout ("ghiozdan.out");

int fv[210];
int last[75100];
int dp[75100];

const int inf = 1e9;

int main() {

    //freopen("input", "r", stdin);freopen("output", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << setprecision(10) << fixed;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(NULL));

    int n , g;
    cin>>n>>g;

    for (int i=1; i<=n; i++){
        int x;
        cin>>x;
        fv[x]++;
    }

    for (int i=1; i<=g; i++){
        last[i] = -1;
    }

    for (int i=200; i>=1; i--){
        for (int j=g; j>=0; j--){
            if (last[j] == -1){
                continue;
            }
            for (int k=j+i; k<=min(j+i*fv[i] , g); k+=i){
                if (last[k] != -1){
                    break;
                }
                last[k] = j;
                dp[k] = dp[j]+(k-j)/i;
            }
        }
    }

    int now = 0;
    for (int i=0; i<=g; i++){
        if (last[i] != -1){
            now = i;
        }
    }
    cout<<now<<" "<<dp[now]<<'\n';


    while (now){
        int add = dp[now] - dp[last[now]];
        int dif = now - last[now];
        for (int i=1; i<=add; i++){
            cout<<dif/add<<'\n';
        }
        now = last[now];
    }


    return 0;
}