Cod sursa(job #1643525)

Utilizator ajeccAjechiloae Eugen ajecc Data 9 martie 2016 19:11:42
Problema Problema rucsacului Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 1.48 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define V vector<int>
#define VP vector<pair<int, int> >
#define clr(A,x) memset(A, x, sizeof(A))
#define cpy(A,B) memcpy(A, B, sizeof(B))
#define g(s) getline(cin, s) ///ai grija la fin ///
#define FASTIO ios_base::sync_with_stdio(0)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MAX=100005;
const ull MOD=100003;
const int NR_CIFRE=100005;
/*template <typename T>
string to_string(const T& n){
    ostringstream os;
    os << n;
    return os.str();
}
*/
/*struct coord
{
    int x,y;

};
bool operator<(const coord &l, const coord &r)
{
    return (l.x<r.x || (l.x==r.x && l.y<r.y));
}*/

ifstream fin("rucsac.in"); /// modifica cu numele corespunzator
ofstream fout("rucsac.out"); /// modifica cu numele corespunzator

int v[10001];

int main()
{
    //VP v;
    int n, g;
    int rez=0;
    fin>>n>>g;
    for1(o, n)
    {
        int w,p;
        fin>>w>>p;
        for(int i=g-w; i>=0; i--)
            if(v[i]+p>v[i+w])
            {
                v[i+w]=v[i]+p;
                if(rez<v[i+w])
                    rez=v[i+w];
            }

    }
    fout<<rez;


    return 0;
}