Pagini recente » Cod sursa (job #2280183) | Cod sursa (job #165586) | Cod sursa (job #636250) | Cod sursa (job #2041616) | Cod sursa (job #1189422)
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef pair<char, char> pcc;
const int Nmax = 105;
const int Lmax = 105;
int N, L;
int B[Nmax][2];
//int dp[Lmax][Lmax];
int dp[Lmax];
int nt[Lmax];
pcc from[Lmax][Lmax];
inline int min(int x, int y) { return x < y ? x : y; }
inline int max(int x, int y) { return x > y ? x : y; }
bool check(int T)
{
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (int n = 0; n < N; n++)
{
int a = B[n][0];
int b = B[n][1];
for (int l = 0; l <= L; l++)
nt[l] = -1;
int x = 0;
while(x*a <= T)
{
int y = (T - x*a) / b;
for (int l = 0; l < L; l++)
if (dp[l] >= 0)
{
if (l+x <= L && nt[l+x] < dp[l] + y)
nt[l+x] = dp[l] + y;
else if (l+x > L && nt[L] < dp[l] + y)
nt[L] = dp[l] + y;
}
x = max(x+1, (T - (y-1)*b)/a);
}
for (int l = 0; l <= L; l++)
if (dp[l] < nt[l])
dp[l] = nt[l];
if (dp[L] >= L)
return 1;
}
return 0;
}
int main()
{
ifstream f ("lapte.in");
ofstream g ("lapte.out");
f >> N >> L;
for (int n = 0; n < N; n++)
f >> B[n][0] >> B[n][1];
int low = 1, high = 205*L;
while(low < high)
{
int mid = (high +low)/2;
if (check(mid))
high = mid;
else
low = mid +1;
}
g << low << '\n';
return 0;
}