Submission #3772839


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, W; cin >> n >> W;
  vll w(n), v(n);
  REP(i, n) {
    cin >> w[i] >> v[i];
  }

  vector<map<int, ll>> dp(n);
  dp[0][w[0]] = v[0];
  REP(i, n-1) {
    MFOR(j, dp[i]) {
      dp[i+1][j->first] = max(dp[i+1][j->first], j->second);
      dp[i+1][j->first + w[i+1]] = max(dp[i+1][j->first + w[i+1]], j->second + v[i+1]);
    }
    dp[i+1][w[i+1]] = max(dp[i+1][w[i+1]], v[i+1]);
  }

  ll ma = 0;
  MFOR(j, dp[n-1]) {
    if(j->first > W) break;
    ma = max(ma, j->second);
  }
  cout << ma << endl;
}

Submission Info

Submission Time
Task D - Simple Knapsack
User kanra824
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1450 Byte
Status WA
Exec Time 56 ms
Memory 13952 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 4
AC × 13
WA × 3
Set Name Test Cases
Sample example0, example1, example2, example3
All antigreedy0, antigreedy1, antigreedy2, example0, example1, example2, example3, quarter0, quarter1, quarter2, rand0, rand1, rand2, smallw0, smallw1, smallw2
Case Name Status Exec Time Memory
antigreedy0 AC 2 ms 512 KB
antigreedy1 AC 2 ms 512 KB
antigreedy2 AC 2 ms 512 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
example3 AC 1 ms 256 KB
quarter0 AC 38 ms 10496 KB
quarter1 AC 38 ms 10496 KB
quarter2 AC 39 ms 9856 KB
rand0 WA 1 ms 256 KB
rand1 WA 8 ms 1920 KB
rand2 WA 2 ms 512 KB
smallw0 AC 55 ms 13824 KB
smallw1 AC 56 ms 13952 KB
smallw2 AC 23 ms 7040 KB