Cod sursa(job #2665484)

Utilizator drknss_Hehe hehe drknss_ Data 30 octombrie 2020 21:12:15
Problema Lapte Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.05 kb
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long LL;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
#define int long long
#define cin in
#define cout out

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const LL inf = 2e9;
const LL mod = 1e9 + 7;
const int N = 2e2 + 11;
const LL INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

ifstream in("lapte.in");
ofstream out("lapte.out");

int n, a[N], b[N], l;
int dp[N][N], from[N][N];

//dp[i][j] - b, a*j l && first i pos

int slv(int t){

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= l; j++){
            dp[i][j] = -inf;
        }
    }

    dp[0][0] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= l; j++){
            for(int k = 0; k <= j && k*a[i] <= t; k++){
                int used = k*a[i];
                int nw = dp[i - 1][j - k] + (t - used)/b[i];
                if(nw > dp[i][j]){
                    dp[i][j] = nw;
                    from[i][j] = j - k;
                }
            }
        }
    }

    return (dp[n][l] >= l);
}


void solve(){

    cin >> n >> l;

    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }

    int l = 0, r = 200, ans = 0;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(slv(mid)){
            ans = mid;
            r = mid - 1;
        }else l = mid + 1;
    }

    slv(ans);

    cout << ans << '\n';

    int x = n;
    vector<pi> v;

    while(x){
        v.pb({l - from[x][l], dp[x][l] - dp[x - 1][from[x][l]]});
        l = from[x][l], x--;
    }

    reverse(all(v));

    for(auto it : v){
        cout << it.ff << ' ' << it.ss << '\n';
    }
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //cout << setprecision(6) << fixed;

    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
}