Cod sursa(job #3143098)

Utilizator NutaAlexandruASN49K NutaAlexandru Data 27 iulie 2023 17:43:13
Problema Lapte Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.58 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <set>
#include <functional>
#include <bitset>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename A> ostream& operator<<(ostream &os, vector<A>&a) { for(auto &c:a)os<<c<<' '; return os;}
template<typename A> istream& operator>>(istream  &os, vector<A>&a) { for(auto &c:a)os>>c; return os;}
template<typename A,size_t N> istream& operator>>(istream &os, array<A,N>&a) { for(auto &c:a)os>>c; return os;}
#define bug(a) cerr << "(" << #a << ": " << a << ")\n";
#define all(x) x.begin(),x.end()
#define pb push_back
#define PQ priority_queue
#define pii pair<int,int>
using i64= int64_t;
using i16= int16_t;
using u64= uint64_t;
using u32= uint32_t;
using i32= int32_t;
const i32 inf=1e9;
const i64 INF=1e18;
const int mod=1e9+7;
ifstream cin("lapte.in");
ofstream cout("lapte.out");
void solve()
{

    int n,l;
    cin>>n>>l;
    vector<pair<int,int>>a(n);
    for(auto &c:a)cin>>c.first>>c.second;
    auto ok=[&](int t,bool x)
    {
        vector<vector<int>>dp(n+1,vector<int>(l+1,-inf));
        vector<vector<int>>tt(n+1,vector<int>(l+1,-1));
        dp[0][0]=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<=l;j++)
            {
                for(int k=j;k>=0 && (j-k)*a[i].first<=t;k--)
                {
                    int aux=dp[i][k]+(t-(j-k)*a[i].first)/a[i].second;
                    if(dp[i+1][j]<aux)
                    {
                        dp[i+1][j]=aux;
                        tt[i+1][j]=k;
                    }
                }
            }
        }
        if(!x)
        {
            return dp[n][l]>=l;
        }
        int j=l;
        for(int i=n;i;i--)
        {
            if(j==-1)exit(-1);
            cout<<j-tt[i][j]<<' '<<dp[i][j]-dp[i-1][tt[i][j]]<<'\n';
            j=tt[i][j];
        }
    };
    int st=1,dr=100,rez=-1;
    while(st<=dr)
    {
        int m=(st+dr)/2;
        if(ok(m,0))
        {
            rez=m;
            dr=m-1;
        }
        else
        {
            st=m+1;
        }
    }
    cout<<rez<<'\n';
    ok(rez,1);
}
main()
{
    auto sol=[&](bool x)
    {
        if(x)return "YES\n";
        return "NO\n";
    };
    i32 tt=1;
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(tt--)
    {
        solve();
    }
}