Cod sursa(job #2091008)

Utilizator mihai.alphamihai craciun mihai.alpha Data 18 decembrie 2017 23:26:44
Problema Lapte Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.71 kb
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define VI vector<int>
#define PII pair<int,int>
#define PDD pair<double,double>
#define ll long long
#define lf double
#define pb push_back
#define For(i, j, n)for(int i = j;i <= n;i++)
#define iFor(i, j, n)for(int i = n;i >= j;i--)
#define R scanf
#define S scanf
#define P printf
#define fin stdin
#define fout stdout

#define DBG 1

const int MN = 105;

int n, l;
int a[MN];
int b[MN];
int d[MN][MN];
int rec[MN][MN];

inline void ver(int t)  {
    For(i, 1, l)
        d[0][i] = INT_MIN;
    For(i, 1, n)  {
        For(j, 0, l)  {
            d[i][j] = d[i - 1][j] + t / b[i];
            rec[i][j] = 0;
            For(k, 1, j)  {
                if(k * a[i] > t)
                    break;
                int exp = d[i - 1][j - k] + (t - a[i] * k) / b[i];//sunt bauti k l de al i-lea musteriu
                if(exp > d[i][j])  {
                    d[i][j] = exp;
                    rec[i][j] = k;
                }
            }
        }
    }
}

int ans[MN];

void recons(int r)  {
    int tot = l;
    iFor(i, 1, n)  {
        ans[i] = rec[i][tot];
        tot -= rec[i][tot];
    }
    For(i, 1, n)  {
        P("%d %d\n", ans[i], (r - a[i] * ans[i]) / b[i]);
    }
}

int main()  {
	if(DBG)  {
		freopen("lapte.in", "r", stdin);
		freopen("lapte.out", "w", stdout);
	}
	R("%d%d", &n, &l);
    For(i, 1, n)  {
        R("%d%d", &a[i], &b[i]);
    }
    int r = -1, pas = 1 << 8;
    while(pas)  {
        ver(r + pas);
        if(d[n][l] < l)  {
            r += pas;
        }
        pas >>= 1;
    }
    r++;
    P("%d\n", r);
    ver(r);
    recons(r);
	return 0;
}