Cod sursa(job #1589783)

Utilizator GrandmasterSoucup Bogdan Grandmaster Data 4 februarie 2016 13:47:41
Problema Energii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>
#include <cstring>
#include <map>
#include <iomanip>
#include <time.h>
#include <stdio.h>
#include <bitset>
#define MAX 500000000000
//#include <iostream>
using namespace std;
ifstream cin("energii.in");
ofstream cout("energii.out");
int DP[2][5004];
int main()
{
    int n, s, x[10004], y[10005], v;
    cin >> n >> s;
    for(int i = 1; i <= n; i++)
        cin >> x[i] >> y[i];
    int l = 0;
    for(int i = 1; i <= n; i++, l = 1 - l){
        for(int j = 0; j <= s; j++){
            DP[l][j] = DP[1 - l][j];
            if(j >= x[i])
                DP[l][j] = max(DP[1 - l][j], DP[1 - l][j - x[i]] + y[i]);
        }
    }
    cout << max(DP[0][s], DP[1][s]);
    return 0;
}