Pagini recente » Cod sursa (job #1987792) | Cod sursa (job #2153122) | Cod sursa (job #1814818) | Cod sursa (job #2883568) | Cod sursa (job #2183536)
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 110;
int n, l, a[maxn], b[maxn], d[maxn][maxn] = {}, how_much_a[maxn][maxn] = {};
int possible_b(int t, int i, int a_baut){
return (t - a[i] * a_baut) / b[i];
}
bool can_do(int t){
for(int i = 0; i < maxn; ++i)
for(int j = 0; j < maxn; ++j)
d[i][j] = -1e9;
d[0][0] = 0;
for(int i = 1; i <= n; ++i)
for(int a_baut = 0; a_baut <= l && a[i] * a_baut <= t; ++a_baut)
for(int j = a_baut; j <= l; ++j)
if(d[i][j] < possible_b(t, i, a_baut) + d[i-1][j-a_baut])
d[i][j] = possible_b(t, i, a_baut) + d[i-1][j-a_baut],
how_much_a[i][j] = a_baut;
return d[n][l] >= l; }
int solve(){
int rez = 127;
for(int step = 64; step; step /= 2)
if(rez-step >= 0 && can_do(rez-step))
rez -= step;
return rez; }
int main(){
ifstream f("lapte.in");
ofstream g("lapte.out");
f >> n >> l;
for(int i = 1; i <= n; ++i)
f >> a[n-i+1] >> b[n-i+1];
const int rez = solve();
g << rez << endl;
can_do(rez);
for(int i = n, a_left = l; i > 0; a_left -= how_much_a[i--][a_left])
g << how_much_a[i][a_left] << ' ' <<
possible_b(rez, i, how_much_a[i][a_left]) << endl;
return 0;
}