hiho week 195 register

Ended

Participants:264

Verdict:Time Limit Exceeded
Score:50 / 100
Submitted:2018-03-25 10:04:57

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <cstring>
#include <math.h>
using namespace std;
long long Wi[100100];
long long Pi[100100];
int main() {
    //freopen("E:\\input.txt", "r", stdin);
    int N,M;
    scanf("%d %d", &N,&M);
    for (int i = 1; i <= N; i++) 
        scanf("%d %d", &Wi[i], &Pi[i]);
    vector<vector<long long>> dp(2, vector<long long>(M + 1, 0));
    int cur = 0;
    for (int i = 1; i <= N; i++) {
        cur = 1 - cur;
        int pre = 1 - cur;
        for (int j = M; j >= 0; j--) {
            if (j < Wi[i]) {
                dp[cur][j] = dp[pre][j];
                continue;
            }
                
            dp[cur][j] = max(dp[pre][j], dp[pre][j - Wi[i]] + Pi[i]);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX