Submission #16489154


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, W;
ll w[105], v[105];
ll DP[105][int(1e5+5)];

int main(){
  cin >> N >> W;
  for (int i = 1; i <= N; i++){
    cin >> w[i] >> v[i];
  }

  fill((ll*)DP, (ll*)(DP + N + 1), 1e18);
  DP[0][0] = 0;

  for (int i = 1; i <= N; i++){
    for (int j = 0; j <= int(1e5); j++){
      DP[i][j] = DP[i-1][j];
    }
    for (int j = 0; j + v[i] <= int(1e5); j++){
      DP[i][j+v[i]] = min(DP[i][j+v[i]], DP[i-1][j] + w[i]);
    }
  }

  for (int j = 1e5; j >= 0; j--){
    if (DP[N][j] <= W){
      cout << j << endl;
      return 0;
    }
  }

  return 0;
}

Submission Info

Submission Time
Task E - Knapsack 2
User yutas
Language C++ (GCC 9.2.1)
Score 100
Code Size 1202 Byte
Status AC
Exec Time 82 ms
Memory 82456 KiB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 21
Set Name Test Cases
All 0_00, 0_01, 0_02, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15, 1_16, 1_17
Case Name Status Exec Time Memory
0_00 AC 13 ms 6488 KiB
0_01 AC 4 ms 4972 KiB
0_02 AC 8 ms 9012 KiB
1_00 AC 5 ms 4976 KiB
1_01 AC 75 ms 82412 KiB
1_02 AC 81 ms 82416 KiB
1_03 AC 78 ms 82452 KiB
1_04 AC 75 ms 82416 KiB
1_05 AC 79 ms 81676 KiB
1_06 AC 82 ms 82300 KiB
1_07 AC 75 ms 81520 KiB
1_08 AC 75 ms 81548 KiB
1_09 AC 72 ms 82440 KiB
1_10 AC 79 ms 81628 KiB
1_11 AC 72 ms 81684 KiB
1_12 AC 70 ms 79980 KiB
1_13 AC 72 ms 82452 KiB
1_14 AC 76 ms 81492 KiB
1_15 AC 77 ms 82456 KiB
1_16 AC 77 ms 82412 KiB
1_17 AC 77 ms 82456 KiB