Pagini recente » Monitorul de evaluare | Monitorul de evaluare | Cod sursa (job #46745) | Monitorul de evaluare | Cod sursa (job #3353641)
#include <bits/stdc++.h>
using namespace std;
const int Nmax=105,inf=-1e9;
int n,l;
int a[Nmax],b[Nmax],dp[Nmax][Nmax],prv[Nmax][Nmax];
bool check(int t) {
fill(dp[0],dp[0]+Nmax*Nmax,inf);
dp[0][0]=0;
for (int i=1; i<=n; ++i) {
for (int j=0; j<=l; ++j) {
for (int lapteA=0; lapteA<=j && lapteA*a[i]<=t; ++lapteA) {
int lapteB=dp[i-1][j-lapteA]+(t-lapteA*a[i])/b[i];
if (dp[i][j]<lapteB) {
dp[i][j]=lapteB;
prv[i][j]=lapteA;
}
}
}
}
return dp[n][l]>=l;
}
ifstream fin("lapte.in");
ofstream fout("lapte.out");
void afis (int i, int j, int t) {
if (i==0) return;
int A=prv[i][j];
int B=(t-A*a[i])/b[i];
afis(i-1,j-A,t);
fout<<A<<' '<<B<<'\n';
}
int main() {
fin>>n>>l;
for (int i=1; i<=n; ++i) fin>>a[i]>>b[i];
int st=0,dr=2e4,ans=2e4;
while (st<=dr) {
int mij=(st+dr)/2;
if (check(mij)) {
ans=mij;
dr=mij-1;
}
else st=mij+1;
}
check(ans);
fout<<ans<<'\n';
afis(n,l,ans);
return 0;
}