Cod sursa(job #3251177)

Utilizator Dia3141Costea Diana Stefania Dia3141 Data 25 octombrie 2024 11:26:26
Problema Lapte Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <fstream>
using namespace std;
ifstream cin("lapte.in");
ofstream cout("lapte.out");
int dp[101][101],r[101][101],n,l,a[101],b[101],sol;
void verif(int t){
    for(int i=1;i<=n;i++)
        for(int j=0;j<=l;j++)
            dp[i][j]=-1,r[i][j]=0;
    for(int i=0;i<=l;i++)
        if(i*a[1]<=t)
            dp[1][i]=(t-i*a[1])/b[1];
    for(int i=2;i<=n;i++)
        for(int j=0;j<=l;j++)
            for(int k=0;k<=j;k++)
                if(dp[i-1][k]!=-1&&dp[i][j]<dp[i-1][k]+(t-(j-k)*a[i])/b[i]&&(j-k)*a[i]<=t){
                    dp[i][j]=dp[i-1][k]+(t-(j-k)*a[i])/b[i];
                    r[i][j]=k;
                }
}
void rec(int i,int j){
    if(j>0||i>0){
        rec(i-1,r[i][j]);
        cout<<j-r[i][j]<<" "<<dp[i][j]-dp[i-1][r[i][j]]<<'\n';
    }
}
int main()
{
    cin>>n>>l;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    int st=1,dr=100;
    while(st<=dr){
        int mid=(st+dr)/2;
        verif(mid);
        if(dp[n][l]>=l)
            sol=mid,dr=mid-1;
        else
            st=mid+1;
    }
    cout<<sol<<'\n';
    verif(sol);
    rec(n,l);
    return 0;
}