Pagini recente » Cod sursa (job #446321) | Cod sursa (job #1098628) | Cod sursa (job #318955) | Cod sursa (job #1323595) | Cod sursa (job #2935917)
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <vector>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
//#include <bits/stdc++.h>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
const int maxx = 5003;
int n, g;
struct oop
{
int w, p;
}Q[maxx];
long long dp[10003];
void read()
{
fin >> n >> g;
for (int i = 1; i <= n; ++i)
{
fin >> Q[i].w >> Q[i].p;
}
}
void fn()
{
for (int i = 1; i <= n; ++i)
for (int j = g - Q[i].w; j >= 0; --j)
dp[j + Q[i].w] = max(dp[j + Q[i].w], Q[i].p + dp[j]);
fout << dp[g];
}
int main()
{
read();
fn();
}