problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k ⌀ | fixed_code stringlengths 12 526k ⌀ | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M ⌀ | fixed_submission_id int64 2 1.54M ⌀ | user_id stringlengths 10 10 ⌀ | language stringclasses 9
values |
|---|---|---|---|---|---|---|---|
p03163 | #include <bits/stdc++.h>
using namespace std;
int n, W, dp[105][100005], v[105], w[105], ans;
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[n][i]);
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
long long n, W, dp[105][100005], v[105], w[105], ans;
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[n][i]);
}
cout << ans;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,433 | 965,434 | u483551214 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[w + 1][n + 1];
for (ll i = 0; i <= w; i++) {
for (ll j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[j - 1] > i)
dp[i][j] = dp[i][j - 1];
else
dp[i][j] = max(v[i - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1]);
}
}
cout << dp[w][n] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[w + 1][n + 1];
for (ll i = 0; i <= w; i++) {
for (ll j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[j - 1] > i)
dp[i][j] = dp[i][j - 1];
else
dp[i][j] = max(v[j - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1]);
}
}
cout << dp[w][n] << endl;
return 0;
}
| [
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,437 | 965,439 | u438469926 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[w + 1][n + 1];
for (ll i = 0; i <= w; i++) {
for (ll j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] > j)
dp[i][j] = dp[i][j - 1];
else
dp[i][j] = max(v[i - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1]);
}
}
cout << dp[w][n] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[w + 1][n + 1];
for (ll i = 0; i <= w; i++) {
for (ll j = 0; j <= n; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[j - 1] > i)
dp[i][j] = dp[i][j - 1];
else
dp[i][j] = max(v[j - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1]);
}
}
cout << dp[w][n] << endl;
return 0;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,440 | 965,439 | u438469926 | cpp |
p03163 | #include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
/* Macros reg. ends here */
const ll INF = 1LL << 50;
static const long long mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
class modutils {
vector<mint> fact, invfact;
public:
modutils(int n = 200005) : fact(n + 1), invfact(n + 1) {
fact[0] = 1;
for (int i = 1; i <= n; i++)
fact[i] = fact[i - 1] * i;
invfact[n] = fact[n].inv();
for (int i = n; i >= 1; i--)
invfact[i - 1] = invfact[i] * i;
}
mint pow(mint x, ll n) { return x.pow(n); }
mint comb(ll n, ll k) {
if (n < 0 || k < 0 || n < k)
return 0;
return fact[n] * invfact[k] * invfact[n - k];
}
mint perm(ll n, ll k) {
if (n < 0 || k < 0 || n < k)
return 0;
return fact[n] * invfact[n - k];
}
mint fac(ll n) { return fact[n]; }
};
int main() {
// ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
ll n, w;
cin >> n >> w;
vll ws(n), vs(n);
rep(i, n) cin >> ws[i] >> vs[i];
vvll dp(n + 1, vll(w + 1, 0));
rep(i, n) {
repLRE(j, 1, w) {
dp[i + 1][j] = dp[i][j];
ll pj = j - ws[i];
if (pj >= 0)
dp[i + 1][j] = dp[i][pj] + vs[i];
}
}
ll ans = dp.back().back();
cout << ans << endl;
return 0;
}
| #include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;
ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
/* Macros reg. ends here */
const ll INF = 1LL << 50;
static const long long mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
class modutils {
vector<mint> fact, invfact;
public:
modutils(int n = 200005) : fact(n + 1), invfact(n + 1) {
fact[0] = 1;
for (int i = 1; i <= n; i++)
fact[i] = fact[i - 1] * i;
invfact[n] = fact[n].inv();
for (int i = n; i >= 1; i--)
invfact[i - 1] = invfact[i] * i;
}
mint pow(mint x, ll n) { return x.pow(n); }
mint comb(ll n, ll k) {
if (n < 0 || k < 0 || n < k)
return 0;
return fact[n] * invfact[k] * invfact[n - k];
}
mint perm(ll n, ll k) {
if (n < 0 || k < 0 || n < k)
return 0;
return fact[n] * invfact[n - k];
}
mint fac(ll n) { return fact[n]; }
};
int main() {
// ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
ll n, w;
cin >> n >> w;
vll ws(n), vs(n);
rep(i, n) cin >> ws[i] >> vs[i];
vvll dp(n + 1, vll(w + 1, 0));
rep(i, n) {
repLRE(j, 1, w) {
dp[i + 1][j] = dp[i][j];
ll pj = j - ws[i];
if (pj >= 0)
chmax(dp[i + 1][j], dp[i][pj] + vs[i]);
}
}
ll ans = dp.back().back();
cout << ans << endl;
return 0;
}
| [
"call.add",
"call.arguments.change"
] | 965,441 | 965,442 | u714724786 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int dp[101][100001];
long long maxProfit(vector<int> &w, vector<int> &v, int n, int W) {
if (n == 0 || W == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (w[n - 1] <= W)
return dp[n][W] = max(v[n - 1] + maxProfit(w, v, n - 1, W - w[n - 1]),
maxProfit(w, v, n - 1, W));
return dp[n][W] = maxProfit(w, v, n - 1, W);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, W;
cin >> n >> W;
vector<int> w(n);
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << maxProfit(w, v, n, W);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long dp[101][100001];
long long maxProfit(vector<int> &w, vector<int> &v, int n, int W) {
if (n == 0 || W == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (w[n - 1] <= W)
return dp[n][W] = max(v[n - 1] + maxProfit(w, v, n - 1, W - w[n - 1]),
maxProfit(w, v, n - 1, W));
return dp[n][W] = maxProfit(w, v, n - 1, W);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, W;
cin >> n >> W;
vector<int> w(n);
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << maxProfit(w, v, n, W);
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,443 | 965,444 | u257062721 | cpp |
p03163 | #include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 10000000000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed << setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define forr(i, p, n) for (ll i = p; i < n; i++)
#define MAXN 500003
typedef long long ll;
using namespace std;
ll mult(ll a, ll b, ll p = MOD) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = MOD) { return (a % p + b % p) % p; }
ll fpow(ll n, ll k, ll p = MOD) {
ll r = 1;
for (; k; k >>= 1) {
if (k & 1)
r = r * n % p;
n = n * n % p;
}
return r;
}
ll inv(ll a, ll p = MOD) { return fpow(a, p - 2, p); }
ll inv_euclid(ll a, ll m = MOD) {
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
ll q = a / m;
ll t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<pair<ll, ll>> v;
ll sum = 0, act = 0, k, n, q, f;
ll w;
cin >> n >> w;
v.reserve(n);
forr(i, 0, n) {
ll a, b;
cin >> a >> b;
v.pb(mp(a, b));
}
ll dp[n + 1][w + 1];
forr(i, 0, n + 1) {
forr(j, 0, w + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (j < v[i - 1].first) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(v[i - 1].second + dp[i - 1][j - v[i - 1].first],
v[i - 1].second);
}
// c//out<<dp[i][j]<<" ";
}
// cout<<endl;
}
cout << dp[n][w] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 10000000000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed << setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define forr(i, p, n) for (ll i = p; i < n; i++)
#define MAXN 500003
typedef long long ll;
using namespace std;
ll mult(ll a, ll b, ll p = MOD) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = MOD) { return (a % p + b % p) % p; }
ll fpow(ll n, ll k, ll p = MOD) {
ll r = 1;
for (; k; k >>= 1) {
if (k & 1)
r = r * n % p;
n = n * n % p;
}
return r;
}
ll inv(ll a, ll p = MOD) { return fpow(a, p - 2, p); }
ll inv_euclid(ll a, ll m = MOD) {
ll m0 = m;
ll y = 0, x = 1;
if (m == 1)
return 0;
while (a > 1) {
ll q = a / m;
ll t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)
x += m0;
return x;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<pair<ll, ll>> v;
ll sum = 0, act = 0, k, n, q, f;
ll w;
cin >> n >> w;
v.reserve(n);
forr(i, 0, n) {
ll a, b;
cin >> a >> b;
v.pb(mp(a, b));
}
ll dp[n + 1][w + 1];
forr(i, 0, n + 1) {
forr(j, 0, w + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (j < v[i - 1].first) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] =
max(v[i - 1].second + dp[i - 1][j - v[i - 1].first], dp[i - 1][j]);
}
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
cout << dp[n][w] << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change"
] | 965,445 | 965,446 | u269759214 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
struct item {
ll weight;
ll value;
};
ll solve(ll n, ll w, vector<item> &v) {
ll dp[n + 1][w + 1]; // w is the maximum capacity that the bag can hold....
// agr app 1 pr hu to sirf vo he item ko le sakte hu jiska weight hu...
// items are not breakable....
for (ll j = 1; j <= w; j++) {
dp[1][j] = 0; // kisi ko bhi nhi le rha hu..
}
dp[1][v.at(1).weight] = v.at(1).value;
for (ll i = 2; i <= n; i++) {
for (ll j = 0; j <= w; j++) // zero se suru karenge...// bag pura empty hu
// ye tu eik valid case hai...
{
ll option1, option2;
option1 = option2 = LLONG_MIN;
option1 = dp[i - 1][j];
if (j - v.at(i).weight >=
0) // uss element ko le sakte hain ki nhi ye check krna hai.....
{
option2 = v.at(i).value + dp[i - 1][j - v.at(i).weight];
}
dp[i][j] = max(option1, option2);
}
}
return *max_element(dp[n], dp[n] + w + 1);
}
int main() {
ll n, w;
cin >> n >> w;
vector<item> v(n + 1); // item is a user defined data type....
for (ll i = 1; i <= n; i++) {
cin >> v.at(i).weight >> v.at(i).value;
}
cout << solve(n, w, v);
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
struct item {
ll weight;
ll value;
};
ll solve(ll n, ll w, vector<item> &v) {
ll dp[n + 1][w + 1]; // w is the maximum capacity that the bag can hold....
// agr app 1 pr hu to sirf vo he item ko le sakte hu jiska weight hu...
// items are not breakable....
for (ll j = 0; j <= w; j++) // j can be zero...
{
dp[1][j] = 0; // kisi ko bhi nhi le rha hu..
}
dp[1][v.at(1).weight] = v.at(1).value;
for (ll i = 2; i <= n; i++) {
for (ll j = 0; j <= w; j++) // zero se suru karenge...// bag pura empty hu
// ye tu eik valid case hai...
{
ll option1, option2;
option1 = option2 = LLONG_MIN;
option1 = dp[i - 1][j];
if (j - v.at(i).weight >=
0) // uss element ko le sakte hain ki nhi ye check krna hai.....
{
option2 = v.at(i).value + dp[i - 1][j - v.at(i).weight];
}
dp[i][j] = max(option1, option2);
}
}
return *max_element(dp[n], dp[n] + w + 1);
}
int main() {
ll n, w;
cin >> n >> w;
vector<item> v(n + 1); // item is a user defined data type....
for (ll i = 1; i <= n; i++) {
cin >> v.at(i).weight >> v.at(i).value;
}
cout << solve(n, w, v);
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 965,486 | 965,487 | u881931540 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
struct item {
ll weight;
ll value;
};
ll solve(ll n, ll w, vector<item> &v) {
ll dp[n + 1][w + 1]; // w is the maximum capacity that the bag can hold....
// agr app 1 pr hu to sirf vo he item ko le sakte hu jiska weight hu...
// items are not breakable....
for (int j = 1; j <= w; j++) {
dp[1][j] = 0; // kisi ko bhi nhi le rha hu..
}
dp[1][v.at(1).weight] = v.at(1).value;
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= w; j++) // zero se suru karenge...// bag pura empty hu
// ye tu eik valid case hai...
{
ll option1, option2;
option1 = option2 = LLONG_MIN;
option1 = dp[i - 1][j];
if (j - v.at(i).weight >=
0) // uss element ko le sakte hain ki nhi ye check krna hai.....
{
option2 = v.at(i).value + dp[i - 1][j - v.at(i).weight];
}
dp[i][j] = max(option1, option2);
}
}
return *max_element(dp[n], dp[n] + w + 1);
}
int main() {
ll n, w;
cin >> n >> w;
vector<item> v(n + 1); // item is a user defined data type....
for (int i = 1; i <= n; i++) {
cin >> v.at(i).weight >> v.at(i).value;
}
cout << solve(n, w, v);
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
struct item {
ll weight;
ll value;
};
ll solve(ll n, ll w, vector<item> &v) {
ll dp[n + 1][w + 1]; // w is the maximum capacity that the bag can hold....
// agr app 1 pr hu to sirf vo he item ko le sakte hu jiska weight hu...
// items are not breakable....
for (ll j = 0; j <= w; j++) // j can be zero...
{
dp[1][j] = 0; // kisi ko bhi nhi le rha hu..
}
dp[1][v.at(1).weight] = v.at(1).value;
for (ll i = 2; i <= n; i++) {
for (ll j = 0; j <= w; j++) // zero se suru karenge...// bag pura empty hu
// ye tu eik valid case hai...
{
ll option1, option2;
option1 = option2 = LLONG_MIN;
option1 = dp[i - 1][j];
if (j - v.at(i).weight >=
0) // uss element ko le sakte hain ki nhi ye check krna hai.....
{
option2 = v.at(i).value + dp[i - 1][j - v.at(i).weight];
}
dp[i][j] = max(option1, option2);
}
}
return *max_element(dp[n], dp[n] + w + 1);
}
int main() {
ll n, w;
cin >> n >> w;
vector<item> v(n + 1); // item is a user defined data type....
for (ll i = 1; i <= n; i++) {
cin >> v.at(i).weight >> v.at(i).value;
}
cout << solve(n, w, v);
return 0;
} | [
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change",
"literal.number.change",
"variable_declaration.value.change",
"expression.off_by_one"
] | 965,488 | 965,487 | u881931540 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
long long dp[101][(int)pow(10, 5) + 1] = {0};
int value[101];
int weight[101];
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j - weight[i] >= 0) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
}
}
}
cout << dp[n][w] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
long long dp[101][(int)pow(10, 5) + 1] = {0};
int value[101];
int weight[101];
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j - weight[i - 1] >= 0) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
}
}
}
cout << dp[n][w] << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 965,491 | 965,492 | u958745398 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
long long actionFunction(vector<int> &weights, vector<long long> &values,
int maxWeightCapacity) {
if (weights.size() == 0 || maxWeightCapacity < 0)
return 0;
vector<vector<long long>> dp(weights.size() + 1,
vector<long long>(maxWeightCapacity + 1, 0));
for (int i = 1; i <= weights.size(); i++) {
for (int k = 0; k <= maxWeightCapacity; k++) {
dp[i][k] =
(long long)max((long long)dp[i - 1][k],
(long long)(weights[i - 1] <= k)
? (long long)values[i - 1] +
(long long)dp[i - 1][k - weights[i - 1]]
: 0);
}
}
return dp[weights.size() - 1][maxWeightCapacity - 1];
}
int main(void) {
vector<int> weights;
vector<long long> values;
int n, k, tmp;
long long tmpl;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> tmp;
cin >> tmpl;
weights.push_back(tmp);
values.push_back(tmpl);
}
cout << actionFunction(weights, values, k) << endl;
}
| #include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
long long actionFunction(vector<int> &weights, vector<long long> &values,
int maxWeightCapacity) {
if (weights.size() == 0 || maxWeightCapacity < 0)
return 0;
vector<vector<long long>> dp(weights.size() + 1,
vector<long long>(maxWeightCapacity + 1, 0));
for (int i = 1; i <= weights.size(); i++) {
for (int k = 0; k <= maxWeightCapacity; k++) {
dp[i][k] =
(long long)max((long long)dp[i - 1][k],
(long long)(weights[i - 1] <= k)
? (long long)values[i - 1] +
(long long)dp[i - 1][k - weights[i - 1]]
: 0);
}
}
return dp[weights.size()][maxWeightCapacity];
}
int main(void) {
vector<int> weights;
vector<long long> values;
int n, k, tmp;
long long tmpl;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> tmp;
cin >> tmpl;
weights.push_back(tmp);
values.push_back(tmpl);
}
cout << actionFunction(weights, values, k) << endl;
}
| [
"expression.operation.binary.remove"
] | 965,495 | 965,496 | u309984532 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
long long actionFunction(vector<int> &weights, vector<long long> &values,
int maxWeightCapacity) {
if (weights.size() == 0 || maxWeightCapacity < 0)
return 0;
vector<vector<long long>> dp(weights.size() + 1,
vector<long long>(maxWeightCapacity + 1, 0));
for (int i = 1; i <= weights.size(); i++) {
for (int k = 0; k <= maxWeightCapacity; k++) {
dp[i][k] = (long long)max(
(long long)dp[i - 1][k],
(long long)(weights[i - 1] <= k)
? (long long)values[i] + (long long)dp[i - 1][k - weights[i - 1]]
: 0);
}
}
return dp[weights.size() - 1][maxWeightCapacity - 1];
}
int main(void) {
vector<int> weights;
vector<long long> values;
int n, k, tmp;
long long tmpl;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> tmp;
cin >> tmpl;
weights.push_back(tmp);
values.push_back(tmpl);
}
cout << actionFunction(weights, values, k) << endl;
}
| #include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
long long actionFunction(vector<int> &weights, vector<long long> &values,
int maxWeightCapacity) {
if (weights.size() == 0 || maxWeightCapacity < 0)
return 0;
vector<vector<long long>> dp(weights.size() + 1,
vector<long long>(maxWeightCapacity + 1, 0));
for (int i = 1; i <= weights.size(); i++) {
for (int k = 0; k <= maxWeightCapacity; k++) {
dp[i][k] =
(long long)max((long long)dp[i - 1][k],
(long long)(weights[i - 1] <= k)
? (long long)values[i - 1] +
(long long)dp[i - 1][k - weights[i - 1]]
: 0);
}
}
return dp[weights.size()][maxWeightCapacity];
}
int main(void) {
vector<int> weights;
vector<long long> values;
int n, k, tmp;
long long tmpl;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> tmp;
cin >> tmpl;
weights.push_back(tmp);
values.push_back(tmpl);
}
cout << actionFunction(weights, values, k) << endl;
}
| [
"expression.operation.binary.remove"
] | 965,497 | 965,496 | u309984532 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
long long int lmax(long long int a, long long int b) {
if (a < b)
return b;
else
return a;
}
int main() {
long long int n, W;
cin >> n >> W;
vector<long long int> w(n);
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long int>> dp(n + 1, vector<long long int>(W, 0));
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i + 1][j] = lmax(dp[i][j], dp[i][j - w[i]] + v[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
cout << dp[n][W] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long int lmax(long long int a, long long int b) {
if (a < b)
return b;
else
return a;
}
int main() {
long long int n, W;
cin >> n >> W;
vector<long long int> w(n);
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long int>> dp(n + 1, vector<long long int>(W + 1, 0));
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i + 1][j] = lmax(dp[i][j], dp[i][j - w[i]] + v[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
cout << dp[n][W] << endl;
return 0;
} | [
"assignment.change"
] | 965,498 | 965,499 | u685983477 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
int n, we;
cin >> n >> we;
vector<long long> w(n);
vector<long long> v(n);
for (int i = 0; i < n; i++) {
cin >> w.at(i) >> v.at(i);
}
vector<vector<long long>> dp(n + 1, vector<long long>(we + 1, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j <= we; j++) {
if (j - w.at(i) >= 0) {
chmax(dp.at(i + 1).at(j), dp.at(i).at(j - w.at(i)) + v.at(i));
}
chmax(dp.at(i).at(j), dp.at(i + 1).at(j));
}
}
cout << dp.at(n).at(we) << endl;
} | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
int n, we;
cin >> n >> we;
vector<long long> w(n);
vector<long long> v(n);
for (int i = 0; i < n; i++) {
cin >> w.at(i) >> v.at(i);
}
vector<vector<long long>> dp(n + 1, vector<long long>(we + 1, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j <= we; j++) {
if (j - w.at(i) >= 0) {
chmax(dp.at(i + 1).at(j), dp.at(i).at(j - w.at(i)) + v.at(i));
}
chmax(dp.at(i + 1).at(j), dp.at(i).at(j));
}
}
cout << dp.at(n).at(we) << endl;
} | [
"call.arguments.change",
"call.arguments.add"
] | 965,513 | 965,514 | u507351098 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct items {
int wt;
int val;
};
long long solution(vector<items> a, int n, int W) {
int dp[n + 1][W + 1];
for (int w = 0; w <= W; w++) {
dp[1][w] = 0;
}
dp[1][a[1].wt] = a[1].val;
for (int i = 2; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (a[i].wt > w) {
continue;
}
dp[i][w] = max(dp[i][w], a[i].val + dp[i - 1][w - a[i].wt]);
}
}
return *max_element(dp[n], dp[n] + W + 1);
}
int main() {
int n, w;
cin >> n >> w;
vector<items> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i].wt >> a[i].val;
}
cout << solution(a, n, w);
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct items {
int wt;
int val;
};
long long solution(vector<items> a, int n, int W) {
long long dp[n + 1][W + 1];
for (int w = 0; w <= W; w++) {
dp[1][w] = 0;
}
dp[1][a[1].wt] = a[1].val;
for (int i = 2; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (a[i].wt > w) {
continue;
}
dp[i][w] = max(dp[i][w], a[i].val + dp[i - 1][w - a[i].wt]);
}
}
return *max_element(dp[n], dp[n] + W + 1);
}
int main() {
int n, w;
cin >> n >> w;
vector<items> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i].wt >> a[i].val;
}
cout << solution(a, n, w);
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,515 | 965,516 | u117708638 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int a[n], b[n];
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
int x[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
x[i][j] = 0;
else if (j < a[i - 1])
x[i][j] = x[i - 1][j];
else
x[i][j] = max(x[i - 1][j], b[i - 1] + x[i - 1][j - a[i - 1]]);
}
}
cout << x[n][w] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long n, w;
cin >> n >> w;
long a[n], b[n];
for (int i = 0; i < n; i++)
cin >> a[i] >> b[i];
long x[n + 1][w + 1];
for (long i = 0; i <= n; i++) {
for (long j = 0; j <= w; j++) {
if (i == 0 || j == 0)
x[i][j] = 0;
else if (j < a[i - 1])
x[i][j] = x[i - 1][j];
else
x[i][j] = max(x[i - 1][j], b[i - 1] + x[i - 1][j - a[i - 1]]);
}
}
cout << x[n][w] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"control_flow.loop.for.initializer.change"
] | 965,517 | 965,518 | u691174533 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
/**
* Uncomment the #define below if problem contains multiple test cases
*/
// #define MULTIPLE_TESTS 1
vector<vector<ll>> cache;
ll knapsack(int cur, int used, int W, const vector<ll> &wt,
const vector<ll> &val) {
if (cur == wt.size()) {
return 0;
}
if (cache[cur][used] != -1) {
return cache[cur][used];
}
// don't consider this item
ll option1 = knapsack(cur + 1, used, W, wt, val);
// consider this item
ll option2 = 0;
if (used + wt[cur] <= W) {
option2 = knapsack(cur + 1, used + wt[cur], W, wt, val) + val[cur];
}
return cache[cur][used] = max(option1, option2);
}
void solve() {
int n, w;
cin >> n >> w;
vector<ll> wt(n), val(n);
for (int i = 0; i < n; ++i) {
cin >> wt[i] >> val[i];
}
cache.assign(n, vector<ll>(w, -1));
cout << knapsack(0, 0, w, wt, val) << endl;
}
int main() {
FAST_IO;
int t = 1;
#ifdef MULTIPLE_TESTS
cin >> t;
#endif
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FAST_IO \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
/**
* Uncomment the #define below if problem contains multiple test cases
*/
// #define MULTIPLE_TESTS 1
vector<vector<ll>> cache;
ll knapsack(int cur, int used, int W, const vector<ll> &wt,
const vector<ll> &val) {
if (cur == wt.size()) {
return 0;
}
if (cache[cur][used] != -1) {
return cache[cur][used];
}
// don't consider this item
ll option1 = knapsack(cur + 1, used, W, wt, val);
// consider this item
ll option2 = 0;
if (used + wt[cur] <= W) {
option2 = knapsack(cur + 1, used + wt[cur], W, wt, val) + val[cur];
}
return cache[cur][used] = max(option1, option2);
}
void solve() {
int n, w;
cin >> n >> w;
vector<ll> wt(n), val(n);
for (int i = 0; i < n; ++i) {
cin >> wt[i] >> val[i];
}
cache.assign(n, vector<ll>(w + 1, -1));
cout << knapsack(0, 0, w, wt, val) << endl;
}
int main() {
FAST_IO;
int t = 1;
#ifdef MULTIPLE_TESTS
cin >> t;
#endif
while (t--) {
solve();
}
return 0;
} | [
"expression.operation.binary.add"
] | 965,519 | 965,520 | u856445425 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int MAX = 1e5;
int n, w;
vector<vector<int>> dp(100, vector<int>(MAX + 1));
vector<int> wi(100);
vector<int> vi(100);
ll calc(int index, int weight) {
if (index == n) {
return 0;
}
if (dp[index][weight] != -1) {
return dp[index][weight];
}
int ans;
if (wi[index] > w - weight) {
ans = calc(index + 1, weight);
} else {
ans = max(vi[index] + calc(index + 1, weight + wi[index]),
calc(index + 1, weight));
}
return dp[index][weight] = ans;
}
void solve() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> wi[i] >> vi[i];
for (int j = 0; j <= w; j++) {
dp[i][j] = -1;
}
}
int max_happ = calc(0, 0);
cout << max_happ << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
const int MAX = 1e5;
int n, w;
vector<vector<ll>> dp(100, vector<ll>(MAX + 1));
vector<int> wi(100);
vector<int> vi(100);
ll calc(int index, int weight) {
if (index == n) {
return 0;
}
if (dp[index][weight] != -1) {
return dp[index][weight];
}
ll ans;
if (wi[index] > w - weight) {
ans = calc(index + 1, weight);
} else {
ans = max(vi[index] + calc(index + 1, weight + wi[index]),
calc(index + 1, weight));
}
return dp[index][weight] = ans;
}
void solve() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> wi[i] >> vi[i];
for (int j = 0; j <= w; j++) {
dp[i][j] = -1;
}
}
ll max_happ = calc(0, 0);
cout << max_happ << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
| [
"call.arguments.change",
"variable_declaration.type.change"
] | 965,521 | 965,522 | u711132198 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
ll n, w;
cin >> n >> w;
vvi dp(n + 1, vi(w + 2, 0));
vector<pair<ll, ll>> wv(n + 2);
repf(i, n) cin >> wv[i].first >> wv[i].second;
for (ll i = 1; i <= n; i++) {
for (ll sum_weight = 1; sum_weight <= w; sum_weight++) {
if (sum_weight - wv[i].first >= 0) {
// i番目の商品を品物を持ち帰れる場合、ギリギリの容量が空いている場合の最大価値+i番目の品物の価値
chmax(dp[i][sum_weight],
dp[i - 1][sum_weight ^ wv[i].first] + wv[i].second);
}
// 選ばない場合はdpテーブルにおける上の行をそのまま引き継ぐ
chmax(dp[i][sum_weight], dp[i - 1][sum_weight]);
}
}
cout << dp[n][w] << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
ll n, w;
cin >> n >> w;
vvi dp(n + 1, vi(w + 1, 0));
vector<pair<ll, ll>> wv(n + 1);
repf(i, n) cin >> wv[i].first >> wv[i].second;
for (ll i = 1; i <= n; i++) {
for (ll sum_weight = 0; sum_weight <= w; sum_weight++) {
if (sum_weight - wv[i].first >= 0) {
// i番目の商品を品物を持ち帰れる場合、ギリギリの容量が空いている場合の最大価値+i番目の品物の価値
chmax(dp[i][sum_weight],
dp[i - 1][sum_weight - wv[i].first] + wv[i].second);
}
// 選ばない場合はdpテーブルにおける上の行をそのまま引き継ぐ
chmax(dp[i][sum_weight], dp[i - 1][sum_weight]);
}
}
cout << dp[n][w] << endl;
} | [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"variable_access.subscript.index.change"
] | 965,525 | 965,526 | u548791035 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
ll n, w;
cin >> n >> w;
vvi dp(n + 1, vi(w + 1, 0));
vector<pair<ll, ll>> wv(n + 1);
repf(i, n) cin >> wv[i].first >> wv[i].second;
for (ll i = 1; i <= n; i++) {
for (ll sum_weight = 1; sum_weight <= w; sum_weight++) {
if (sum_weight - wv[i].first >= 0) {
// i番目の商品を品物を持ち帰れる場合、ギリギリの容量が空いている場合の最大価値+i番目の品物の価値
chmax(dp[i][sum_weight],
dp[i - 1][sum_weight ^ wv[i].first] + wv[i].second);
}
// 選ばない場合はdpテーブルにおける上の行をそのまま引き継ぐ
chmax(dp[i][sum_weight], dp[i - 1][sum_weight]);
}
}
cout << dp[n][w] << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define per(i, n) for (ll i = ((ll)(n)) - 1; i >= 0; i--)
#define perf(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
ll n, w;
cin >> n >> w;
vvi dp(n + 1, vi(w + 1, 0));
vector<pair<ll, ll>> wv(n + 1);
repf(i, n) cin >> wv[i].first >> wv[i].second;
for (ll i = 1; i <= n; i++) {
for (ll sum_weight = 0; sum_weight <= w; sum_weight++) {
if (sum_weight - wv[i].first >= 0) {
// i番目の商品を品物を持ち帰れる場合、ギリギリの容量が空いている場合の最大価値+i番目の品物の価値
chmax(dp[i][sum_weight],
dp[i - 1][sum_weight - wv[i].first] + wv[i].second);
}
// 選ばない場合はdpテーブルにおける上の行をそのまま引き継ぐ
chmax(dp[i][sum_weight], dp[i - 1][sum_weight]);
}
}
cout << dp[n][w] << endl;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,527 | 965,526 | u548791035 | cpp |
p03163 | ///=======================///
/// coder: Andy - Tohrumi ///
///=======================///
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio \
ios_base::sync_with_stdio(); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for (__typeof(a) i = a; i > b; i--)
using namespace std;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<pll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vl;
///======code start here======///
signed main() {
fastio;
int N, W;
cin >> N >> W;
int w[N], v[N];
rep(i, 0, N) { cin >> w[i] >> v[i]; }
int dp[N + 1][W + 1];
rep(i, 0, N + 1) {
rep(j, 0, W + 1) { dp[i][j] = 0; }
}
rep(i, 1, N + 1) {
rep(j, 1, W + 1) {
if (j >= w[i - 1])
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[N][W] << endl;
return 0;
}
| ///=======================///
/// coder: Andy - Tohrumi ///
///=======================///
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio \
ios_base::sync_with_stdio(); \
cin.tie(0); \
cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for (__typeof(a) i = a; i > b; i--)
using namespace std;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<pll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vl;
///======code start here======///
signed main() {
fastio;
int N, W;
cin >> N >> W;
int w[N], v[N];
rep(i, 0, N) { cin >> w[i] >> v[i]; }
ll dp[N + 1][W + 1];
rep(i, 0, N + 1) {
rep(j, 0, W + 1) { dp[i][j] = 0; }
}
rep(i, 1, N + 1) {
rep(j, 1, W + 1) {
if (j >= w[i - 1])
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[N][W] << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 965,528 | 965,529 | u340424586 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
void rwf() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int N = 105, mxW = 1e5 + 5;
int n, W, w[N], v[N];
int dp[N][mxW];
int solve(int wr, int m) {
if (m == 0 || wr == 0)
return 0;
if (dp[m][wr] != -1)
return dp[m][wr];
if (wr - w[m] < 0)
return dp[m][wr] = solve(wr, m - 1);
return dp[m][wr] = max(solve(wr, m - 1), v[m] + solve(wr - w[m], m - 1));
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
rwf();
cin >> n >> W;
memset(&dp, -1, sizeof(dp));
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
int ans = solve(W, n);
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
void rwf() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int N = 105, mxW = 1e5 + 5;
int n, W, w[N], v[N];
int dp[N][mxW];
int solve(int wr, int m) {
if (m == 0 || wr == 0)
return 0;
if (dp[m][wr] != -1)
return dp[m][wr];
if (wr - w[m] < 0)
return dp[m][wr] = solve(wr, m - 1);
return dp[m][wr] = max(solve(wr, m - 1), v[m] + solve(wr - w[m], m - 1));
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// rwf();
cin >> n >> W;
memset(&dp, -1, sizeof(dp));
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
int ans = solve(W, n);
cout << ans;
return 0;
} | [
"call.remove"
] | 965,541 | 965,542 | u870088166 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
vector<long long> p;
vector<long long> val;
long long W;
long long n;
int knapSack() {
long long DP[n + 1][W + 1];
for (int i = 0; i <= n; i++) {
for (int i1 = 0; i1 <= W; i1++) {
if (i == 0 || i1 == 0) {
DP[i][i1] = 0;
} else {
if (p[i - 1] <= i1) {
DP[i][i1] = max(val[i - 1] + DP[i - 1][i1 - p[i - 1]], DP[i - 1][i1]);
} else {
DP[i][i1] = DP[i - 1][i1];
}
}
}
}
return DP[n][W];
}
int main() {
cin >> n >> W;
val.resize(n);
p.resize(n);
for (int i = 0; i < n; i++) {
cin >> p[i] >> val[i];
}
cout << knapSack() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<long long> p;
vector<long long> val;
long long W;
long long n;
long long knapSack() {
long long DP[n + 1][W + 1];
for (int i = 0; i <= n; i++) {
for (int i1 = 0; i1 <= W; i1++) {
if (i == 0 || i1 == 0) {
DP[i][i1] = 0;
} else {
if (p[i - 1] <= i1) {
DP[i][i1] = max(val[i - 1] + DP[i - 1][i1 - p[i - 1]], DP[i - 1][i1]);
} else {
DP[i][i1] = DP[i - 1][i1];
}
}
}
}
return DP[n][W];
}
int main() {
cin >> n >> W;
val.resize(n);
p.resize(n);
for (int i = 0; i < n; i++) {
cin >> p[i] >> val[i];
}
cout << knapSack() << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,543 | 965,544 | u365691497 | cpp |
p03163 |
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin >> x
#define print(x) cout << x
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define reset(d, val) memset(d, val, sizeof(d))
#define sort(v) sort(v.begin(), v.end())
#define sort_arr(arr, i, f) sort(arr + i, arr + f)
#define pq priority_queue<int, vector<int>, greater<int>>
#define pq1 priority_queue<pll, vector<pll>, greater<pll>>
const int mod = 1e9 + 7;
int n;
ll w, wt[101], val[101], sm = 100000;
ll dp[100001];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> w;
dp[0] = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
for (int j = w; j >= 0; j--) {
if (j - wt[i] >= 0)
dp[j] = min(dp[j], dp[j - wt[i]] + val[i]);
}
}
ll ans = 0;
for (ll i = 0; i <= w; ++i) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin >> x
#define print(x) cout << x
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define reset(d, val) memset(d, val, sizeof(d))
#define sort(v) sort(v.begin(), v.end())
#define sort_arr(arr, i, f) sort(arr + i, arr + f)
#define pq priority_queue<int, vector<int>, greater<int>>
#define pq1 priority_queue<pll, vector<pll>, greater<pll>>
const int mod = 1e9 + 7;
int n;
ll w, wt[101], val[101], sm = 100000;
ll dp[100001];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> w;
dp[0] = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
for (int j = w; j >= 0; j--) {
if (j - wt[i] >= 0)
dp[j] = max(dp[j], dp[j - wt[i]] + val[i]);
}
}
ll ans = 0;
for (ll i = 0; i <= w; ++i) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 965,547 | 965,548 | u925841581 | cpp |
p03163 |
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin >> x
#define print(x) cout << x
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define reset(d, val) memset(d, val, sizeof(d))
#define sort(v) sort(v.begin(), v.end())
#define sort_arr(arr, i, f) sort(arr + i, arr + f)
#define pq priority_queue<int, vector<int>, greater<int>>
#define pq1 priority_queue<pll, vector<pll>, greater<pll>>
const int mod = 1e9 + 7;
int n;
ll w, wt[101], val[101], sm = 100000;
ll dp[100001];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> w;
dp[0] = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
for (int j = sm; j >= 0; j--) {
if (j - wt[i] >= 0)
dp[j] = min(dp[j], dp[j - wt[i]] + val[i]);
}
}
ll ans = 0;
for (ll i = 0; i <= w; ++i) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin >> x
#define print(x) cout << x
#define pii pair<int, int>
#define pll pair<ll, ll>
#define gcd(a, b) __gcd(a, b)
#define reset(d, val) memset(d, val, sizeof(d))
#define sort(v) sort(v.begin(), v.end())
#define sort_arr(arr, i, f) sort(arr + i, arr + f)
#define pq priority_queue<int, vector<int>, greater<int>>
#define pq1 priority_queue<pll, vector<pll>, greater<pll>>
const int mod = 1e9 + 7;
int n;
ll w, wt[101], val[101], sm = 100000;
ll dp[100001];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> w;
dp[0] = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
for (int j = w; j >= 0; j--) {
if (j - wt[i] >= 0)
dp[j] = max(dp[j], dp[j - wt[i]] + val[i]);
}
}
ll ans = 0;
for (ll i = 0; i <= w; ++i) {
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
| [
"variable_declaration.value.change",
"identifier.change",
"control_flow.loop.for.initializer.change",
"misc.opposites",
"assignment.value.change",
"call.function.change"
] | 965,549 | 965,548 | u925841581 | cpp |
p03163 |
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
// cin.ignore(); must be there when using getline(cin, s)
ll n, w;
cin >> n >> w;
ll wt[n];
ll v[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(dp[i][j - wt[i - 1]] + v[i - 1], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w];
return 0;
}
|
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define f first
#define s second
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
// cin.ignore(); must be there when using getline(cin, s)
ll n, w;
cin >> n >> w;
ll wt[n];
ll v[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + v[i - 1], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w];
return 0;
}
| [
"assignment.change"
] | 965,552 | 965,553 | u918403704 | cpp |
p03163 | #include <bits/stdc++.h>
//#define int long long
typedef long long ll;
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define fori(i, l, r) fore(i, l, (r) + 1)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
const double PI = atan(1) * 4;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool isprime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const int mod = 998244353;
bool comp(pair<int, int> a, pair<int, int> b) { return b.ff < a.ff; }
ll pw(ll b, ll e) {
ll ans = 1;
while (e) {
if (e & 1)
ans = (ans * b) % mod;
b = (b * b) % mod;
e >>= 1;
}
return ans;
}
ll fact[200002], inv[200002];
ll C(ll n, ll k) { return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod); }
/*void bsearch(int max,int min) // for function
//void bsearch(int a,int n, int x) // for array
{
int k=min;
// for array
/* for(int b=n/2; b>=1; b/=2)
{
while(k+b<n && arr[k+b]<=x) k+=b;
}
if(arr[k]==x)
cout<<"found at "<<k+1;
else
cout<<"not found";
*/
// for function
/* for(int b=max; b>=1; b/=2)
{
while( !fn(b+k) ) k+=b;
}
cout<<k+1;
}*/
int vis[200005];
int main() {
int t = 1;
// cin>>t;
while (t--) {
int n, W;
cin >> n >> W;
int w[n], v[n];
forn(i, n) { cin >> w[i] >> v[i]; }
int dp[n + 1][W + 1];
fori(i, 0, n) dp[i][0] = 0;
fori(i, 0, W) dp[0][i] = 0;
fori(i, 1, n) {
fori(j, 1, W) {
if (w[i - 1] <= j) {
dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][W];
}
return 0;
} | #include <bits/stdc++.h>
//#define int long long
typedef long long ll;
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define forn(i, n) fore(i, 0, n)
#define fori(i, l, r) fore(i, l, (r) + 1)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
const double PI = atan(1) * 4;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
bool isprime(int n) {
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const int mod = 998244353;
bool comp(pair<int, int> a, pair<int, int> b) { return b.ff < a.ff; }
ll pw(ll b, ll e) {
ll ans = 1;
while (e) {
if (e & 1)
ans = (ans * b) % mod;
b = (b * b) % mod;
e >>= 1;
}
return ans;
}
ll fact[200002], inv[200002];
ll C(ll n, ll k) { return ((((fact[n] * inv[k]) % mod) * inv[n - k]) % mod); }
/*void bsearch(int max,int min) // for function
//void bsearch(int a,int n, int x) // for array
{
int k=min;
// for array
/* for(int b=n/2; b>=1; b/=2)
{
while(k+b<n && arr[k+b]<=x) k+=b;
}
if(arr[k]==x)
cout<<"found at "<<k+1;
else
cout<<"not found";
*/
// for function
/* for(int b=max; b>=1; b/=2)
{
while( !fn(b+k) ) k+=b;
}
cout<<k+1;
}*/
int vis[200005];
int main() {
int t = 1;
// cin>>t;
while (t--) {
int n, W;
cin >> n >> W;
int w[n], v[n];
forn(i, n) { cin >> w[i] >> v[i]; }
ll dp[n + 1][W + 1];
fori(i, 0, n) dp[i][0] = 0;
fori(i, 0, W) dp[0][i] = 0;
fori(i, 1, n) {
fori(j, 1, W) {
if (w[i - 1] <= j) {
dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][W];
}
return 0;
} | [
"variable_declaration.type.change"
] | 965,554 | 965,555 | u412316386 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int KnapSack(int W, vector<int> val, vector<int> wt, int n) {
vector<vector<int>> K(n + 1, vector<int>(W + 1));
for (int i = 0; i <= n; i++) {
for (int w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, Cap;
cin >> n >> Cap;
vector<int> Values(n);
vector<int> Weights(n);
for (int i = 0; i < n; i++) {
cin >> Weights[i] >> Values[i];
}
cout << KnapSack(Cap, Values, Weights, n) << endl;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
int KnapSack(int W, vector<int> val, vector<int> wt, int n) {
vector<vector<int>> K(n + 1, vector<int>(W + 1));
for (int i = 0; i <= n; i++) {
for (int w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
signed main() {
int n, Cap;
cin >> n >> Cap;
vector<int> Values(n);
vector<int> Weights(n);
for (int i = 0; i < n; i++) {
cin >> Weights[i] >> Values[i];
}
cout << KnapSack(Cap, Values, Weights, n) << endl;
}
| [
"variable_declaration.type.primitive.change"
] | 965,565 | 965,566 | u405337522 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int knapSackRec(int W, int wt[], int val[], int i, int **dp) {
if (i < 0)
return 0;
if (dp[i][W] != -1)
return dp[i][W];
if (wt[i] > W) {
// Store the value of function call
// stack in table before return
dp[i][W] = knapSackRec(W, wt, val, i - 1, dp);
return dp[i][W];
} else {
// Store value in a table before return
dp[i][W] = max(val[i] + knapSackRec(W - wt[i], wt, val, i - 1, dp),
knapSackRec(W, wt, val, i - 1, dp));
// Return value of table after storing
return dp[i][W];
}
}
int knapSack(int W, int wt[], int val[], int n) {
// double pointer to declare the
// table dynamically
int **dp;
dp = new int *[n];
// loop to create the table dynamically
for (int i = 0; i < n; i++)
dp[i] = new int[W + 1];
// loop to initially filled the
// table with -1
for (int i = 0; i < n; i++)
for (int j = 0; j < W + 1; j++)
dp[i][j] = -1;
return knapSackRec(W, wt, val, n - 1, dp);
}
int main() {
int n, W;
cin >> n >> W;
int wt[n], val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
cout << knapSack(W, wt, val, n);
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
int knapSackRec(int W, int wt[], int val[], int i, int **dp) {
if (i < 0)
return 0;
if (dp[i][W] != -1)
return dp[i][W];
if (wt[i] > W) {
// Store the value of function call
// stack in table before return
dp[i][W] = knapSackRec(W, wt, val, i - 1, dp);
return dp[i][W];
} else {
// Store value in a table before return
dp[i][W] = max(val[i] + knapSackRec(W - wt[i], wt, val, i - 1, dp),
knapSackRec(W, wt, val, i - 1, dp));
// Return value of table after storing
return dp[i][W];
}
}
int knapSack(int W, int wt[], int val[], int n) {
// double pointer to declare the
// table dynamically
int **dp;
dp = new int *[n];
// loop to create the table dynamically
for (int i = 0; i < n; i++)
dp[i] = new int[W + 1];
// loop to initially filled the
// table with -1
for (int i = 0; i < n; i++)
for (int j = 0; j < W + 1; j++)
dp[i][j] = -1;
return knapSackRec(W, wt, val, n - 1, dp);
}
signed main() {
int n, W;
cin >> n >> W;
int wt[n], val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
cout << knapSack(W, wt, val, n);
return 0;
} | [
"variable_declaration.type.primitive.change"
] | 965,567 | 965,568 | u405337522 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
vector<long long int> dp(W + 1, 0);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = W; j >= 0; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
vector<long long int> dp(W + 1, 0);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 965,569 | 965,570 | u558282734 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
int dp[100001];
for (int i = 0; i <= W; i++)
dp[i] = 0;
for (int i = 0; i < N; i++) {
int w, v;
cin >> w >> v;
for (int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << dp[W] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
long long dp[100001];
for (int i = 0; i <= W; i++)
dp[i] = 0;
for (int i = 0; i < N; i++) {
int w, v;
cin >> w >> v;
for (int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << dp[W] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,571 | 965,572 | u929569377 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod = 1e9 + 7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#include <string>
string char_to_str(char c) {
string tem(1, c);
return tem;
}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a < b) {
return a;
}
return b;
}
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
int main() {
fastio;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll n, W;
cin >> n >> W;
ll a[n + 1][W + 1];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= W; ++j) {
a[i][j] = 0;
}
}
for (int i = 1; i <= n; ++i) {
ll w, v;
cin >> w >> v;
for (int j = 1; j <= W; ++j) {
a[i][j] = a[i - 1][j];
if (j - w >= 0) {
a[i][j] = max(a[i][j], a[i - 1][j - w] + v);
}
}
}
int an = 0;
for (int i = 0; i <= W; ++i) {
an = max(a[n][i], an);
}
cout << an;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
ll mod = 1e9 + 7;
#define PI 3.1415926535897932385
#define INF 100000000000000000ll
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#include <string>
string char_to_str(char c) {
string tem(1, c);
return tem;
}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a, ll b) {
if (a > b) {
return a;
}
return b;
}
ll min(ll a, ll b) {
if (a < b) {
return a;
}
return b;
}
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output
int main() {
fastio;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ll n, W;
cin >> n >> W;
ll a[n + 1][W + 1];
for (ll i = 0; i <= n; ++i) {
for (ll j = 0; j <= W; ++j) {
a[i][j] = 0;
}
}
for (ll i = 1; i <= n; ++i) {
ll w, v;
cin >> w >> v;
for (ll j = 1; j <= W; ++j) {
a[i][j] = a[i - 1][j];
if (j - w >= 0) {
a[i][j] = max(a[i][j], a[i - 1][j - w] + v);
}
}
}
ll an = 0;
for (ll i = 0; i <= W; ++i) {
an = max(a[n][i], an);
}
cout << an;
return 0;
} | [
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change"
] | 965,580 | 965,581 | u268750247 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
/*long maxValue(int n, int w, vector<int>& weight, vector<int>& value, int i) {
if (w <= 0 or i == n) return 0;
cout << w << endl;
if (w-weight[i] < 0) return maxValue (n, w, weight, value, i+1);
return (long) max ((long) value[i] + maxValue (n, w-weight[i], weight,
value, i+1), maxValue (n, w, weight, value, i+1));
}*/
int main() {
int n;
cin >> n;
int W;
cin >> W;
vector<int> weight(n), value(n);
for (int i = 0; i < n; ++i)
cin >> weight[i] >> value[i];
/*long sum = maxValue(n, W, weight, value, 0);
cout << sum;*/
int i, w;
int K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (weight[i - 1] <= w)
K[i][w] = max(value[i - 1] + K[i - 1][w - weight[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
cout << K[n][W];
} | #include <bits/stdc++.h>
using namespace std;
/*long maxValue(int n, int w, vector<int>& weight, vector<int>& value, int i) {
if (w <= 0 or i == n) return 0;
cout << w << endl;
if (w-weight[i] < 0) return maxValue (n, w, weight, value, i+1);
return (long) max ((long) value[i] + maxValue (n, w-weight[i], weight,
value, i+1), maxValue (n, w, weight, value, i+1));
}*/
int main() {
long n;
cin >> n;
long W;
cin >> W;
vector<long> weight(n), value(n);
for (long i = 0; i < n; ++i)
cin >> weight[i] >> value[i];
/*long sum = maxValue(n, W, weight, value, 0);
cout << sum;*/
long i, w;
long K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (weight[i - 1] <= w)
K[i][w] = max(value[i - 1] + K[i - 1][w - weight[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
cout << K[n][W];
} | [
"variable_declaration.type.primitive.change",
"control_flow.loop.for.initializer.change"
] | 965,586 | 965,587 | u275673917 | cpp |
p03163 | /*
Author : Simanta Deb Turja
*/
#include <bits/stdc++.h>
using namespace std;
#define Professor
using ll = long long;
using i64 = unsigned long long;
template <typename T> inline T Min(T a, T b, T c) { return min(a, min(b, c)); }
template <typename T> inline T Min(T a, T b, T c, T d) {
return min(a, min(b, min(c, d)));
}
template <typename T> inline T Max(T a, T b, T c) { return max(a, max(b, c)); }
template <typename T> inline T Max(T a, T b, T c, T d) {
return max(a, max(b, max(c, d)));
}
template <typename T> inline T Ceil(T a, T b) {
return ((a % b == 0) ? (a / b) : (a / b + 1));
}
template <typename T> inline T Floor(T a, T b) { return a / b; }
template <typename T> inline T Power(T a, T p) {
T res = 1, x = a;
while (p) {
if (p & 1)
res = (res * x);
x = (x * x);
p >>= 1;
}
return res;
}
template <typename T> inline T BigMod(T a, T p, T M) {
a %= M;
T ret = 1;
while (p) {
if (p & 1)
ret = (ret * a) % M;
a = (a * a) % M;
p = p >> 1;
}
return ret;
}
template <typename T> inline T InverseMod(T a, T M) {
return BigMod(a, M - 2, M);
}
template <typename T> inline T gcd(T a, T b) {
a = abs(a);
b = abs(b);
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <typename T> inline T lcm(T x, T y) {
return (((x) / gcd((x), (y))) * (y));
}
#define endl '\n'
#define eb emplace_back
const int N = (int)4e5 + 10;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const ll LLINF = (ll)1e18 + 1;
const int INF = (int)1e9 + 1;
const ll MOD = (ll)1e9 + 7;
template <typename T> bool cmp(const pair<T, T> &a, const pair<T, T> &b) {
return a.first < b.first;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
auto Solve = [&]() {
#ifdef __APPLE__
cout << "Running\n";
#endif
int n, W;
cin >> n >> W;
vector<ll> w(n), v(n);
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n, vector<ll>(W));
vector<vector<bool>> vis(n, vector<bool>(W, 0));
function<ll(int, int)> memo = [&](int pos, int cap) {
if (pos == n) {
return 0LL;
}
if (vis[pos][cap] != 0) {
return dp[pos][cap];
}
vis[pos][cap] = 1;
ll ret = -LLINF;
if (cap - w[pos] >= 0) {
ret = max(ret, memo(pos + 1, cap - w[pos]) + v[pos]);
}
ret = max(ret, memo(pos + 1, cap));
return dp[pos][cap] = ret;
};
cout << memo(0, W) << endl;
};
Solve();
return 0;
}
| /*
Author : Simanta Deb Turja
*/
#include <bits/stdc++.h>
using namespace std;
#define Professor
using ll = long long;
using i64 = unsigned long long;
template <typename T> inline T Min(T a, T b, T c) { return min(a, min(b, c)); }
template <typename T> inline T Min(T a, T b, T c, T d) {
return min(a, min(b, min(c, d)));
}
template <typename T> inline T Max(T a, T b, T c) { return max(a, max(b, c)); }
template <typename T> inline T Max(T a, T b, T c, T d) {
return max(a, max(b, max(c, d)));
}
template <typename T> inline T Ceil(T a, T b) {
return ((a % b == 0) ? (a / b) : (a / b + 1));
}
template <typename T> inline T Floor(T a, T b) { return a / b; }
template <typename T> inline T Power(T a, T p) {
T res = 1, x = a;
while (p) {
if (p & 1)
res = (res * x);
x = (x * x);
p >>= 1;
}
return res;
}
template <typename T> inline T BigMod(T a, T p, T M) {
a %= M;
T ret = 1;
while (p) {
if (p & 1)
ret = (ret * a) % M;
a = (a * a) % M;
p = p >> 1;
}
return ret;
}
template <typename T> inline T InverseMod(T a, T M) {
return BigMod(a, M - 2, M);
}
template <typename T> inline T gcd(T a, T b) {
a = abs(a);
b = abs(b);
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <typename T> inline T lcm(T x, T y) {
return (((x) / gcd((x), (y))) * (y));
}
#define endl '\n'
#define eb emplace_back
const int N = (int)4e5 + 10;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const ll LLINF = (ll)1e18 + 1;
const int INF = (int)1e9 + 1;
const ll MOD = (ll)1e9 + 7;
template <typename T> bool cmp(const pair<T, T> &a, const pair<T, T> &b) {
return a.first < b.first;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
auto Solve = [&]() {
#ifdef __APPLE__
cout << "Running\n";
#endif
int n, W;
cin >> n >> W;
vector<ll> w(n), v(n);
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n, vector<ll>(W + 1));
vector<vector<bool>> vis(n, vector<bool>(W + 1, false));
function<ll(int, int)> memo = [&](int pos, int cap) {
if (pos == n) {
return 0LL;
}
if (vis[pos][cap] != 0) {
return dp[pos][cap];
}
vis[pos][cap] = 1;
ll ret = -LLINF;
if (cap - w[pos] >= 0) {
ret = max(ret, memo(pos + 1, cap - w[pos]) + v[pos]);
}
ret = max(ret, memo(pos + 1, cap));
return dp[pos][cap] = ret;
};
cout << memo(0, W) << endl;
};
Solve();
return 0;
}
| [
"call.arguments.change"
] | 965,590 | 965,591 | u095814925 | cpp |
p03163 | #include <bits/stdc++.h>
/* imp functions
ARRAYS AND STRINGS
sorting arrays - sort(array,array+n);
sorting string - sort(s.begin() , s.end())
finding size of string - str.length();
VECTORS:
assign() – It assigns new value to the vector elements by replacing old
ones push_back() – It push the elements into a vector from the back pop_back() –
It is used to pop or remove elements from a vector from the back. insert() – It
inserts new elements before the element at the specified position
erase(v.begin()+i) – It is used to remove elements from a container from
the specified position or range. swap() – It is used to swap the contents of one
vector with another vector of same type. Sizes may differ. clear() – It is used
to remove all the elements of the vector container emplace() – It extends the
container by inserting new element at position emplace_back() – It is used to
insert a new element into the vector container, the new element is added to the
end of the vector v.reverse(v.begin(),v.end()) - reversing vector v.size() -
finding size of vector v.sort(v.begin(),v.end()) - sorting vectors
find(v.begin() , v.end() , element) - finding element in given vector in
order n lower_bound(v.begin() , v.end() , element) - returns pointer pointing to
element equal to or greater than the given element upper_bound(v.begin()
,v.end() , element) -returns pointer pointing to element greater than the given
element SETS: begin() – Returns an iterator to the first element in the set.
end() – Returns an iterator to the theoretical element that follows last
element in the set. size() – Returns the number of elements in the set.
max_size() – Returns the maximum number of elements that the set can
hold. empty() – Returns whether the set is empty. set.erase(iterator pointing to
the element) - ersases the element present at the required index // for finding
iterator: auto it = s.find(element) set.find(element) - returns iterator
pointing to the given element if it is present else return pointer pointing to
set.end() set.lower_bound(element) - return iterator pointing to element greater
than or equal to the given element set.upper_bound(element) - return iterator
pointing to element greater than the given element MULTISETS: same as sets, the
only difference is that it can contain duplicate elements and can sort elements
as per requirement multiset<ll,greater<ll>> set1; multiset<ll,less<ll>> set2;
DEQUE:
deque.push_front(element)
deque.push_back(element)
deque.pop_back()
deque.pop_front
MAPS:
map.insert() – Insert elements with a particular key in the map container.
(eg - map.insert({key,element}) or map[key] = element map.count() – Returns 1 if
the key is present else returns 0 map.erase()– Used to erase element from the
container. map.find() –Returns an iterator to the element with key value ‘g’ in
the map if found, else returns the iterator to end. map.emplace(key , element)–
Inserts the key and its element in the map container. map.upper_bound()– Returns
an iterator to the first element that is equivalent to mapped value with key
value ‘g’ or definitely will go after the element with key value ‘g’ in the map
map.lower_bound()– Returns an iterator to the first element that is
equivalent to mapped value with key value ‘g’ or definitely will not go before
the element with key value ‘g’ in the map map.size() – Returns the number of
elements in the map map.begin() and end()– begin() returns an iterator to the
first element in the map. end() returns an iterator to the theoretical element
that follows last element in the map map.clear()– Removes all the elements from
the map. map.at()– at() function is used to return the reference to the element
associated with the key k. map.swap() function is used to exchange the contents
of two maps but the maps must be of same type, although sizes may differ.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
/* Properties of modulo:Fermat's little theorem
(a/b)%m ,where m is prime = (a%m) * (b^(m-2))%m
*/
using namespace std;
#define IOS \
{ \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0); \
}
#define ll long long
#define pb push_back
#define gcd __gcd
// sorting in reverse order
bool compare(ll x, ll y) { return x > y; }
// checking whether a number is prime or not
ll isprime(ll n) {
if (n == 1)
return 0;
else if (n == 2)
return 1;
else {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return 0;
}
return 1;
}
}
// returning vector containing all prime numbers less than a given number
vector<ll> get_prime_factors_less_than(ll n) {
vector<ll> factor;
vector<ll> prime(n, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i <= n; i++) {
if (prime[i] == 1) {
for (ll j = i * i; j <= n; j = j + i)
prime[j] = 0;
factor.push_back(i);
}
}
return factor;
}
// returning vector containing index refering to elements of normal array after
// sorting it
vector<ll> retain_index(ll arr[], ll n) {
vector<pair<ll, ll>> vp;
for (ll i = 0; i < n; ++i) {
vp.push_back(make_pair(arr[i], i));
}
sort(vp.begin(), vp.end());
vector<ll> retain;
for (ll i = 0; i < vp.size(); i++) {
ll a = vp[i].second;
retain.pb(a);
}
return retain;
}
// returns x^y in order logn
ll power(ll x, ll y) {
if (y == 0)
return 1;
ll a = power(x, y / 2);
if (y % 2 == 0)
return a * a;
else
return x * a * a;
}
int main() {
IOS;
ll test, i;
test = 1;
// cin>>test;
while (test--) {
ll n, w;
cin >> n >> w;
ll wt[n], v[n];
for (ll i = 0; i <= n; i++)
cin >> wt[i] >> v[i];
ll dp[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][w] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
}
}
| #include <bits/stdc++.h>
/* imp functions
ARRAYS AND STRINGS
sorting arrays - sort(array,array+n);
sorting string - sort(s.begin() , s.end())
finding size of string - str.length();
VECTORS:
assign() – It assigns new value to the vector elements by replacing old
ones push_back() – It push the elements into a vector from the back pop_back() –
It is used to pop or remove elements from a vector from the back. insert() – It
inserts new elements before the element at the specified position
erase(v.begin()+i) – It is used to remove elements from a container from
the specified position or range. swap() – It is used to swap the contents of one
vector with another vector of same type. Sizes may differ. clear() – It is used
to remove all the elements of the vector container emplace() – It extends the
container by inserting new element at position emplace_back() – It is used to
insert a new element into the vector container, the new element is added to the
end of the vector v.reverse(v.begin(),v.end()) - reversing vector v.size() -
finding size of vector v.sort(v.begin(),v.end()) - sorting vectors
find(v.begin() , v.end() , element) - finding element in given vector in
order n lower_bound(v.begin() , v.end() , element) - returns pointer pointing to
element equal to or greater than the given element upper_bound(v.begin()
,v.end() , element) -returns pointer pointing to element greater than the given
element SETS: begin() – Returns an iterator to the first element in the set.
end() – Returns an iterator to the theoretical element that follows last
element in the set. size() – Returns the number of elements in the set.
max_size() – Returns the maximum number of elements that the set can
hold. empty() – Returns whether the set is empty. set.erase(iterator pointing to
the element) - ersases the element present at the required index // for finding
iterator: auto it = s.find(element) set.find(element) - returns iterator
pointing to the given element if it is present else return pointer pointing to
set.end() set.lower_bound(element) - return iterator pointing to element greater
than or equal to the given element set.upper_bound(element) - return iterator
pointing to element greater than the given element MULTISETS: same as sets, the
only difference is that it can contain duplicate elements and can sort elements
as per requirement multiset<ll,greater<ll>> set1; multiset<ll,less<ll>> set2;
DEQUE:
deque.push_front(element)
deque.push_back(element)
deque.pop_back()
deque.pop_front
MAPS:
map.insert() – Insert elements with a particular key in the map container.
(eg - map.insert({key,element}) or map[key] = element map.count() – Returns 1 if
the key is present else returns 0 map.erase()– Used to erase element from the
container. map.find() –Returns an iterator to the element with key value ‘g’ in
the map if found, else returns the iterator to end. map.emplace(key , element)–
Inserts the key and its element in the map container. map.upper_bound()– Returns
an iterator to the first element that is equivalent to mapped value with key
value ‘g’ or definitely will go after the element with key value ‘g’ in the map
map.lower_bound()– Returns an iterator to the first element that is
equivalent to mapped value with key value ‘g’ or definitely will not go before
the element with key value ‘g’ in the map map.size() – Returns the number of
elements in the map map.begin() and end()– begin() returns an iterator to the
first element in the map. end() returns an iterator to the theoretical element
that follows last element in the map map.clear()– Removes all the elements from
the map. map.at()– at() function is used to return the reference to the element
associated with the key k. map.swap() function is used to exchange the contents
of two maps but the maps must be of same type, although sizes may differ.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
*/
/* Properties of modulo:Fermat's little theorem
(a/b)%m ,where m is prime = (a%m) * (b^(m-2))%m
*/
using namespace std;
#define IOS \
{ \
ios ::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0); \
}
#define ll long long
#define pb push_back
#define gcd __gcd
// sorting in reverse order
bool compare(ll x, ll y) { return x > y; }
// checking whether a number is prime or not
ll isprime(ll n) {
if (n == 1)
return 0;
else if (n == 2)
return 1;
else {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return 0;
}
return 1;
}
}
// returning vector containing all prime numbers less than a given number
vector<ll> get_prime_factors_less_than(ll n) {
vector<ll> factor;
vector<ll> prime(n, 1);
prime[0] = 0, prime[1] = 0;
for (ll i = 2; i <= n; i++) {
if (prime[i] == 1) {
for (ll j = i * i; j <= n; j = j + i)
prime[j] = 0;
factor.push_back(i);
}
}
return factor;
}
// returning vector containing index refering to elements of normal array after
// sorting it
vector<ll> retain_index(ll arr[], ll n) {
vector<pair<ll, ll>> vp;
for (ll i = 0; i < n; ++i) {
vp.push_back(make_pair(arr[i], i));
}
sort(vp.begin(), vp.end());
vector<ll> retain;
for (ll i = 0; i < vp.size(); i++) {
ll a = vp[i].second;
retain.pb(a);
}
return retain;
}
// returns x^y in order logn
ll power(ll x, ll y) {
if (y == 0)
return 1;
ll a = power(x, y / 2);
if (y % 2 == 0)
return a * a;
else
return x * a * a;
}
int main() {
IOS;
ll test, i;
test = 1;
// cin>>test;
while (test--) {
ll n, w;
cin >> n >> w;
ll wt[n], v[n];
for (ll i = 0; i <= n; i++)
cin >> wt[i] >> v[i];
ll dp[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
}
}
| [
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 965,596 | 965,597 | u483635716 | cpp |
p03163 | #include <bits/stdc++.h>
#include <cctype>
#define ll long long int
#define PB push_back
#define GO \
ll t; \
cin >> t; \
while (t--)
#define ALLR(x) x.rbegin(), x.rend()
#define PII pair<ll, ll>
#define VI vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define F first
#define S second
#define PI 3.141592653589793238
#define SZ(x) (ll) x.size()
#define hell2 998244353
#define hell9 1000000007
#define FO(i, a, b) for (i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define BS binary_search
#define MP make_pair
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
/*ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
ll fac[500000]={0};
ll done=1;
ll ncrModP(ll n, ll r, ll p)
{
if (r==0)
return 1;
fac[0] = 1;
if(n>done)
{for (ll i=done ; i<=n; i++)
fac[i] = (fac[i-1]*i)%p;}
done=max(done,n);
return (fac[n]* modInverse(fac[r], p) % p *
modInverse(fac[n-r], p) % p) % p;
}
/*ll ncrM(ll n, ll r, ll p)
{
if (r > n - r)
r = n - r;
ll C[r + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++) {
for (ll j = min(i, r); j > 0; j--)
C[j] = (C[j] + C[j - 1]) % p;
}
return C[r];
}
map<ll,ll>f;
ll done=2;
ll fib(ll k)
{
ll i;f[0]=1;f[1]=1;f[2]=2;
if(k<=done)return f[k];
for(i=done;i<=k;i++)f[i]=(f[i-1]%hell9+f[i-2]%hell9)%hell9;
done=k;
return f[k]%hell9;
}*/
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
fio ll n, w, i, a, b, j;
cin >> n >> w;
vector<pair<ll, ll>> v;
ll dp[n + 1][w + 1];
FO(i, 0, n) {
cin >> a >> b;
v.PB({a, b});
}
for (i = 0; i <= n; i++) {
for (j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
dp[i][j] = dp[i - 1][j];
if (j - v[i - 1].F > 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i - 1].F] + v[i - 1].S);
}
}
}
}
cout << dp[n][w];
return 0;
} | #include <bits/stdc++.h>
#include <cctype>
#define ll long long int
#define PB push_back
#define GO \
ll t; \
cin >> t; \
while (t--)
#define ALLR(x) x.rbegin(), x.rend()
#define PII pair<ll, ll>
#define VI vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define F first
#define S second
#define PI 3.141592653589793238
#define SZ(x) (ll) x.size()
#define hell2 998244353
#define hell9 1000000007
#define FO(i, a, b) for (i = a; i < b; i++)
#define lbnd lower_bound
#define ubnd upper_bound
#define BS binary_search
#define MP make_pair
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
/*ll power(ll x, ll y, ll p)
{
ll res = 1;
x = x % p;
while (y > 0)
{
if (y & 1)
res = (res*x) % p;
y = y>>1;
x = (x*x) % p;
}
return res;
}
ll modInverse(ll n, ll p)
{
return power(n, p-2, p);
}
ll fac[500000]={0};
ll done=1;
ll ncrModP(ll n, ll r, ll p)
{
if (r==0)
return 1;
fac[0] = 1;
if(n>done)
{for (ll i=done ; i<=n; i++)
fac[i] = (fac[i-1]*i)%p;}
done=max(done,n);
return (fac[n]* modInverse(fac[r], p) % p *
modInverse(fac[n-r], p) % p) % p;
}
/*ll ncrM(ll n, ll r, ll p)
{
if (r > n - r)
r = n - r;
ll C[r + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (ll i = 1; i <= n; i++) {
for (ll j = min(i, r); j > 0; j--)
C[j] = (C[j] + C[j - 1]) % p;
}
return C[r];
}
map<ll,ll>f;
ll done=2;
ll fib(ll k)
{
ll i;f[0]=1;f[1]=1;f[2]=2;
if(k<=done)return f[k];
for(i=done;i<=k;i++)f[i]=(f[i-1]%hell9+f[i-2]%hell9)%hell9;
done=k;
return f[k]%hell9;
}*/
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
fio ll n, w, i, a, b, j;
cin >> n >> w;
vector<pair<ll, ll>> v;
ll dp[n + 1][w + 1];
FO(i, 0, n) {
cin >> a >> b;
v.PB({a, b});
}
for (i = 0; i <= n; i++) {
for (j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
dp[i][j] = dp[i - 1][j];
if (j - v[i - 1].F >= 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i - 1].F] + v[i - 1].S);
}
}
}
}
cout << dp[n][w];
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 965,598 | 965,599 | u232917796 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, w;
cin >> n >> w;
int val[n + 1];
int wg[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wg[i] >> val[i];
}
val[0] = 0;
wg[0] = 0;
int dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (j == 0 || i == 0) {
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j];
if (j - wg[i] >= 0)
dp[i][j] = max(dp[i][j], (dp[i - 1][(j - wg[i])] + val[i]));
}
}
cout << dp[n][w] << endl;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(void) {
int n, w;
cin >> n >> w;
int val[n + 1];
int wg[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wg[i] >> val[i];
}
val[0] = 0;
wg[0] = 0;
int dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (j == 0 || i == 0) {
dp[i][j] = 0;
continue;
}
dp[i][j] = dp[i - 1][j];
if (j - wg[i] >= 0)
dp[i][j] = max(dp[i][j], (dp[i - 1][(j - wg[i])] + val[i]));
}
}
cout << dp[n][w] << endl;
} | [
"variable_declaration.type.primitive.change"
] | 965,612 | 965,613 | u043140820 | cpp |
p03163 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (ll(i) = 0; i < (ll)(n); ++(i))
#define INF 10e12
#define MOD 1000000000 + 7
#define MX 51000
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
using namespace std;
struct nap {
ll w;
ll v;
};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, W;
cin >> N >> W;
vector<ll> w(N);
vector<ll> v(N);
for (ll i = 0; i < N; ++i) {
ll a, b;
cin >> a >> b;
w[i] = a;
v[i] = b;
}
vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
rep(i, W + 1) dp[0][i] = 0;
rep(i, N) {
rep(j, W + 1) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
cout << dp[N][W] << endl;
}
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
typedef long long ll;
#define rep(i, n) for (ll(i) = 0; i < (ll)(n); ++(i))
#define INF 10e12
#define MOD 1000000000 + 7
#define MX 51000
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
using namespace std;
struct nap {
ll w;
ll v;
};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, W;
cin >> N >> W;
vector<ll> w(N);
vector<ll> v(N);
for (ll i = 0; i < N; ++i) {
ll a, b;
cin >> a >> b;
w[i] = a;
v[i] = b;
}
vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
rep(i, W + 1) dp[0][i] = 0;
rep(i, N) {
rep(j, W + 1) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W] << endl;
}
| [] | 965,616 | 965,617 | u110044127 | cpp |
p03163 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void dk() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int knapsack(int a[], int val[], int n, int k) {
int dp[k + 1][n + 1];
for (int i = 0; i <= n; i++) {
dp[0][i] = 0;
}
for (int i = 0; i <= k; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
if (a[j - 1] <= i) {
dp[i][j] = max(dp[i][j - 1], dp[i - a[j - 1]][j - 1] + val[j - 1]);
} else {
dp[i][j] = dp[i][j - 1];
}
// cout << dp[i][j] << " ";
}
// cout << endl;
}
return dp[k][n];
}
int32_t main() {
dk();
int n, k;
cin >> n >> k;
int val[n], a[n];
for (int i = 0; i < n; i++) {
cin >> a[i] >> val[i];
}
int m = knapsack(a, val, n, k);
cout << m;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void dk() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int knapsack(int a[], int val[], int n, int k) {
int dp[k + 1][n + 1];
for (int i = 0; i <= n; i++) {
dp[0][i] = 0;
}
for (int i = 0; i <= k; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
if (a[j - 1] <= i) {
dp[i][j] = max(dp[i][j - 1], dp[i - a[j - 1]][j - 1] + val[j - 1]);
} else {
dp[i][j] = dp[i][j - 1];
}
// cout << dp[i][j] << " ";
}
// cout << endl;
}
return dp[k][n];
}
int32_t main() {
// dk();
int n, k;
cin >> n >> k;
int val[n], a[n];
for (int i = 0; i < n; i++) {
cin >> a[i] >> val[i];
}
int m = knapsack(a, val, n, k);
cout << m;
return 0;
} | [
"call.remove"
] | 965,623 | 965,624 | u752344870 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define pi pair<ll, ll>
#define map map<ll, ll>
#define set set<ll>
const int m = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, w;
cin >> n >> w;
int weight[n], value[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
int dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j >= weight[i - 1])
dp[i][j] =
max(dp[i - 1][j], value[i - 1] + dp[i - 1][j - weight[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define f first
#define sec second
#define pb push_back
#define pf push_front
#define pbb pop_back
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define pi pair<ll, ll>
#define map map<ll, ll>
#define set set<ll>
const int m = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, w;
cin >> n >> w;
ll weight[100005], value[100005];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
ll dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j >= weight[i - 1])
dp[i][j] =
max(dp[i - 1][j], value[i - 1] + dp[i - 1][j - weight[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
}
| [
"variable_declaration.type.change",
"identifier.replace.remove",
"literal.replace.add",
"variable_declaration.array_dimensions.change"
] | 965,625 | 965,626 | u675040086 | cpp |
p03163 |
using namespace std;
#include <bits/stdc++.h>
int max(int a, int b) { return (a > b) ? a : b; }
int knapSack(int W, int wt[], int val[], int n) {
int i, w;
int K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
int val[n], wt[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << (knapSack(w, wt, val, n));
return 0;
}
|
using namespace std;
#include <bits/stdc++.h>
long long int max(int a, int b) { return (a > b) ? a : b; }
long long int knapSack(int W, int wt[], int val[], int n) {
int i, w;
long long int K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
int val[n], wt[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << (knapSack(w, wt, val, n));
return 0;
}
| [
"variable_declaration.type.widen.change"
] | 965,627 | 965,628 | u581698586 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
return (sum_3(j) - sum_3(i - 1) + M) % M;
}
/* clang-format off */
namespace myDebug {
template <class T> auto is_printable(T *v) -> decltype(cout << *v, 0);
template <class T> char is_printable(...);
template <class T> struct range{T begin, end;};
class Debug {
class DebugImpl {
public:
~DebugImpl() { cout << endl; }
#define enable_cond(cmp) enable_if<sizeof(is_printable<T>(nullptr)) cmp 1, DebugImpl &>::type
template <class T> typename enable_cond(!=) operator<<(const T v) {
cout << v; return *this;
}
template <class T> typename enable_cond(==) operator<<(const T v) {
return *this << range<decltype(begin(v))>({begin(v), end(v)});
}
template <class T, class U> DebugImpl& operator<<(const pair<T, U> p) {
return *this << "(" << p.first << ", " << p.second << ")";
}
template <class T> DebugImpl& operator<<(const range<T> v) {
for (auto it = v.begin; it != v.end; ++it) {
*this << *it << " ";
}
return *this << "\n";
}
#ifdef enable_cond
#undef enable_cond
#endif
} os;
public:
#ifdef D_LOCAL
template<class T> Debug& operator<<(const T v) {
os << v; cout << endl; return *this;
}
#else
template <class T> Debug& operator<<(const T &) { return *this; }
#endif
};
#define px(...) #__VA_ARGS__":" << (__VA_ARGS__)
}; // namespace myDebug
/* clang-format on */
myDebug::Debug debug;
ll pow_f(ll b, ll e, ll M = ::M) {
ll ans = 1;
b = b % M;
while (e) {
if (e & 1) {
ans = (ans * b) % M;
}
b = (b * b) % M;
e >>= 1;
}
return ans;
}
ll nCr(ll n, ll r) {
if (r > n || n < 0 || r < 0) {
return 0;
}
if (n == r || r == 0) {
return 1;
}
r = min(r, n - r);
ll ans = 1;
for (ll i = 1; i <= r; ++i) {
ans = (ans * (n - i + 1)) / (i);
}
return ans;
}
ll nCr(tuple<ll, ll> t) {
auto n = get<0>(t);
auto k = get<1>(t);
return nCr(n + k - 1, k);
}
ll modinv(ll x, ll M = ::M) { return pow_f(x, M - 2, M); }
void solve() {
ll n, w;
cin >> n >> w;
vector<pair<ll, ll>> obj;
obj.resize(n);
for (auto &i : obj) {
cin >> i.first >> i.second;
}
vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));
for (int i = 0; i <= w; ++i)
dp[0][i] = 0;
for (int i = 0; i <= n; ++i)
dp[i][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= w; ++j) {
dp[i][j] = -1;
if (w - obj[i - 1].first >= 0)
dp[i][j] =
max(dp[i][j], obj[i - 1].second + dp[i - 1][j - obj[i - 1].first]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
cout << dp[n][w] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef D_LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
return (sum_3(j) - sum_3(i - 1) + M) % M;
}
/* clang-format off */
namespace myDebug {
template <class T> auto is_printable(T *v) -> decltype(cout << *v, 0);
template <class T> char is_printable(...);
template <class T> struct range{T begin, end;};
class Debug {
class DebugImpl {
public:
~DebugImpl() { cout << endl; }
#define enable_cond(cmp) enable_if<sizeof(is_printable<T>(nullptr)) cmp 1, DebugImpl &>::type
template <class T> typename enable_cond(!=) operator<<(const T v) {
cout << v; return *this;
}
template <class T> typename enable_cond(==) operator<<(const T v) {
return *this << range<decltype(begin(v))>({begin(v), end(v)});
}
template <class T, class U> DebugImpl& operator<<(const pair<T, U> p) {
return *this << "(" << p.first << ", " << p.second << ")";
}
template <class T> DebugImpl& operator<<(const range<T> v) {
for (auto it = v.begin; it != v.end; ++it) {
*this << *it << " ";
}
return *this << "\n";
}
#ifdef enable_cond
#undef enable_cond
#endif
} os;
public:
#ifdef D_LOCAL
template<class T> Debug& operator<<(const T v) {
os << v; cout << endl; return *this;
}
#else
template <class T> Debug& operator<<(const T &) { return *this; }
#endif
};
#define px(...) #__VA_ARGS__":" << (__VA_ARGS__)
}; // namespace myDebug
/* clang-format on */
myDebug::Debug debug;
ll pow_f(ll b, ll e, ll M = ::M) {
ll ans = 1;
b = b % M;
while (e) {
if (e & 1) {
ans = (ans * b) % M;
}
b = (b * b) % M;
e >>= 1;
}
return ans;
}
ll nCr(ll n, ll r) {
if (r > n || n < 0 || r < 0) {
return 0;
}
if (n == r || r == 0) {
return 1;
}
r = min(r, n - r);
ll ans = 1;
for (ll i = 1; i <= r; ++i) {
ans = (ans * (n - i + 1)) / (i);
}
return ans;
}
ll nCr(tuple<ll, ll> t) {
auto n = get<0>(t);
auto k = get<1>(t);
return nCr(n + k - 1, k);
}
ll modinv(ll x, ll M = ::M) { return pow_f(x, M - 2, M); }
void solve() {
ll n, w;
cin >> n >> w;
vector<pair<ll, ll>> obj;
obj.resize(n);
for (auto &i : obj) {
cin >> i.first >> i.second;
}
vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
for (int i = 0; i <= w; ++i)
dp[0][i] = 0;
for (int i = 0; i <= n; ++i)
dp[i][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= w; ++j) {
dp[i][j] = -1;
if (j - obj[i - 1].first >= 0)
dp[i][j] =
max(dp[i][j], obj[i - 1].second + dp[i - 1][j - obj[i - 1].first]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
cout << dp[n][w] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef D_LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
solve();
return 0;
}
| [
"call.arguments.add",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 965,629 | 965,630 | u878592875 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
return (sum_3(j) - sum_3(i - 1) + M) % M;
}
/* clang-format off */
namespace myDebug {
template <class T> auto is_printable(T *v) -> decltype(cout << *v, 0);
template <class T> char is_printable(...);
template <class T> struct range{T begin, end;};
class Debug {
class DebugImpl {
public:
~DebugImpl() { cout << endl; }
#define enable_cond(cmp) enable_if<sizeof(is_printable<T>(nullptr)) cmp 1, DebugImpl &>::type
template <class T> typename enable_cond(!=) operator<<(const T v) {
cout << v; return *this;
}
template <class T> typename enable_cond(==) operator<<(const T v) {
return *this << range<decltype(begin(v))>({begin(v), end(v)});
}
template <class T, class U> DebugImpl& operator<<(const pair<T, U> p) {
return *this << "(" << p.first << ", " << p.second << ")";
}
template <class T> DebugImpl& operator<<(const range<T> v) {
for (auto it = v.begin; it != v.end; ++it) {
*this << *it << " ";
}
return *this << "\n";
}
#ifdef enable_cond
#undef enable_cond
#endif
} os;
public:
#ifdef D_LOCAL
template<class T> Debug& operator<<(const T v) {
os << v; cout << endl; return *this;
}
#else
template <class T> Debug& operator<<(const T &) { return *this; }
#endif
};
#define px(...) #__VA_ARGS__":" << (__VA_ARGS__)
}; // namespace myDebug
/* clang-format on */
myDebug::Debug debug;
ll pow_f(ll b, ll e, ll M = ::M) {
ll ans = 1;
b = b % M;
while (e) {
if (e & 1) {
ans = (ans * b) % M;
}
b = (b * b) % M;
e >>= 1;
}
return ans;
}
ll nCr(ll n, ll r) {
if (r > n || n < 0 || r < 0) {
return 0;
}
if (n == r || r == 0) {
return 1;
}
r = min(r, n - r);
ll ans = 1;
for (ll i = 1; i <= r; ++i) {
ans = (ans * (n - i + 1)) / (i);
}
return ans;
}
ll nCr(tuple<ll, ll> t) {
auto n = get<0>(t);
auto k = get<1>(t);
return nCr(n + k - 1, k);
}
ll modinv(ll x, ll M = ::M) { return pow_f(x, M - 2, M); }
void solve() {
ll n, w;
cin >> n >> w;
vector<pair<ll, ll>> obj;
obj.resize(n);
for (auto &i : obj) {
cin >> i.first >> i.second;
}
vector<vector<ll>> dp(n + 1, vector<ll>(w + 1));
for (int i = 0; i <= w; ++i)
dp[0][i] = 0;
for (int i = 0; i <= n; ++i)
dp[i][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= w; ++j) {
dp[i][j] = -1;
if (w - obj[i - 1].first >= 0)
dp[i][j] =
max(dp[i][j], obj[i - 1].second + dp[i - 1][j - obj[i - 1].first]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
cout << dp[n][w] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef D_LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) {
return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M;
}
inline ll sum_1(const ll i, const ll j) {
return (sum_1(j) - sum_1(i - 1) + M) % M;
}
inline ll sum_2(const ll i, const ll j) {
return (sum_2(j) - sum_2(i - 1) + M) % M;
}
inline ll sum_3(const ll i, const ll j) {
return (sum_3(j) - sum_3(i - 1) + M) % M;
}
/* clang-format off */
namespace myDebug {
template <class T> auto is_printable(T *v) -> decltype(cout << *v, 0);
template <class T> char is_printable(...);
template <class T> struct range{T begin, end;};
class Debug {
class DebugImpl {
public:
~DebugImpl() { cout << endl; }
#define enable_cond(cmp) enable_if<sizeof(is_printable<T>(nullptr)) cmp 1, DebugImpl &>::type
template <class T> typename enable_cond(!=) operator<<(const T v) {
cout << v; return *this;
}
template <class T> typename enable_cond(==) operator<<(const T v) {
return *this << range<decltype(begin(v))>({begin(v), end(v)});
}
template <class T, class U> DebugImpl& operator<<(const pair<T, U> p) {
return *this << "(" << p.first << ", " << p.second << ")";
}
template <class T> DebugImpl& operator<<(const range<T> v) {
for (auto it = v.begin; it != v.end; ++it) {
*this << *it << " ";
}
return *this << "\n";
}
#ifdef enable_cond
#undef enable_cond
#endif
} os;
public:
#ifdef D_LOCAL
template<class T> Debug& operator<<(const T v) {
os << v; cout << endl; return *this;
}
#else
template <class T> Debug& operator<<(const T &) { return *this; }
#endif
};
#define px(...) #__VA_ARGS__":" << (__VA_ARGS__)
}; // namespace myDebug
/* clang-format on */
myDebug::Debug debug;
ll pow_f(ll b, ll e, ll M = ::M) {
ll ans = 1;
b = b % M;
while (e) {
if (e & 1) {
ans = (ans * b) % M;
}
b = (b * b) % M;
e >>= 1;
}
return ans;
}
ll nCr(ll n, ll r) {
if (r > n || n < 0 || r < 0) {
return 0;
}
if (n == r || r == 0) {
return 1;
}
r = min(r, n - r);
ll ans = 1;
for (ll i = 1; i <= r; ++i) {
ans = (ans * (n - i + 1)) / (i);
}
return ans;
}
ll nCr(tuple<ll, ll> t) {
auto n = get<0>(t);
auto k = get<1>(t);
return nCr(n + k - 1, k);
}
ll modinv(ll x, ll M = ::M) { return pow_f(x, M - 2, M); }
void solve() {
ll n, w;
cin >> n >> w;
vector<pair<ll, ll>> obj;
obj.resize(n);
for (auto &i : obj) {
cin >> i.first >> i.second;
}
vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
for (int i = 0; i <= w; ++i)
dp[0][i] = 0;
for (int i = 0; i <= n; ++i)
dp[i][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= w; ++j) {
dp[i][j] = -1;
if (j - obj[i - 1].first >= 0)
dp[i][j] =
max(dp[i][j], obj[i - 1].second + dp[i - 1][j - obj[i - 1].first]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
cout << dp[n][w] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef D_LOCAL
freopen("in.in", "r", stdin);
freopen("out.out", "w", stdout);
#endif
solve();
return 0;
} | [
"call.arguments.add",
"identifier.change",
"control_flow.branch.if.condition.change"
] | 965,629 | 965,631 | u878592875 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n);
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> w.at(i) >> v.at(i);
}
vector<vector<int>> dp(n + 1, vector<int>(W + 1));
for (int j = 0; j <= W; j++) {
dp.at(0).at(j) = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w.at(i)) {
dp.at(i + 1).at(j) =
max(dp.at(i).at(j - w.at(i)) + v.at(i), dp.at(i).at(j));
} else {
dp.at(i + 1).at(j) = dp.at(i).at(j);
}
}
}
cout << dp.at(n).at(W) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n);
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> w.at(i) >> v.at(i);
}
vector<vector<long long int>> dp(n + 1, vector<long long int>(W + 1));
for (int j = 0; j <= W; j++) {
dp.at(0).at(j) = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w.at(i)) {
dp.at(i + 1).at(j) =
max(dp.at(i).at(j - w.at(i)) + v.at(i), dp.at(i).at(j));
} else {
dp.at(i + 1).at(j) = dp.at(i).at(j);
}
}
}
cout << dp.at(n).at(W) << endl;
}
| [
"variable_declaration.type.widen.change"
] | 965,632 | 965,633 | u607229598 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int knap[n][2];
for (int i = 0; i < n; i++)
for (int j = 0; j < 2; j++)
cin >> knap[i][j];
//入力
int dp[n + 1][w + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= w; j++)
dp[i][j] = 0;
// dp表
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (j >= knap[i - 1][0])
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - knap[i - 1][0]] + knap[i - 1][1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
long long knap[n][2];
for (int i = 0; i < n; i++)
for (int j = 0; j < 2; j++)
cin >> knap[i][j];
//入力
long long dp[n + 1][w + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= w; j++)
dp[i][j] = 0;
// dp表
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (j >= knap[i - 1][0])
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - knap[i - 1][0]] + knap[i - 1][1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,634 | 965,635 | u842028864 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define SZ(items) (int)items.size()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a) memset(a, -1, sizeof(a))
#define nl "\n";
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template <class T> inline T ison(T n, T pos) {
return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b) {
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <class T> inline T bigmod(T p, T e, T m) {
T ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % m;
p = (p * p) % m;
}
return (T)ret;
};
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " is " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " is " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
int dp[101][100005];
int n, tw;
vector<pair<long long, long long>> items;
long long recur(int pos, int w) {
if (pos == n) {
return 0;
}
if (dp[pos][w] != -1) {
return dp[pos][w];
}
long long mx = 0;
if (w + items[pos].first <= tw) {
mx = max(mx, items[pos].second + recur(pos + 1, w + items[pos].first));
}
mx = max(mx, recur(pos + 1, w));
return dp[pos][w] = mx;
}
void solve() {
SET(dp);
cin >> n >> tw;
items.resize(n);
for (int i = 0; i < n; i++) {
cin >> items[i].first >> items[i].second;
}
cout << recur(0, 0) << nl;
}
int main() {
ios_base::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
cout.tie(nullptr);
cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define SZ(items) (int)items.size()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a) memset(a, -1, sizeof(a))
#define nl "\n";
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template <class T> inline T ison(T n, T pos) {
return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b) {
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <class T> inline T bigmod(T p, T e, T m) {
T ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % m;
p = (p * p) % m;
}
return (T)ret;
};
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " is " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " is " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
long long dp[101][100005];
int n, tw;
vector<pair<long long, long long>> items;
long long recur(int pos, int w) {
if (pos == n) {
return 0;
}
if (dp[pos][w] != -1) {
return dp[pos][w];
}
long long mx = 0;
if (w + items[pos].first <= tw) {
mx = max(mx, items[pos].second + recur(pos + 1, w + items[pos].first));
}
mx = max(mx, recur(pos + 1, w));
return dp[pos][w] = mx;
}
void solve() {
SET(dp);
cin >> n >> tw;
items.resize(n);
for (int i = 0; i < n; i++) {
cin >> items[i].first >> items[i].second;
}
cout << recur(0, 0) << nl;
}
int main() {
ios_base::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
cout.tie(nullptr);
cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,641 | 965,642 | u098704227 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define SZ(items) (int)items.size()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a) memset(a, -1, sizeof(a))
#define nl "\n";
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template <class T> inline T ison(T n, T pos) {
return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b) {
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <class T> inline T bigmod(T p, T e, T m) {
T ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % m;
p = (p * p) % m;
}
return (T)ret;
};
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " is " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " is " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
int dp[101][10005];
int n, tw;
vector<pair<long long, long long>> items;
long long recur(int pos, int w) {
if (pos == n) {
return 0;
}
if (dp[pos][w] != -1) {
return dp[pos][w];
}
long long mx = 0;
if (w + items[pos].first <= tw) {
mx = max(mx, items[pos].second + recur(pos + 1, w + items[pos].first));
}
mx = max(mx, recur(pos + 1, w));
return dp[pos][w] = mx;
}
void solve() {
SET(dp);
cin >> n >> tw;
items.resize(n);
for (int i = 0; i < n; i++) {
cin >> items[i].first >> items[i].second;
}
cout << recur(0, 0) << nl;
}
int main() {
ios_base::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
cout.tie(nullptr);
cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define SZ(items) (int)items.size()
#define CLR(a) memset(a, 0, sizeof(a))
#define SET(a) memset(a, -1, sizeof(a))
#define nl "\n";
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); }
template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); }
template <class T> inline T ison(T n, T pos) {
return (bool)(n & ((T)1 << pos));
}
template <class T> inline T gcd(T a, T b) {
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <class T> inline T bigmod(T p, T e, T m) {
T ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1)
ret = (ret * p) % m;
p = (p * p) % m;
}
return (T)ret;
};
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " is " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " is " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
long long dp[101][100005];
int n, tw;
vector<pair<long long, long long>> items;
long long recur(int pos, int w) {
if (pos == n) {
return 0;
}
if (dp[pos][w] != -1) {
return dp[pos][w];
}
long long mx = 0;
if (w + items[pos].first <= tw) {
mx = max(mx, items[pos].second + recur(pos + 1, w + items[pos].first));
}
mx = max(mx, recur(pos + 1, w));
return dp[pos][w] = mx;
}
void solve() {
SET(dp);
cin >> n >> tw;
items.resize(n);
for (int i = 0; i < n; i++) {
cin >> items[i].first >> items[i].second;
}
cout << recur(0, 0) << nl;
}
int main() {
ios_base::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
cout.tie(nullptr);
cin.tie(nullptr);
int t = 1;
while (t--) {
solve();
}
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 965,643 | 965,642 | u098704227 | cpp |
p03163 | #include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
const int wmax = 1e5 + 5;
const int nmax = 1e2 + 5;
int weights[nmax];
int value[nmax];
int dp[wmax];
int main() {
std::ios_base::sync_with_stdio(false);
int N, W;
std::cin >> N >> W;
for (int i = 0; i < N; i++) {
std::cin >> weights[i] >> value[i];
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < N; i++) {
for (int j = W - weights[i]; ~j; j--) {
dp[j + weights[i]] = std::max(dp[j + weights[i]], dp[j] + value[i]);
}
}
// for (int i=0; i<=W; i++) std::cout << dp[i] << " ";
std::cout << dp[W];
return 0;
}
| #include <cmath>
#include <cstring>
#include <iostream>
#include <limits>
const int wmax = 1e5 + 5;
const int nmax = 1e2 + 5;
int weights[nmax];
long long value[nmax];
long long dp[wmax];
int main() {
std::ios_base::sync_with_stdio(false);
int N, W;
std::cin >> N >> W;
for (int i = 0; i < N; i++) {
std::cin >> weights[i] >> value[i];
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < N; i++) {
for (int j = W - weights[i]; ~j; j--) {
dp[j + weights[i]] = std::max(dp[j + weights[i]], dp[j] + value[i]);
}
}
// for (int i=0; i<=W; i++) std::cout << dp[i] << " ";
std::cout << dp[W];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,644 | 965,645 | u958610807 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int v[n + 1], w[n + 1];
int dp[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (w[i] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
cout << dp[n][k] << endl;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
long long int v[n + 1], w[n + 1];
long long int dp[n + 1][k + 1];
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (w[i] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
cout << dp[n][k] << endl;
}
| [
"variable_declaration.type.widen.change"
] | 965,646 | 965,647 | u842473278 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define debug(var) \
do { \
std::cout << #var << " : "; \
view(var); \
} while (0)
template <typename T> void view(T e) { std::cout << e << std::endl; }
template <typename T> void view(const std::vector<T> &v) {
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const int MOD = 1000000007;
const int INF = 1e9;
const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int main() {
int n, W;
cin >> n >> W;
vector<int> v(n), w(n);
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
int dp[W + 1];
fill(dp, dp + W + 1, 0);
for (int i = 0; i < n; i++)
for (int j = W; j >= 0; j--) {
if (j >= w[i])
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
cout << dp[W] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define debug(var) \
do { \
std::cout << #var << " : "; \
view(var); \
} while (0)
template <typename T> void view(T e) { std::cout << e << std::endl; }
template <typename T> void view(const std::vector<T> &v) {
for (const auto &e : v) {
std::cout << e << " ";
}
std::cout << std::endl;
}
template <typename T> void view(const std::vector<std::vector<T>> &vv) {
for (const auto &v : vv) {
view(v);
}
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
const int MOD = 1000000007;
const int INF = 1e9;
const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int main() {
int n, W;
cin >> n >> W;
vector<ll> v(n), w(n);
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
ll dp[W + 1];
fill(dp, dp + W + 1, 0);
for (int i = 0; i < n; i++)
for (int j = W; j >= 0; j--) {
if (j >= w[i])
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
cout << dp[W] << endl;
} | [
"variable_declaration.type.change"
] | 965,652 | 965,653 | u279033107 | cpp |
p03163 | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using namespace __gnu_pbds;
typedef tree< // find_by_order & order_of_key
int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
new_set;
#define MOD 1000000007
#define MAXN (int)(1e5 + 10000)
#define MAXW (int)(203)
long long dp[MAXN][MAXW];
array<pair<long long, long long>, MAXN> arr;
int main(void) {
#ifdef HELL_JUDGE
freopen("input", "r", stdin);
freopen("output", "w", stdout);
freopen("error", "w", stderr);
#endif
memset(dp, 0ll, sizeof(dp));
long long n, w;
cin >> n >> w;
for (int i = 1; i <= n; ++i) {
cin >> arr[i].first >> arr[i].second;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= w; ++j) {
if (arr[i].second <= j) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - arr[i].first] + arr[i].second);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << '\n';
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
using namespace __gnu_pbds;
typedef tree< // find_by_order & order_of_key
int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
new_set;
#define MOD 1000000007
#define MAXW (int)(1e5 + 10000)
#define MAXN (int)(203)
long long dp[MAXN][MAXW];
array<pair<long long, long long>, MAXN> arr;
int main(void) {
#ifdef HELL_JUDGE
freopen("input", "r", stdin);
freopen("output", "w", stdout);
freopen("error", "w", stderr);
#endif
memset(dp, 0ll, sizeof(dp));
long long n, w;
cin >> n >> w;
for (int i = 1; i <= n; ++i) {
cin >> arr[i].first >> arr[i].second;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= w; ++j) {
if (arr[i].first <= j) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - arr[i].first] + arr[i].second);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << '\n';
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 965,656 | 965,655 | u896543512 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, w;
cin >> n >> w;
int a[n + 1], wt[n + 1];
rep(i, 1, n + 1) cin >> wt[i] >> a[i];
int dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= w; i++) {
if (wt[j] > i) {
dp[j][i] = dp[j - 1][i];
} else
dp[j][i] = max(dp[j - 1][i], a[j] + dp[j - 1][i - wt[j]]);
// cout<<dp[j][i]<<" ";
}
// cout<<endl;
}
cout << dp[n][w];
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, w;
cin >> n >> w;
long long a[n + 1], wt[n + 1];
rep(i, 1, n + 1) cin >> wt[i] >> a[i];
long long dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= w; i++) {
if (wt[j] > i) {
dp[j][i] = dp[j - 1][i];
} else
dp[j][i] = max(dp[j - 1][i], a[j] + dp[j - 1][i - wt[j]]);
// cout<<dp[j][i]<<" ";
}
// cout<<endl;
}
cout << dp[n][w];
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,659 | 965,660 | u473179530 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Knapsack(ll *weights, ll *values, int w, int n) {
ll dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (weights[i - 1] <= j) {
dp[i][j] =
max(dp[i - 1][j], values[i - 1] + dp[i - 1][w - weights[i - 1]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
return dp[n][w];
}
int main() {
int n, w;
cin >> n >> w;
ll *weights = new ll[n];
ll *values = new ll[n];
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
}
ll answer = Knapsack(weights, values, w, n);
cout << answer << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll Knapsack(ll *weights, ll *values, int w, int n) {
ll dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (weights[i - 1] <= j) {
dp[i][j] =
max(dp[i - 1][j], values[i - 1] + dp[i - 1][j - weights[i - 1]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
return dp[n][w];
}
int main() {
int n, w;
cin >> n >> w;
ll *weights = new ll[n];
ll *values = new ll[n];
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
}
ll answer = Knapsack(weights, values, w, n);
cout << answer << "\n";
return 0;
} | [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,661 | 965,662 | u740301715 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define fora(i, a, b) for (int i = (a); i < (b); i++)
#define ford(i, n) for (int i = (n)-1; i >= 0; i--)
#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x " = " << x << endl)
#define watch_all(x) \
TRACE(cerr << #x " = "; for (auto __i : x) cerr << __i << " "; cerr << endl)
#define INF 0x3F3F3F3F
//=========================
// ============================
// Codigo Original
// ============================
int N, _W;
int W[101], V[101];
ll dp[101][100001];
void run_test() {
cin >> N >> _W;
for1(i, N) cin >> W[i] >> V[i];
ini(dp, 0);
for1(i, N) for (int w = 1; w <= _W; w++) if (W[i] > w) dp[i][w] =
dp[i - 1][w];
else dp[i][w] = max(dp[i][w], dp[i - 1][w - W[i]] + V[i]);
cout << dp[N][_W] << endl;
}
// ============================
// Otimizando Memoria
// Removendo uma dimensao da DP
// ============================
/*int N, _W;
int W[101], V[101];
ll dp[100001];
void run_test() {
cin >> N >> _W;
for1(i, N) cin >> W[i] >> V[i];
ini(dp, 0);
for1(i, N)
for(int w = _W; w >= W[i]; w--)
dp[w] = max(dp[w], dp[w - W[i]] + V[i]);
cout << dp[_W] << endl;
}*/
//=========================
ifstream infile;
clock_t start__;
void open_func();
void close_func();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
open_func();
// int t; cin >> t; while(t--) run_test();
run_test();
close_func();
return 0;
}
void open_func() {
// infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
start__ = clock();
cerr << "---" << endl;
}
void close_func() {
clock_t elapsed = clock() - start__;
cerr << "---" << endl
<< "(time " << fixed << setprecision(2)
<< elapsed * (1.0 / CLOCKS_PER_SEC) << "s)" << endl;
// if(infile.good()) infile.close();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define fora(i, a, b) for (int i = (a); i < (b); i++)
#define ford(i, n) for (int i = (n)-1; i >= 0; i--)
#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x " = " << x << endl)
#define watch_all(x) \
TRACE(cerr << #x " = "; for (auto __i : x) cerr << __i << " "; cerr << endl)
#define INF 0x3F3F3F3F
//=========================
// ============================
// Codigo Original
// ============================
int N, _W;
int W[101], V[101];
ll dp[101][100001];
void run_test() {
cin >> N >> _W;
for1(i, N) cin >> W[i] >> V[i];
ini(dp, 0);
for1(i, N) for (int w = 1; w <= _W; w++) if (W[i] > w) dp[i][w] =
dp[i - 1][w];
else dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - W[i]] + V[i]);
cout << dp[N][_W] << endl;
}
// ============================
// Otimizando Memoria
// Removendo uma dimensao da DP
// ============================
/*int N, _W;
int W[101], V[101];
ll dp[100001];
void run_test() {
cin >> N >> _W;
for1(i, N) cin >> W[i] >> V[i];
ini(dp, 0);
for1(i, N)
for(int w = _W; w >= W[i]; w--)
dp[w] = max(dp[w], dp[w - W[i]] + V[i]);
cout << dp[_W] << endl;
}*/
//=========================
ifstream infile;
clock_t start__;
void open_func();
void close_func();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
open_func();
// int t; cin >> t; while(t--) run_test();
run_test();
close_func();
return 0;
}
void open_func() {
// infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
start__ = clock();
cerr << "---" << endl;
}
void close_func() {
clock_t elapsed = clock() - start__;
cerr << "---" << endl
<< "(time " << fixed << setprecision(2)
<< elapsed * (1.0 / CLOCKS_PER_SEC) << "s)" << endl;
// if(infile.good()) infile.close();
}
| [
"assignment.change"
] | 965,663 | 965,664 | u373096848 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define fora(i, a, b) for (int i = (a); i < (b); i++)
#define ford(i, n) for (int i = (n)-1; i >= 0; i--)
#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x " = " << x << endl)
#define watch_all(x) \
TRACE(cerr << #x " = "; for (auto __i : x) cerr << __i << " "; cerr << endl)
#define INF 0x3F3F3F3F
//=========================
int N, _W;
int W[101], V[101];
int dp[101][100001];
void run_test() {
cin >> N >> _W;
for1(i, N) cin >> W[i] >> V[i];
for1(i, N) {
for1(w, _W) {
if (W[i] > w)
dp[i][w] = dp[i - 1][w];
else
dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - W[i]] + V[i]);
}
}
cout << dp[N][_W] << endl;
}
//=========================
ifstream infile;
clock_t start__;
void open_func();
void close_func();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
open_func();
// int t; cin >> t; while(t--) run_test();
run_test();
close_func();
return 0;
}
void open_func() {
// infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
start__ = clock();
cerr << "---" << endl;
}
void close_func() {
clock_t elapsed = clock() - start__;
cerr << "---" << endl
<< "(time " << fixed << setprecision(2)
<< elapsed * (1.0 / CLOCKS_PER_SEC) << "s)" << endl;
// if(infile.good()) infile.close();
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define present(i, c) ((c).find(i) != (c).end())
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define fora(i, a, b) for (int i = (a); i < (b); i++)
#define ford(i, n) for (int i = (n)-1; i >= 0; i--)
#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x " = " << x << endl)
#define watch_all(x) \
TRACE(cerr << #x " = "; for (auto __i : x) cerr << __i << " "; cerr << endl)
#define INF 0x3F3F3F3F
//=========================
int N, _W;
int W[101], V[101];
ll dp[101][100001];
void run_test() {
cin >> N >> _W;
for1(i, N) cin >> W[i] >> V[i];
for1(i, N) {
for1(w, _W) {
if (W[i] > w)
dp[i][w] = dp[i - 1][w];
else
dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - W[i]] + V[i]);
}
}
cout << dp[N][_W] << endl;
}
//=========================
ifstream infile;
clock_t start__;
void open_func();
void close_func();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
open_func();
// int t; cin >> t; while(t--) run_test();
run_test();
close_func();
return 0;
}
void open_func() {
// infile = ifstream("input.in"); if(infile.good()) cin.rdbuf(infile.rdbuf());
start__ = clock();
cerr << "---" << endl;
}
void close_func() {
clock_t elapsed = clock() - start__;
cerr << "---" << endl
<< "(time " << fixed << setprecision(2)
<< elapsed * (1.0 / CLOCKS_PER_SEC) << "s)" << endl;
// if(infile.good()) infile.close();
}
| [
"variable_declaration.type.change"
] | 965,665 | 965,666 | u373096848 | cpp |
p03163 | #include <bits/stdc++.h>
#define int long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int, int>
#define vi vector<int>
#define umapi unordered_map<int, int>
const int m = 998244353;
using namespace std;
void FIO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main() {
FIO();
int n, mx;
cin >> n >> mx;
int w[n], v[n], dp[mx + 1];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= mx; i++) {
dp[i] = -1;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = mx; j >= 0; j--) {
if (dp[j] != -1 && j + w[i] <= mx)
dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
}
}
int ret = dp[0];
for (int i = 0; i <= mx; i++) {
ret = max(ret, dp[i]);
}
cout << ret << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int, int>
#define vi vector<int>
#define umapi unordered_map<int, int>
const int m = 998244353;
using namespace std;
void FIO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main() {
// FIO();
int n, mx;
cin >> n >> mx;
int w[n], v[n], dp[mx + 1];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= mx; i++) {
dp[i] = -1;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = mx; j >= 0; j--) {
if (dp[j] != -1 && j + w[i] <= mx)
dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
}
}
int ret = dp[0];
for (int i = 0; i <= mx; i++) {
ret = max(ret, dp[i]);
}
cout << ret << "\n";
return 0;
}
| [
"call.remove"
] | 965,667 | 965,668 | u841140330 | cpp |
p03163 |
#include <iostream>
using namespace std;
#define ffor(i, a, b) for (int i = a; i < b; i++)
#define ll long long
int main() {
ll w, n;
cin >> n >> w;
ll wt[n], v[n];
ffor(i, 0, n) { cin >> wt[i] >> v[i]; }
ll dp[n + 1][w + 1];
ffor(i, 0, n + 1) {
ffor(j, 0, w + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (wt[i - 1] <= j) {
dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - wt[i - 1]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n - 1][w];
} |
#include <iostream>
using namespace std;
#define ffor(i, a, b) for (int i = a; i < b; i++)
#define ll long long
int main() {
ll w, n;
cin >> n >> w;
ll wt[n], v[n];
ffor(i, 0, n) { cin >> wt[i] >> v[i]; }
ll dp[n + 1][w + 1];
ffor(i, 0, n + 1) {
ffor(j, 0, w + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else if (wt[i - 1] <= j) {
dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - wt[i - 1]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w];
} | [
"expression.operation.binary.remove"
] | 965,669 | 965,670 | u476428694 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int knapSack(int W, int wt[], int val[], int n) {
int i, w;
int K[n + 1][W + 1];
// Build table K[][] in bottom up manner
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = std::max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
int weight[n], value[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
cout << knapSack(w, weight, value, n) << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long int knapSack(int W, int wt[], int val[], int n) {
int i, w;
long long int K[n + 1][W + 1];
// Build table K[][] in bottom up manner
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = std::max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
int weight[n], value[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
cout << knapSack(w, weight, value, n) << "\n";
return 0;
} | [
"variable_declaration.type.widen.change"
] | 965,671 | 965,672 | u472796082 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define f(i, x, y) for (int i = x; i < y; i++)
#define mp make_pair
#define F first
#define S second
#define N 100005
int main() {
int n, w;
cin >> n >> w;
int wt[n + 1], p[n + 1];
f(i, 1, n + 1) cin >> wt[i] >> p[i];
// cout<<"c1";
vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0));
f(i, 1, n + 1) {
f(j, 0, w + 1) {
if (j >= wt[i]) {
dp[i][j] = max(dp[i - 1][j - wt[i]] + p[i], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define f(i, x, y) for (int i = x; i < y; i++)
#define mp make_pair
#define F first
#define S second
#define N 100005
int main() {
int n, w;
cin >> n >> w;
int wt[n + 1], p[n + 1];
f(i, 1, n + 1) cin >> wt[i] >> p[i];
// cout<<"c1";
vector<vector<long long>> dp(n + 1, vector<long long>(w + 1, 0));
// if(wt[1]<=w)
// dp[1][wt[1]] = p[1];
f(i, 1, n + 1) {
f(j, 0, w + 1) {
if (j >= wt[i]) {
dp[i][j] = max(dp[i - 1][j - wt[i]] + p[i], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,673 | 965,674 | u440947888 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int t[101][100001];
int solve(int wt[], int val[], int n, int w) {
if (n == 0 || w == 0)
return 0;
if (t[n][w] != -1)
return t[n][w];
else {
if (wt[n - 1] <= w)
return t[n][w] = max(val[n - 1] + solve(wt, val, n - 1, w - wt[n - 1]),
solve(wt, val, n - 1, w));
else
return t[n][w] = solve(wt, val, n - 1, w);
}
}
int main() {
memset(t, -1, sizeof(t));
int n, w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
for (int i = 0; i < 102; i++)
for (int j = 0; j < 100002; j++) {
if (i == 0 || j == 0)
t[i][j] = 0;
}
cout << solve(wt, val, n, w) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long long int t[101][100001];
long long int solve(int wt[], int val[], int n, int w) {
if (n == 0 || w == 0)
return 0;
if (t[n][w] != -1)
return t[n][w];
else {
if (wt[n - 1] <= w)
return t[n][w] = max(val[n - 1] + solve(wt, val, n - 1, w - wt[n - 1]),
solve(wt, val, n - 1, w));
else
return t[n][w] = solve(wt, val, n - 1, w);
}
}
int main() {
memset(t, -1, sizeof(t));
int n, w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
for (int i = 0; i < 102; i++)
for (int j = 0; j < 100002; j++) {
if (i == 0 || j == 0)
t[i][j] = 0;
}
cout << solve(wt, val, n, w) << endl;
}
| [
"variable_declaration.type.widen.change"
] | 965,678 | 965,679 | u730945939 | cpp |
p03163 | #include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define F first
#define S second
using namespace std;
void data() {
#ifdef NURS
freopen("main.in", "r", stdin);
freopen("main.out", "w", stdout);
#endif
}
const int N = 1e5 + 100;
const int mod = 1e9 + 7;
int dp[N];
int main() {
data();
int n, w;
cin >> n >> w;
int a[n + 1], b[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
for (int j = w - a[i]; j >= 0; j--) {
dp[j + a[i]] = max(dp[j + a[i]], dp[j] + b[i]);
}
}
int mx = 0;
for (int i = 1; i <= w; i++) {
mx = max(mx, dp[i]);
}
cout << mx;
}
| #include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define F first
#define S second
using namespace std;
void data() {
#ifdef NURS
freopen("main.in", "r", stdin);
freopen("main.out", "w", stdout);
#endif
}
const int N = 1e5 + 100;
const int mod = 1e9 + 7;
ll dp[N];
int main() {
data();
int n, w;
cin >> n >> w;
int a[n + 1], b[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
for (int j = w - a[i]; j >= 0; j--) {
dp[j + a[i]] = max(dp[j + a[i]], dp[j] + b[i]);
}
}
ll mx = 0;
for (int i = 1; i <= w; i++) {
mx = max(mx, dp[i]);
}
cout << mx;
}
| [
"variable_declaration.type.change"
] | 965,680 | 965,681 | u165212329 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int n, W, i, j;
cin >> n >> W;
int wt[n];
int val[n];
for (i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
}
int dp[n + 1][W + 1];
for (i = 0; i <= W; i++)
dp[0][i] = 0;
for (i = 0; i <= n; i++)
dp[i][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= W; j++) {
if (j >= wt[i - 1]) {
dp[i][j] = max((dp[i - 1][j - wt[i - 1]] + val[i - 1]), dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W];
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll int n, W, i, j;
cin >> n >> W;
ll int wt[n];
ll int val[n];
for (i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
}
ll int dp[n + 1][W + 1];
for (i = 0; i <= W; i++)
dp[0][i] = 0;
for (i = 0; i <= n; i++)
dp[i][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= W; j++) {
if (j >= wt[i - 1]) {
dp[i][j] = max((dp[i - 1][j - wt[i - 1]] + val[i - 1]), dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W];
} | [] | 965,686 | 965,687 | u963181188 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int dp[105][100005];
int knapsack(int w[], int v[], int W, int n) {
if (W == 0 || n == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (w[n - 1] <= W) {
return dp[n][W] = max(v[n - 1] + knapsack(w, v, W - w[n - 1], n - 1),
knapsack(w, v, W, n - 1));
} else
return dp[n][W] = knapsack(w, v, W, n - 1);
}
int main() {
int n, W;
cin >> n >> W;
int w[n], v[n];
memset(dp, -1, sizeof dp);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(w, v, W, n) << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
long long dp[105][100005];
long long knapsack(int w[], int v[], int W, int n) {
if (W == 0 || n == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (w[n - 1] <= W) {
return dp[n][W] = max(v[n - 1] + knapsack(w, v, W - w[n - 1], n - 1),
knapsack(w, v, W, n - 1));
} else
return dp[n][W] = knapsack(w, v, W, n - 1);
}
int main() {
int n, W;
cin >> n >> W;
int w[n], v[n];
memset(dp, -1, sizeof dp);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(w, v, W, n) << '\n';
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,690 | 965,691 | u248069860 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int dp[100000 + 1];
int main() {
int n, weight;
cin >> n >> weight;
int w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
for (int j = weight; j >= w[i]; j--) {
if (j - w[i] >= 0)
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
else
dp[j] = dp[j];
}
}
cout << dp[weight] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100000 + 1];
int main() {
int n, weight;
cin >> n >> weight;
int w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
for (int j = weight; j >= w[i]; j--) {
if (j - w[i] >= 0)
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
else
dp[j] = dp[j];
}
}
cout << dp[weight] << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 965,692 | 965,693 | u500482384 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, w;
cin >> n >> w;
int wt[n], v[n];
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> v[i];
}
int k[n + 1][w + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
k[i][j] = 0;
else if (wt[i - 1] <= j) {
k[i][j] = max(v[i - 1] + k[i - 1][j - wt[i - 1]], k[i - 1][j]);
} else
k[i][j] = k[i - 1][j];
}
cout << k[n][w] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n, w;
cin >> n >> w;
int wt[n], v[n];
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> v[i];
}
long long k[n + 1][w + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
k[i][j] = 0;
else if (wt[i - 1] <= j) {
k[i][j] = max(v[i - 1] + k[i - 1][j - wt[i - 1]], k[i - 1][j]);
} else
k[i][j] = k[i - 1][j];
}
cout << k[n][w] << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,694 | 965,695 | u926681074 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, W;
scanf("%d%d", &n, &W);
vector<int> dp(W + 1, 0);
for (int item = 0; item < n; item++) {
int weight, value;
scanf("%d%d", &weight, &value);
for (int wa = W - weight; wa >= 0; wa--) {
dp[wa + weight] = max(dp[wa + weight], dp[wa] + value);
}
// cout<<dp[i]<<" ";
// cout<<endl;
}
int ans = 0;
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, W;
scanf("%d%d", &n, &W);
vector<long long int> dp(W + 1, 0);
for (int item = 0; item < n; item++) {
int weight, value;
scanf("%d%d", &weight, &value);
for (int wa = W - weight; wa >= 0; wa--) {
dp[wa + weight] = max(dp[wa + weight], dp[wa] + value);
}
// cout<<dp[i]<<" ";
// cout<<endl;
}
long long int ans = 0;
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
| [
"variable_declaration.type.widen.change"
] | 965,696 | 965,697 | u801369645 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 110;
const int MAXW = 1e5 + 10;
struct item {
int w, v;
};
item a[MAXN];
int N, W;
int dp[MAXW];
int main() {
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> a[i].w >> a[i].v;
}
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= N; i++) {
for (int j = W; j >= a[i].w; j--) {
dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
}
int ans = 0;
for (int j = 1; j <= W; j++) {
ans = max(ans, dp[j]);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 110;
const int MAXW = 1e5 + 10;
struct item {
int w, v;
};
item a[MAXN];
int N, W;
ll dp[MAXW];
int main() {
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> a[i].w >> a[i].v;
}
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= N; i++) {
for (int j = W; j >= a[i].w; j--) {
dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
}
ll ans = 0;
for (int j = 1; j <= W; j++) {
ans = max(ans, dp[j]);
}
cout << ans << endl;
return 0;
} | [
"variable_declaration.type.change"
] | 965,698 | 965,699 | u309591719 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define tc \
int T; \
cin >> T; \
while (T--)
const int INF = 1e9 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, W;
cin >> n >> W;
vector<vector<int>> a(n, vector<int>(2));
vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));
for (auto &e : a)
for (auto &d : e)
cin >> d;
for (int i = 0; i < W + 1; ++i) {
dp[0][i] = 0;
}
for (int i = 0; i < n + 1; ++i) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= W; ++j) {
if (j >= a[i - 1][0])
dp[i][j] = max(dp[i - 1][j], a[i - 1][1] + dp[i - 1][j - a[i - 1][0]]);
else
dp[i][j] = dp[i - 1][j];
}
cout << dp[n][W];
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define tc \
int T; \
cin >> T; \
while (T--)
const int INF = 1e9 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, W;
cin >> n >> W;
vector<vector<int>> a(n, vector<int>(2));
vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, 0ll));
for (auto &e : a)
for (auto &d : e)
cin >> d;
for (int i = 0; i < W + 1; ++i) {
dp[0][i] = 0;
}
for (int i = 0; i < n + 1; ++i) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= W; ++j) {
if (j >= a[i - 1][0])
dp[i][j] =
max(dp[i - 1][j], a[i - 1][1] + dp[i - 1][j - (a[i - 1][0])]);
else
dp[i][j] = dp[i - 1][j];
}
cout << dp[n][W];
return 0;
}
| [
"call.arguments.change"
] | 965,702 | 965,703 | u035574447 | cpp |
p03163 | // THINK FIRST CODE NEXT!!!!!!!!!!!!!!!!!
// It does not matter how slowly you go as long as you do not stop. - Confucius
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << ':' << x << endl;
#define loop3(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define loop(i, n) for (int i = 0; i < n; i++)
#define loop2(i, n) for (int i = 1; i <= n; i += 1)
#define pb push_back
#define mp make_pair
#define v1d vector<ll>
#define v2d vector<vector<ll>>
#define Sort(v) sort(v.begin(), v.end())
const int INF = 1e9 + 5;
#define ll long long
// #define mp make_pair
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 998244353
#define MOD (1000 * 1000 * 1000 + 7)
#define MN LLONG_MIN
#define MX LLONG_MAX
#define v1d vector<ll>
#define v2d vector<vector<ll>>
#define vip vector<pair<ll, ll>>
#define v1s vector<string>
#define pa pair<ll, ll>
#define mxpq(T) priority_queue<T>
#define mnpq(T) priority_queue<T, vector<T>, greater<T>>
#define print(v) \
for (auto i : v) \
cout << i << " "; \
cout << endl;
#define p2d(v) \
for (auto a : v) { \
for (auto b : a) \
cout << b << " "; \
cout << endl; \
}
#define p1d(v) \
for (auto a : v) \
cout << a << " "; \
cout << endl;
#define ppd(v) \
for (auto a : v) \
cout << a.ff << " " << a.ss << endl;
#define input(b, n) \
for (int i = 0; i < n; i++) \
cin >> b[i];
#define Sort(v) sort(v.begin(), v.end())
#define RSort(v) sort(v.rbegin(), v.rend())
#define all(v) v.begin(), v.end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// string s = bitset<64>(a).to_string();
// recursion solution
ll fun1(v1d wt, v1d val, ll W, ll n) {
if (W == 0 || n == 0)
return 0;
if (wt[n - 1] <= W) {
return max(val[n - 1] + fun1(wt, val, W - wt[n - 1], n - 1),
fun1(wt, val, W, n - 1));
}
return fun1(wt, val, W, n - 1);
}
// memoization solution
ll fun2(v1d wt, v1d val, ll W, ll n, v2d dp) {
if (W == 0 || n == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W) {
return dp[n][W] = max(val[n - 1] + fun2(wt, val, W - wt[n - 1], n - 1, dp),
fun2(wt, val, W, n - 1, dp));
}
return fun2(wt, val, W, n - 1, dp);
}
// tabular method
ll fun3(v1d wt, v1d val, ll W) {
ll n = wt.size();
v2d dp(n + 1, v1d(W + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
/*if(i == 0 || j == 0)
{
continue;
}*/
if (wt[i - 1] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]);
}
}
}
return dp[n][W];
}
int main() {
ll n, W;
cin >> n >> W;
v1d wt(n), val(n);
loop(i, n) { cin >> wt[i] >> val[i]; }
// int ans = fun1(wt,val,W,n);
v2d dp(n + 1, v1d(W + 1, -1));
// int ans1 = fun2(wt,val,W,n,dp);
// cout<<ans1<<" ";
ll ans3 = fun3(wt, val, W);
deb(ans3);
// deb(ans1);
return 0;
} | // THINK FIRST CODE NEXT!!!!!!!!!!!!!!!!!
// It does not matter how slowly you go as long as you do not stop. - Confucius
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << ':' << x << endl;
#define loop3(i, k, n) for (i = k; i < n; i++)
#define ll long long
#define loop(i, n) for (int i = 0; i < n; i++)
#define loop2(i, n) for (int i = 1; i <= n; i += 1)
#define pb push_back
#define mp make_pair
#define v1d vector<ll>
#define v2d vector<vector<ll>>
#define Sort(v) sort(v.begin(), v.end())
const int INF = 1e9 + 5;
#define ll long long
// #define mp make_pair
#define eb emplace_back
#define pb push_back
#define ss second
#define ff first
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 998244353
#define MOD (1000 * 1000 * 1000 + 7)
#define MN LLONG_MIN
#define MX LLONG_MAX
#define v1d vector<ll>
#define v2d vector<vector<ll>>
#define vip vector<pair<ll, ll>>
#define v1s vector<string>
#define pa pair<ll, ll>
#define mxpq(T) priority_queue<T>
#define mnpq(T) priority_queue<T, vector<T>, greater<T>>
#define print(v) \
for (auto i : v) \
cout << i << " "; \
cout << endl;
#define p2d(v) \
for (auto a : v) { \
for (auto b : a) \
cout << b << " "; \
cout << endl; \
}
#define p1d(v) \
for (auto a : v) \
cout << a << " "; \
cout << endl;
#define ppd(v) \
for (auto a : v) \
cout << a.ff << " " << a.ss << endl;
#define input(b, n) \
for (int i = 0; i < n; i++) \
cin >> b[i];
#define Sort(v) sort(v.begin(), v.end())
#define RSort(v) sort(v.rbegin(), v.rend())
#define all(v) v.begin(), v.end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// string s = bitset<64>(a).to_string();
// recursion solution
ll fun1(v1d wt, v1d val, ll W, ll n) {
if (W == 0 || n == 0)
return 0;
if (wt[n - 1] <= W) {
return max(val[n - 1] + fun1(wt, val, W - wt[n - 1], n - 1),
fun1(wt, val, W, n - 1));
}
return fun1(wt, val, W, n - 1);
}
// memoization solution
ll fun2(v1d wt, v1d val, ll W, ll n, v2d dp) {
if (W == 0 || n == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W) {
return dp[n][W] = max(val[n - 1] + fun2(wt, val, W - wt[n - 1], n - 1, dp),
fun2(wt, val, W, n - 1, dp));
}
return fun2(wt, val, W, n - 1, dp);
}
// tabular method
ll fun3(v1d wt, v1d val, ll W) {
ll n = wt.size();
v2d dp(n + 1, v1d(W + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
/*if(i == 0 || j == 0)
{
continue;
}*/
if (wt[i - 1] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]);
}
}
}
return dp[n][W];
}
int main() {
ll n, W;
cin >> n >> W;
v1d wt(n), val(n);
loop(i, n) { cin >> wt[i] >> val[i]; }
// int ans = fun1(wt,val,W,n);
v2d dp(n + 1, v1d(W + 1, -1));
// int ans1 = fun2(wt,val,W,n,dp);
// cout<<ans1<<" ";
ll ans3 = fun3(wt, val, W);
// deb(ans3);
cout << ans3;
// deb(ans1);
return 0;
} | [
"call.arguments.change"
] | 965,712 | 965,713 | u958825287 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
int wt[N + 1], val[N + 1];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
int dp[N + 1][W + 1];
for (int i = 0; i <= N; i++) {
for (int w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (wt[i - 1] <= w) {
dp[i][w] = val[i - 1] + dp[i - 1][w - wt[i - 1]];
dp[i][w] = max(dp[i][w], dp[i - 1][w]);
} else
dp[i][w] = dp[i - 1][w];
}
}
cout << dp[N][W];
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
int wt[N + 1], val[N + 1];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
long long dp[N + 1][W + 1];
for (int i = 0; i <= N; i++) {
for (int w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (wt[i - 1] <= w) {
dp[i][w] = val[i - 1] + dp[i - 1][w - wt[i - 1]];
dp[i][w] = max(dp[i][w], dp[i - 1][w]);
} else
dp[i][w] = dp[i - 1][w];
}
}
cout << dp[N][W];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,714 | 965,715 | u601589675 | cpp |
p03163 | #include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define forr(i, k, n) for (int i = k; i < n; i++)
#define iforr(i, k, n) for (int i = n - 1; i >= k; i--)
#define rep(i, n) forr(i, 0, n)
#define irep(i, n) iforr(i, 0, n)
#define aut(i, arr) for (auto &i : arr)
#define all(arr) arr.begin(), arr.end()
#define pb push_back
#define pii pair<int, int>
#define vpii vector<pii>
#define f first
#define db double
#define s second
#define ll long long
#define ull unsigned long long
#define E '\n'
#define lmax 9223372036854775807;
#define MOD 1000000007
using namespace std;
vi v;
vvi ed;
void dfs(int i) {
v[i] = 1;
aut(j, ed[i]) if (!v[j]) dfs(j);
}
void Fast_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("code.in", "r", stdin);
freopen("code.out", "w", stdout);
#endif
}
int main() {
Fast_IO();
int t;
// cin>>t;
t = 1;
while (t--) {
int n;
cin >> n;
int k;
cin >> k;
vi arr(n);
vi ar(n);
rep(i, n) {
cin >> arr[i];
cin >> ar[i];
}
vector<vector<ll>> dp(2, vector<ll>(k + 1, -1));
dp[0][0] = 0;
int flg = 1;
forr(i, 1, n + 1) {
dp[flg][0] = 0;
forr(j, 1, k + 1) {
dp[flg][j] = dp[flg ^ 1][j];
if (arr[i - 1] <= j)
if (dp[flg ^ 1][j - arr[i - 1]] >= 0)
dp[flg][j] =
max(dp[flg][j], ar[i - 1] + dp[flg ^ 1][j - arr[i - 1]]);
}
flg ^= 1;
}
ll ans = -1;
rep(i, k + 1) ans = max(ans, dp[flg ^ 1][i]);
cout << ans;
cout << E;
}
return 0;
} | #include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vi>
#define forr(i, k, n) for (int i = k; i < n; i++)
#define iforr(i, k, n) for (int i = n - 1; i >= k; i--)
#define rep(i, n) forr(i, 0, n)
#define irep(i, n) iforr(i, 0, n)
#define aut(i, arr) for (auto &i : arr)
#define all(arr) arr.begin(), arr.end()
#define pb push_back
#define pii pair<int, int>
#define vpii vector<pii>
#define f first
#define db double
#define s second
#define ll long long
#define ull unsigned long long
#define E '\n'
#define lmax 9223372036854775807;
#define MOD 1000000007
using namespace std;
vi v;
vvi ed;
void dfs(int i) {
v[i] = 1;
aut(j, ed[i]) if (!v[j]) dfs(j);
}
void Fast_IO() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("code.in", "r", stdin);
freopen("code.out", "w", stdout);
#endif
}
int main() {
// Fast_IO();
int t;
// cin>>t;
t = 1;
while (t--) {
int n;
cin >> n;
int k;
cin >> k;
vi arr(n);
vi ar(n);
rep(i, n) {
cin >> arr[i];
cin >> ar[i];
}
vector<vector<ll>> dp(2, vector<ll>(k + 1, -1));
dp[0][0] = 0;
int flg = 1;
forr(i, 1, n + 1) {
dp[flg][0] = 0;
forr(j, 1, k + 1) {
dp[flg][j] = dp[flg ^ 1][j];
if (arr[i - 1] <= j)
if (dp[flg ^ 1][j - arr[i - 1]] >= 0)
dp[flg][j] =
max(dp[flg][j], ar[i - 1] + dp[flg ^ 1][j - arr[i - 1]]);
}
flg ^= 1;
}
ll ans = -1;
rep(i, k + 1) ans = max(ans, dp[flg ^ 1][i]);
cout << ans;
cout << E;
}
return 0;
} | [
"call.remove"
] | 965,716 | 965,717 | u491084584 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1001001001;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n);
vector<ll> v(n);
rep(i, n) cin >> w[i] >> v[i];
// dp[i][j] i番目までで、重さWを選ぶ場合の最大価値
vvl dp(n + 1, vector<ll>(W, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (j - w[i] >= 0)
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[n][W] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1001001001;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n);
vector<ll> v(n);
rep(i, n) cin >> w[i] >> v[i];
// dp[i][j] i番目までで、重さWを選ぶ場合の最大価値
vvl dp(n + 1, vector<ll>(W + 1, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (j - w[i] >= 0)
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[n][W] << endl;
}
| [
"assignment.change"
] | 965,733 | 965,734 | u493928141 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n = 0, w = 0;
cin >> n >> w;
int t[n + 1][w + 1] = {0};
int weight_array[n] = {0};
int value_array[n] = {0};
for (int i = 0; i < n; i++) {
cin >> weight_array[i] >> value_array[i];
}
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
t[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (weight_array[i - 1] <= j)
t[i][j] = max(value_array[i - 1] + t[i - 1][j - weight_array[i - 1]],
t[i - 1][j]);
else
t[i][j] = t[i - 1][j];
}
}
cout << t[n][w];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n = 0, w = 0;
cin >> n >> w;
long long int t[n + 1][w + 1] = {0};
int weight_array[n] = {0};
int value_array[n] = {0};
for (int i = 0; i < n; i++) {
cin >> weight_array[i] >> value_array[i];
}
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
t[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (weight_array[i - 1] <= j)
t[i][j] = max(value_array[i - 1] + t[i - 1][j - weight_array[i - 1]],
t[i - 1][j]);
else
t[i][j] = t[i - 1][j];
}
}
cout << t[n][w];
return 0;
}
| [
"variable_declaration.type.widen.change"
] | 965,737 | 965,738 | u208922403 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int t[102][100002];
int n = 0, w = 0;
int knapsack(int n, int w, int weight_array[], int value_array[]) {
if (n == 0 || w == 0)
return 0;
if (t[n][w] != -1)
return t[n][w];
if (weight_array[n - 1] > w)
return t[n][w] = knapsack(n - 1, w, weight_array, value_array);
else
return t[n][w] =
max(value_array[n - 1] + knapsack(n - 1, w - weight_array[n - 1],
weight_array, value_array),
knapsack(n - 1, w, weight_array, value_array));
}
int main() {
int testcase = 1;
// cin>>testcase;
for (int p = 0; p < testcase; p++) {
cin >> n >> w;
int weight_array[n] = {0};
int value_array[n] = {0};
for (int i = 0; i < n; i++) {
cin >> weight_array[i] >> value_array[i];
}
memset(t, -1, sizeof(t));
cout << knapsack(n, w, weight_array, value_array) << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
long long t[101][100001];
int n = 0, w = 0;
long long int knapsack(int n, int w, int weight_array[], int value_array[]) {
if (n == 0 || w == 0)
return 0;
if (t[n][w] != -1)
return t[n][w];
if (weight_array[n - 1] > w)
return t[n][w] = knapsack(n - 1, w, weight_array, value_array);
else
return t[n][w] =
max(value_array[n - 1] + knapsack(n - 1, w - weight_array[n - 1],
weight_array, value_array),
knapsack(n - 1, w, weight_array, value_array));
}
int main() {
int testcase = 1;
// cin>>testcase;
for (int p = 0; p < testcase; p++) {
cin >> n >> w;
int weight_array[n] = {0};
int value_array[n] = {0};
for (int i = 0; i < n; i++) {
cin >> weight_array[i] >> value_array[i];
}
memset(t, -1, sizeof(t));
cout << knapsack(n, w, weight_array, value_array) << "\n";
}
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 965,739 | 965,740 | u208922403 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a, b, c) \
for (int b = 0; b < c; b++) \
cin >> a[b]
// #define mp make_pair
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mx 400005
#define fiint(a, b) memset(a, b, sizeof(a))
#define bitcount __builtin_popcount
#define fori(i, a, b) for (int i = a; i < b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cout << x << endl;
#define cases(t) \
int t; \
cin >> t; \
while (t--)
#define inf1 INT_MAX
#define all(a) a.begin(), a.end()
#define vec vector<int>
#define pii pair<int, int>
#define plii pair<int, int>
#define pint pair<int, int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int)x.size()
#define PI 3.14159265359
bool prime[10000001];
void sieveFunction(int maxLimit) {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; maxLimit >= i; i++) {
if (prime[i]) {
for (int j = 2 * i; maxLimit >= j; j += i)
prime[j] = false;
}
}
}
signed main() {
int n, w;
cin >> n >> w;
vector<int> v[n + 1];
int a, b;
fori(i, 1, n + 1) {
cin >> a >> b;
v[i].pb(a);
v[i].pb(b);
}
vector<vector<int>> dp(n + 1, vector<int>(w + 1));
fori(i, 1, n + 1) fori(j, 0, w + 1) if (v[i][0] <= j) dp[i][j] =
max(dp[i - 1][j], v[i][1] + dp[i][j - v[i][0]]);
else dp[i][j] = dp[i - 1][j];
cout << dp[n][w] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a, b, c) \
for (int b = 0; b < c; b++) \
cin >> a[b]
// #define mp make_pair
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mx 400005
#define fiint(a, b) memset(a, b, sizeof(a))
#define bitcount __builtin_popcount
#define fori(i, a, b) for (int i = a; i < b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cout << x << endl;
#define cases(t) \
int t; \
cin >> t; \
while (t--)
#define inf1 INT_MAX
#define all(a) a.begin(), a.end()
#define vec vector<int>
#define pii pair<int, int>
#define plii pair<int, int>
#define pint pair<int, int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int)x.size()
#define PI 3.14159265359
bool prime[10000001];
void sieveFunction(int maxLimit) {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; maxLimit >= i; i++) {
if (prime[i]) {
for (int j = 2 * i; maxLimit >= j; j += i)
prime[j] = false;
}
}
}
signed main() {
int n, w;
cin >> n >> w;
vector<int> v[n + 1];
int a, b;
fori(i, 1, n + 1) {
cin >> a >> b;
v[i].pb(a);
v[i].pb(b);
}
vector<vector<int>> dp(n + 1, vector<int>(w + 1));
fori(i, 1, n + 1) fori(j, 1, w + 1) if (v[i][0] <= j) dp[i][j] =
max(dp[i - 1][j], v[i][1] + dp[i - 1][j - v[i][0]]);
else dp[i][j] = dp[i - 1][j];
cout << dp[n][w] << endl;
}
| [
"literal.number.change",
"call.arguments.change",
"assignment.change"
] | 965,741 | 965,742 | u827746123 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a, b, c) \
for (int b = 0; b < c; b++) \
cin >> a[b]
// #define mp make_pair
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mx 400005
#define fiint(a, b) memset(a, b, sizeof(a))
#define bitcount __builtin_popcount
#define fori(i, a, b) for (int i = a; i < b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cout << x << endl;
#define cases(t) \
int t; \
cin >> t; \
while (t--)
#define inf1 INT_MAX
#define all(a) a.begin(), a.end()
#define vec vector<int>
#define pii pair<int, int>
#define plii pair<int, int>
#define pint pair<int, int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int)x.size()
#define PI 3.14159265359
bool prime[10000001];
void sieveFunction(int maxLimit) {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; maxLimit >= i; i++) {
if (prime[i]) {
for (int j = 2 * i; maxLimit >= j; j += i)
prime[j] = false;
}
}
}
signed main() {
int n, w;
cin >> n >> w;
vector<int> v[n + 1];
int a, b;
fori(i, 1, n + 1) {
cin >> a >> b;
v[i].pb(a);
v[i].pb(b);
}
vector<vector<int>> dp(n + 1, vector<int>(w + 1));
fori(i, 1, n + 1) fori(j, 1, w + 1) if (v[i][0] <= j) dp[i][j] =
max(dp[i - 1][j], v[i][1] + dp[i][j - v[i][0]]);
else dp[i][j] = dp[i - 1][j];
cout << dp[n][w] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a, b, c) \
for (int b = 0; b < c; b++) \
cin >> a[b]
// #define mp make_pair
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mx 400005
#define fiint(a, b) memset(a, b, sizeof(a))
#define bitcount __builtin_popcount
#define fori(i, a, b) for (int i = a; i < b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cout << x << endl;
#define cases(t) \
int t; \
cin >> t; \
while (t--)
#define inf1 INT_MAX
#define all(a) a.begin(), a.end()
#define vec vector<int>
#define pii pair<int, int>
#define plii pair<int, int>
#define pint pair<int, int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int)x.size()
#define PI 3.14159265359
bool prime[10000001];
void sieveFunction(int maxLimit) {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; maxLimit >= i; i++) {
if (prime[i]) {
for (int j = 2 * i; maxLimit >= j; j += i)
prime[j] = false;
}
}
}
signed main() {
int n, w;
cin >> n >> w;
vector<int> v[n + 1];
int a, b;
fori(i, 1, n + 1) {
cin >> a >> b;
v[i].pb(a);
v[i].pb(b);
}
vector<vector<int>> dp(n + 1, vector<int>(w + 1));
fori(i, 1, n + 1) fori(j, 1, w + 1) if (v[i][0] <= j) dp[i][j] =
max(dp[i - 1][j], v[i][1] + dp[i - 1][j - v[i][0]]);
else dp[i][j] = dp[i - 1][j];
cout << dp[n][w] << endl;
}
| [
"assignment.change"
] | 965,743 | 965,742 | u827746123 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a, b, c) \
for (int b = 0; b < c; b++) \
cin >> a[b]
// #define mp make_pair
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mx 400005
#define fiint(a, b) memset(a, b, sizeof(a))
#define bitcount __builtin_popcount
#define fori(i, a, b) for (int i = a; i < b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cout << x << endl;
#define cases(t) \
int t; \
cin >> t; \
while (t--)
#define inf1 INT_MAX
#define all(a) a.begin(), a.end()
#define vec vector<int>
#define pii pair<int, int>
#define plii pair<int, int>
#define pint pair<int, int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int)x.size()
#define PI 3.14159265359
bool prime[10000001];
void sieveFunction(int maxLimit) {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; maxLimit >= i; i++) {
if (prime[i]) {
for (int j = 2 * i; maxLimit >= j; j += i)
prime[j] = false;
}
}
}
signed main() {
int n, w;
cin >> n >> w;
vector<int> v[n + 1];
int a, b;
fori(i, 1, n + 1) {
cin >> a >> b;
v[i].pb(a);
v[i].pb(b);
}
vector<vector<int>> dp(n + 1, vector<int>(w + 1));
fori(i, 1, n + 1) fori(j, 1, w + 1) if (v[i][0] <= j) dp[i][j] =
max(dp[i - 1][j - 1], v[i][1] + dp[i][j - v[i][0]]);
else dp[i][j] = dp[i - 1][j];
cout << dp[n][w] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define MOD 1000000007
#define mod 1000000007
#define M 1000000007
#define pb push_back
#define take(a, b, c) \
for (int b = 0; b < c; b++) \
cin >> a[b]
// #define mp make_pair
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mx 400005
#define fiint(a, b) memset(a, b, sizeof(a))
#define bitcount __builtin_popcount
#define fori(i, a, b) for (int i = a; i < b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define debug(x) cout << x << endl;
#define cases(t) \
int t; \
cin >> t; \
while (t--)
#define inf1 INT_MAX
#define all(a) a.begin(), a.end()
#define vec vector<int>
#define pii pair<int, int>
#define plii pair<int, int>
#define pint pair<int, int>
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int)x.size()
#define PI 3.14159265359
bool prime[10000001];
void sieveFunction(int maxLimit) {
memset(prime, true, sizeof(prime));
prime[0] = prime[1] = false;
for (int i = 2; maxLimit >= i; i++) {
if (prime[i]) {
for (int j = 2 * i; maxLimit >= j; j += i)
prime[j] = false;
}
}
}
signed main() {
int n, w;
cin >> n >> w;
vector<int> v[n + 1];
int a, b;
fori(i, 1, n + 1) {
cin >> a >> b;
v[i].pb(a);
v[i].pb(b);
}
vector<vector<int>> dp(n + 1, vector<int>(w + 1));
fori(i, 1, n + 1) fori(j, 1, w + 1) if (v[i][0] <= j) dp[i][j] =
max(dp[i - 1][j], v[i][1] + dp[i - 1][j - v[i][0]]);
else dp[i][j] = dp[i - 1][j];
cout << dp[n][w] << endl;
}
| [
"expression.operation.binary.remove",
"assignment.change"
] | 965,744 | 965,742 | u827746123 | cpp |
p03163 | /*
Author-KUSHAGRA SINGH
Birla Institute of Technology Mesra
CS K18
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
//#define mp make_pair
#define pb emplace_back
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define khtm "\n"
#define F first
#define S second
#define fr(i, a, n) for (i = a; i < n; i++)
#define ALL(x) x.begin(), x.end()
#define frr(i, a, n) for (i = n - 1; i >= a; i--)
#define mod 1000000007
#define fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define testcase \
ll T; \
cin >> T; \
while (T--)
const int MAX = 1e6 + 2;
/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
Number of leading zeroes: __builtin_clz(x)
Number of trailing zeroes : __builtin_ctz(x)
Number of set bits: __builtin_popcount(x)
*/
ll i, j, k, l, m, r, n;
ll a[MAX];
// ll dp[2006];
vpll v;
ll dp[2005][2005];
ll rec(ll pos, ll rem) {
if (pos == n)
return 0;
if (dp[pos][rem] == -1) {
dp[pos][rem] = 0;
if (rem >= v[pos].F) {
dp[pos][rem] =
max(v[pos].S + rec(pos + 1, rem - v[pos].F), rec(pos + 1, rem));
} else {
dp[pos][rem] = rec(pos + 1, rem);
}
}
return dp[pos][rem];
}
int main() {
fast memset(dp, -1, sizeof dp);
cin >> k >> n;
// vpll v;
fr(i, 0, n) {
cin >> l >> r;
v.pb(l, r);
}
cout << rec(0, k) << khtm;
return 0;
}
| /*
Author-KUSHAGRA SINGH
Birla Institute of Technology Mesra
CS K18
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
//#define mp make_pair
#define pb emplace_back
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define pq priority_queue<int>
#define khtm "\n"
#define F first
#define S second
#define fr(i, a, n) for (i = a; i < n; i++)
#define ALL(x) x.begin(), x.end()
#define frr(i, a, n) for (i = n - 1; i >= a; i--)
#define mod 1000000007
#define fast \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define testcase \
ll T; \
cin >> T; \
while (T--)
const int MAX = 1e6 + 2;
/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
Number of leading zeroes: __builtin_clz(x)
Number of trailing zeroes : __builtin_ctz(x)
Number of set bits: __builtin_popcount(x)
*/
ll i, j, k, l, m, r, n;
ll a[MAX];
// ll dp[2006];
vpll v;
ll dp[205][100005];
ll rec(ll pos, ll rem) {
if (pos == n)
return 0;
if (dp[pos][rem] == -1) {
dp[pos][rem] = 0;
if (rem >= v[pos].F) {
dp[pos][rem] =
max(v[pos].S + rec(pos + 1, rem - v[pos].F), rec(pos + 1, rem));
} else {
dp[pos][rem] = rec(pos + 1, rem);
}
}
return dp[pos][rem];
}
int main() {
fast memset(dp, -1, sizeof dp);
cin >> n >> k;
// vpll v;
fr(i, 0, n) {
cin >> l >> r;
v.pb(l, r);
}
// cout<<"Hey stupid robber, you can get ";
cout << rec(0, k) << khtm;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"expression.operation.binary.remove"
] | 965,760 | 965,759 | u897990209 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n, w;
cin >> n >> w;
vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
for (int i = 1; i <= n; i++) {
ll weight, value;
cin >> weight >> value;
for (int j = 1; j <= w; j++) {
dp[i][j] = max(dp[i - 1][j],
j - weight >= 0 ? dp[i - 1][j - weight] + value : 0);
}
}
cout << dp[n - 1][w - 1] << endl;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n, w;
cin >> n >> w;
vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
for (int i = 1; i <= n; i++) {
ll weight, value;
cin >> weight >> value;
for (int j = 1; j <= w; j++) {
dp[i][j] = max(dp[i - 1][j],
j - weight >= 0 ? dp[i - 1][j - weight] + value : 0);
}
}
cout << dp[n][w] << endl;
} | [
"expression.operation.binary.remove"
] | 965,763 | 965,764 | u972556261 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
int dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= w; i++) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (wt[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, w;
cin >> n >> w;
long long int wt[n], val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
long long int dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= w; i++) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (wt[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
} | [
"variable_declaration.type.widen.change"
] | 965,771 | 965,772 | u249024658 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<long long> vals;
vector<int> weights;
vector<pair<int, long long>> all;
for (int i = 0; i < N; i++) {
long long val, weight;
cin >> weight >> val;
// vals.push_back(val);
// weights.push_back(weight);
all.push_back(make_pair(weight, val));
}
// cout << endl;
// sort(all.begin(), all.end());
for (int i = 0; i < (int)all.size(); i++) {
weights.push_back(all[i].first);
vals.push_back(all[i].second);
// cout << weights[i] << " " << vals[i] << endl;
}
// dp[i][w]
// dp[0][w] = 0
// dp[i][w] = max(dp[][w-w1])
// int pos = 0;
// vector<bool> used(W, false);
// vector<long long> dp(W+1, 0);
// for(int i = 1; i <= W; i++)
// {
// long long m = 0;
// for(int j = 0; j < weights.size(); j++)
// {
// if(i - weights[j] >= 0 && !used[j])
// {
// m = max({m, dp[i-weights[j]] + vals[j]});
// used[j] = true;
// }
// }
// dp[i] = m;
// }
vector<vector<long long>> dp(N + 1, vector<long long>(W + 1, 0));
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (weights[i] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + vals[i - 1]);
}
}
// for(auto& v: dp)
// {
// for(auto& e: v)
// cout << e << " ";
// cout << endl;
// }
cout << dp[N][W] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<long long> vals;
vector<int> weights;
// vals.push_back(0);
// weights.push_back(0);
vector<pair<int, long long>> all;
for (int i = 0; i < N; i++) {
long long val, weight;
cin >> weight >> val;
// vals.push_back(val);
// weights.push_back(weight);
all.push_back(make_pair(weight, val));
}
// cout << endl;
// sort(all.begin(), all.end());
for (int i = 0; i < (int)all.size(); i++) {
weights.push_back(all[i].first);
vals.push_back(all[i].second);
// cout << weights[i] << " " << vals[i] << endl;
}
// dp[i][w]
// dp[0][w] = 0
// dp[i][w] = max(dp[][w-w1])
// int pos = 0;
// vector<bool> used(W, false);
// vector<long long> dp(W+1, 0);
// for(int i = 1; i <= W; i++)
// {
// long long m = 0;
// for(int j = 0; j < weights.size(); j++)
// {
// if(i - weights[j] >= 0 && !used[j])
// {
// m = max({m, dp[i-weights[j]] + vals[j]});
// used[j] = true;
// }
// }
// dp[i] = m;
// }
vector<vector<long long>> dp(N + 1, vector<long long>(W + 1, 0));
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (weights[i - 1] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weights[i - 1]] + vals[i - 1]);
}
}
// for(auto& v: dp)
// {
// for(auto& e: v)
// cout << e << " ";
// cout << endl;
// }
cout << dp[N][W] << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 965,775 | 965,776 | u298033264 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = INT_MAX; // 2147483647
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
#define debug(var) std::cout << #var " = " << var << std::endl
#else
#define debug(var)
#endif
#define p(var) std::cout << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0, i##_length = (n); i < i##_length; ++i)
#define repeq(i, n) for (int i = 1, i##_length = (n); i <= i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a >= 0 && ceil(a) == floor(a); }
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
for (int i = 0, len = v.size(); i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
for (int i = 0, len = vv.size(); i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
/*-----8<-----8<-----*/
int main() {
int N, W;
cin >> N >> W;
vector<int> v(N, 0), w(N, 0);
rep(i, N) { cin >> w[i] >> v[i]; }
// dp[i][j] 商品iまで使える状態 重さjの中での最大値
vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
rep(i, N) {
repeq(j, W) {
if (j - w[i] < 0) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
}
p(dp[N][W]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = INT_MAX; // 2147483647
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
#ifdef LOCAL_ENV
#define debug(var) std::cout << #var " = " << var << std::endl
#else
#define debug(var)
#endif
#define p(var) std::cout << var << std::endl
#define PI (acos(-1))
#define rep(i, n) for (int i = 0, i##_length = (n); i < i##_length; ++i)
#define repeq(i, n) for (int i = 1, i##_length = (n); i <= i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline double isnatural(double a) { return a >= 0 && ceil(a) == floor(a); }
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
for (int i = 0, len = v.size(); i < len; ++i) {
s << v[i];
if (i < len - 1)
s << "\t";
}
return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
for (int i = 0, len = vv.size(); i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const map<T1, T2> &m) {
s << "{" << endl;
for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr) {
s << "\t" << (*itr).first << " : " << (*itr).second << endl;
}
s << "}" << endl;
return s;
}
/*-----8<-----8<-----*/
int main() {
int N, W;
cin >> N >> W;
vector<ll> v(N, 0), w(N, 0);
rep(i, N) { cin >> w[i] >> v[i]; }
// dp[i][j] 商品iまで使える状態 重さjの中での最大値
vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
rep(i, N) {
repeq(j, W) {
if (j - w[i] < 0) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
}
p(dp[N][W]);
return 0;
}
| [
"call.arguments.change"
] | 965,783 | 965,784 | u061071198 | cpp |
p03163 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define RREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll dp[110][100010];
int solve() {
int n, w;
cin >> n >> w;
vector<ll> W(n), V(n);
rep(i, n) cin >> W[i] >> V[i];
rep(i, n) {
rep(j, w + 1) {
if (j + W[i] <= w)
dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]);
else
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[n][w] << endl;
return 0;
}
int main() {
// ios::sync_with_stdio(false);cin.tie(nullptr);
// cout << fixed;cout << setprecision(16);
solve();
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <ctype.h>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define RREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const long long INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll dp[110][100010];
int solve() {
int n, w;
cin >> n >> w;
vector<ll> W(n), V(n);
rep(i, n) cin >> W[i] >> V[i];
rep(i, n) {
rep(j, w + 1) {
if (j + W[i] <= w)
dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]);
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[n][w] << endl;
return 0;
}
int main() {
// ios::sync_with_stdio(false);cin.tie(nullptr);
// cout << fixed;cout << setprecision(16);
solve();
return 0;
} | [
"control_flow.branch.else.remove"
] | 965,875 | 965,876 | u820341516 | cpp |
p03163 | #include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll dp[110][100010];
int main() {
int n, w;
cin >> n >> w;
vector<int> W(n), V(n);
rep0(i, n) cin >> W[i] >> V[i];
rep0(i, n) {
rep0(j, w + 1) {
if (j + W[i] <= w) {
dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]);
} else {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
}
cout << dp[n][w] << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll dp[110][100010];
int main() {
int n, w;
cin >> n >> w;
vector<int> W(n), V(n);
rep0(i, n) cin >> W[i] >> V[i];
rep0(i, n) {
rep0(j, w + 1) {
if (j + W[i] <= w) {
dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]);
}
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[n][w] << endl;
return 0;
} | [] | 965,877 | 965,878 | u820341516 | cpp |
p03163 | #include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll dp[110][100010];
int main() {
int n, w;
cin >> n >> w;
vector<int> W(n), V(n);
rep0(i, n) cin >> W[i] >> V[i];
rep0(i, n) {
rep0(j, w + 1) {
if (j - W[i] >= 0) {
dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]);
} else {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
}
cout << dp[n][w] << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll dp[110][100010];
int main() {
int n, w;
cin >> n >> w;
vector<int> W(n), V(n);
rep0(i, n) cin >> W[i] >> V[i];
rep0(i, n) {
rep0(j, w + 1) {
if (j + W[i] <= w) {
dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]);
}
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[n][w] << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.arithmetic.change",
"control_flow.branch.if.condition.change"
] | 965,879 | 965,878 | u820341516 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
lli i, j, k, n, t;
cin >> n >> t;
lli w[n], v[n];
for (i = 0; i < n; i++)
cin >> w[i] >> v[i];
lli a[n + 1][t + 1];
for (i = 0; i <= n; i++)
a[i][0] = 0;
for (i = 0; i <= t; i++)
a[0][i] = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= t; j++) {
if (w[i - 1] > j)
a[i][j] = a[i - 1][j - 1];
else
a[i][j] = max(a[i - 1][j], v[i - 1] + a[i - 1][j - w[i - 1]]);
}
}
cout << a[n][t];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
lli i, j, k, n, t;
cin >> n >> t;
lli w[n], v[n];
for (i = 0; i < n; i++)
cin >> w[i] >> v[i];
lli a[n + 1][t + 1];
for (i = 0; i <= n; i++)
a[i][0] = 0;
for (i = 0; i <= t; i++)
a[0][i] = 0;
for (i = 1; i <= n; i++) {
for (j = 1; j <= t; j++) {
if (w[i - 1] > j)
a[i][j] = a[i - 1][j];
else
a[i][j] = max(a[i - 1][j], v[i - 1] + a[i - 1][j - w[i - 1]]);
}
}
cout << a[n][t];
return 0;
} | [
"expression.operation.binary.remove"
] | 965,880 | 965,881 | u391913928 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define IO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
double PI = acos(-1);
int n, w;
int val[105], weight[105];
int dp[100005][105];
int solve(int ww, int i) {
if (ww < 0)
return -1e9;
if (i == n)
return 0;
if (dp[ww][i] != -1)
return dp[ww][i];
return dp[ww][i] =
max(solve(ww - weight[i], i + 1) + val[i], solve(ww, i + 1));
}
int main() {
// IO
memset(dp, -1, sizeof dp);
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> weight[i] >> val[i];
cout << solve(w, 0);
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define IO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
double PI = acos(-1);
int n, w;
ll val[105], weight[105];
ll dp[100005][105];
ll solve(int ww, int i) {
if (ww < 0)
return -1e18;
if (i == n)
return 0;
if (dp[ww][i] != -1)
return dp[ww][i];
return dp[ww][i] =
max(solve(ww - weight[i], i + 1) + val[i], solve(ww, i + 1));
}
int main() {
// IO
memset(dp, -1, sizeof dp);
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> weight[i] >> val[i];
cout << solve(w, 0);
return 0;
}
| [
"variable_declaration.type.change",
"literal.number.change",
"function.return_value.change"
] | 965,888 | 965,889 | u131127512 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;
int n, w;
std::vector<pair<int, ll>> inp;
vector<vector<ll>> dp;
ll knapsack(int i = 0, int curr_wt = w) {
if (i == n)
return 0;
if (dp[i][curr_wt] == -1) {
ll ans = knapsack(i + 1, curr_wt);
if (curr_wt - inp[i].first >= 0) {
ans = max(ans, knapsack(i + 1, curr_wt - inp[i].first) + inp[i].second);
}
dp[i][curr_wt] = ans;
return ans;
} else
return dp[i][curr_wt];
}
ll bottoms_up_knapsack() {
for (int i = 0; i <= w; i++) {
dp[0][w] = 0;
}
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
ll ans = dp[i - 1][j];
if (j - inp[i - 1].first >= 0) {
ans = max(ans, dp[i - 1][j - inp[i - 1].first] + inp[i - 1].second);
dp[i][j] = ans;
}
}
}
return dp[n][w];
}
int main() {
cin >> n >> w;
inp.resize(n);
for (int i = 0; i < n; i++) {
cin >> inp[i].first;
cin >> inp[i].second;
}
dp.assign(n + 1, vector<ll>(w + 1, -1));
cout << bottoms_up_knapsack() << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;
int n, w;
std::vector<pair<int, ll>> inp;
vector<vector<ll>> dp;
ll knapsack(int i = 0, int curr_wt = w) {
if (i == n)
return 0;
if (dp[i][curr_wt] == -1) {
ll ans = knapsack(i + 1, curr_wt);
if (curr_wt - inp[i].first >= 0) {
ans = max(ans, knapsack(i + 1, curr_wt - inp[i].first) + inp[i].second);
}
dp[i][curr_wt] = ans;
return ans;
} else
return dp[i][curr_wt];
}
ll bottoms_up_knapsack() {
for (int i = 0; i <= w; i++) {
dp[0][i] = 0;
}
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
ll ans = dp[i - 1][j];
if (j - inp[i - 1].first >= 0) {
ans = max(ans, dp[i - 1][j - inp[i - 1].first] + inp[i - 1].second);
}
dp[i][j] = ans;
}
}
return dp[n][w];
}
int main() {
cin >> n >> w;
inp.resize(n);
for (int i = 0; i < n; i++) {
cin >> inp[i].first;
cin >> inp[i].second;
}
dp.assign(n + 1, vector<ll>(w + 1, -1));
cout << bottoms_up_knapsack() << endl;
/*for(int i=0;i<=n;i++)
{
for(int j=0;j<=w;j++)
{
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
} | [
"assignment.variable.change",
"identifier.change",
"variable_access.subscript.index.change"
] | 965,902 | 965,903 | u351351871 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n, w;
cin >> n >> w;
int weight[n];
ll values[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> values[i];
}
ll dp[n][100000] = {};
for (int i = 0; i < n; i++) {
for (int sum_w = 0; sum_w <= w; sum_w++) {
if (sum_w - weight[i] >= 0) {
chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + values[i]);
}
chmax(dp[i + 1][sum_w], dp[i][sum_w]);
}
}
cout << dp[n][w] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n, w;
cin >> n >> w;
int weight[n];
ll values[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> values[i];
}
ll dp[n + 1][100000] = {};
for (int i = 0; i < n; i++) {
for (int sum_w = 0; sum_w <= w; sum_w++) {
if (sum_w - weight[i] >= 0) {
chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + values[i]);
}
chmax(dp[i + 1][sum_w], dp[i][sum_w]);
}
}
cout << dp[n][w] << endl;
return 0;
} | [
"variable_declaration.array_dimensions.change",
"assignment.change"
] | 965,911 | 965,912 | u450093740 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n, w;
cin >> n >> w;
int weight[n];
ll values[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> values[i];
}
ll dp[n + 1][100100] = {};
for (int i = 0; i < n; i++) {
for (int sum_w = 0; sum_w <= w; sum_w++) {
if (sum_w - weight[i] >= 0) {
chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + values[i]);
} else {
chmax(dp[i + 1][sum_w], dp[i][sum_w]);
}
}
}
cout << dp[n][w] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n, w;
cin >> n >> w;
int weight[n];
ll values[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> values[i];
}
ll dp[n + 1][100000] = {};
for (int i = 0; i < n; i++) {
for (int sum_w = 0; sum_w <= w; sum_w++) {
if (sum_w - weight[i] >= 0) {
chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + values[i]);
}
chmax(dp[i + 1][sum_w], dp[i][sum_w]);
}
}
cout << dp[n][w] << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 965,913 | 965,912 | u450093740 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
vector<long long int> wt;
vector<long long int> val;
long long int n, w;
long long int mem[105][100005];
long long int dp(long long int i, long long int x) {
if (i >= n)
return 0;
if (mem[i][x] != -1)
return mem[i][x];
long long int ans = 0;
ans = max(dp(i + 1, x), ans);
if (x + wt[i] < w)
ans = max(ans, dp(i + 1, x + wt[i]) + val[i]);
mem[i][x] = ans;
return ans;
}
int main() {
cin >> n >> w;
memset(mem, -1, sizeof(mem));
for (long long int i = 0; i < n; i++) {
long long int x, y;
cin >> x >> y;
wt.push_back(x);
val.push_back(y);
}
cout << dp(0, 0);
} | #include <bits/stdc++.h>
using namespace std;
vector<long long int> wt;
vector<long long int> val;
long long int n, w;
long long int mem[105][100005];
long long int dp(long long int i, long long int x) {
if (i >= n)
return 0;
if (mem[i][x] != -1)
return mem[i][x];
long long int ans = 0;
ans = max(dp(i + 1, x), ans);
if (x + wt[i] <= w)
ans = max(ans, dp(i + 1, x + wt[i]) + val[i]);
mem[i][x] = ans;
return ans;
}
int main() {
cin >> n >> w;
memset(mem, -1, sizeof(mem));
for (long long int i = 0; i < n; i++) {
long long int x, y;
cin >> x >> y;
wt.push_back(x);
val.push_back(y);
}
cout << dp(0, 0);
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 965,919 | 965,920 | u774919576 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
struct item {
long long int val;
long long int wt;
};
vector<item> v;
long long int mem[105][100005] = {-1};
long long int dp(long long int n, long long int w) {
if (mem[n][w] != -1)
return mem[n][w];
if (n == 1) {
if (v[n].wt <= w)
return v[n].val;
} else {
if (v[n].wt <= w)
mem[n][w] = max(dp(n - 1, w - v[n].wt) + v[n].val, dp(n - 1, w));
else
mem[n][w] = dp(n - 1, w);
}
return mem[n][w];
}
int main() {
long long int n, ww;
cin >> n >> ww;
item x;
x.val = 0;
x.wt = 0;
v.push_back(x);
memset(mem, -1, sizeof mem);
for (long long int i = 0; i < n; i++) {
item x;
cin >> x.wt;
cin >> x.val;
v.push_back(x);
}
cout << dp(n, ww) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
struct item {
long long int val;
long long int wt;
};
vector<item> v;
long long int mem[105][100005] = {-1};
long long int dp(long long int n, long long int w) {
if (mem[n][w] != -1)
return mem[n][w];
if (n == 1) {
if (v[n].wt <= w)
return v[n].val;
else
return 0;
} else {
if (v[n].wt <= w)
mem[n][w] = max(dp(n - 1, w - v[n].wt) + v[n].val, dp(n - 1, w));
else
mem[n][w] = dp(n - 1, w);
}
return mem[n][w];
}
int main() {
long long int n, ww;
cin >> n >> ww;
item x;
x.val = 0;
x.wt = 0;
v.push_back(x);
memset(mem, -1, sizeof mem);
for (long long int i = 0; i < n; i++) {
item x;
cin >> x.wt;
cin >> x.val;
v.push_back(x);
}
cout << dp(n, ww) << endl;
return 0;
} | [
"control_flow.branch.else_if.replace.remove",
"control_flow.branch.if.replace.add",
"control_flow.return.add",
"control_flow.return.0.add"
] | 965,921 | 965,922 | u774919576 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<int> w(N);
vector<int> val(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> val[i];
}
int dp[N + 1][W + 1];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
if (w[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<long> w(N);
vector<long> val(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> val[i];
}
long dp[N + 1][W + 1];
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
if (w[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W] << endl;
} | [
"variable_declaration.type.primitive.change"
] | 965,923 | 965,924 | u290563481 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll knapsack(vector<ll> &val, vector<ll> &wt, ll W, ll n,
vector<vector<ll>> &dp) {
if (n == 0 || W == 0)
return dp[n][W] = 0;
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W)
return dp[n][W] =
max(val[n - 1] + knapsack(val, wt, W - wt[n - 1], n - 1, dp),
knapsack(val, wt, W, n - 1, dp));
else
return dp[n][W] = knapsack(val, wt, W, n - 1, dp);
}
int main() {
ll n, W;
cin >> n >> W;
vector<ll> wt(n), val(n);
for (ll i = 0; i < n; i++)
cin >> wt[i] >> val[i];
vector<vector<ll>> dp(n, vector<ll>(W + 1, -1));
cout << knapsack(val, wt, W, n, dp);
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll knapsack(vector<ll> &val, vector<ll> &wt, ll W, ll n,
vector<vector<ll>> &dp) {
if (n == 0 || W == 0)
return dp[n][W] = 0;
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W)
return dp[n][W] =
max(val[n - 1] + knapsack(val, wt, W - wt[n - 1], n - 1, dp),
knapsack(val, wt, W, n - 1, dp));
else
return dp[n][W] = knapsack(val, wt, W, n - 1, dp);
}
int main() {
ll n, W;
cin >> n >> W;
vector<ll> wt(n), val(n);
for (ll i = 0; i < n; i++)
cin >> wt[i] >> val[i];
vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, -1));
cout << knapsack(val, wt, W, n, dp);
cout << endl;
return 0;
} | [
"assignment.change"
] | 965,925 | 965,926 | u464716710 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll knapsack(vector<ll> &val, vector<ll> &wt, ll W, ll n,
vector<vector<ll>> &dp) {
if (n == 0 || W == 0)
return dp[n][W] = 0;
if (dp[n - 1][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W)
return dp[n][W] =
max(val[n - 1] + knapsack(val, wt, W - wt[n - 1], n - 1, dp),
knapsack(val, wt, W, n - 1, dp));
else
return dp[n][W] = knapsack(val, wt, W, n - 1, dp);
}
int main() {
ll n, W;
cin >> n >> W;
vector<ll> wt(n), val(n);
for (ll i = 0; i < n; i++)
cin >> wt[i] >> val[i];
vector<vector<ll>> dp(n, vector<ll>(W + 1, -1));
cout << knapsack(val, wt, W, n, dp);
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll knapsack(vector<ll> &val, vector<ll> &wt, ll W, ll n,
vector<vector<ll>> &dp) {
if (n == 0 || W == 0)
return dp[n][W] = 0;
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W)
return dp[n][W] =
max(val[n - 1] + knapsack(val, wt, W - wt[n - 1], n - 1, dp),
knapsack(val, wt, W, n - 1, dp));
else
return dp[n][W] = knapsack(val, wt, W, n - 1, dp);
}
int main() {
ll n, W;
cin >> n >> W;
vector<ll> wt(n), val(n);
for (ll i = 0; i < n; i++)
cin >> wt[i] >> val[i];
vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, -1));
cout << knapsack(val, wt, W, n, dp);
cout << endl;
return 0;
} | [
"expression.operation.binary.remove"
] | 965,927 | 965,926 | u464716710 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
int w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
int dp[n + 1][W + 1];
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
if (w[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], (v[i - 1] + dp[i - 1][j - w[i - 1]]));
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
int w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
long long int dp[n + 1][W + 1];
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
if (w[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], (v[i - 1] + dp[i - 1][j - w[i - 1]]));
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W] << endl;
} | [
"variable_declaration.type.widen.change"
] | 965,928 | 965,929 | u072063395 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
int dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j >= wt[i - 1]) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w;
cin >> n >> w;
int wt[n];
long long val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
long long dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j >= wt[i - 1]) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << "\n";
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,930 | 965,931 | u766871659 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define ff first
#define tc \
int ttt; \
cin >> ttt; \
while (ttt--)
#define ss second
#define f(i, a, b) for (int i = a; i < b; i++)
#define rev(i, a, b) for (int i = a; i >= b; i--)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }
int logg(ll x, ll y) {
if (x == 0)
return -1;
return logg(x / y, y) + 1;
}
ll poww(ll a, ll b, ll m) {
if (b == 0)
return 1;
ll ans = 1;
ans = poww(a, b >> 1, m);
ans = (ans * ans) % m;
if (b & 1)
ans = (ans * a) % m;
return ans;
}
// Start of code
const int N = 1e5 + 5;
int dp[105][105];
int weight[105];
int val[105];
int n, w;
int solve() {
memset(dp, -1, sizeof dp);
dp[1][weight[1]] = val[1];
int maxg = dp[1][weight[1]];
f(i, 2, n + 1) {
f(j, 0, w + 1) {
dp[i][j] = dp[i - 1][j];
if (weight[i] > j)
continue;
dp[i][j] = max(dp[i][j], val[i] + dp[i - 1][j - weight[i]]);
maxg = max(maxg, dp[i][j]);
}
}
return maxg;
}
int32_t main() {
fast;
cin >> n >> w;
f(i, 1, n + 1) cin >> weight[i] >> val[i];
cout << solve() << nl;
}
| #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define ff first
#define tc \
int ttt; \
cin >> ttt; \
while (ttt--)
#define ss second
#define f(i, a, b) for (int i = a; i < b; i++)
#define rev(i, a, b) for (int i = a; i >= b; i--)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }
int logg(ll x, ll y) {
if (x == 0)
return -1;
return logg(x / y, y) + 1;
}
ll poww(ll a, ll b, ll m) {
if (b == 0)
return 1;
ll ans = 1;
ans = poww(a, b >> 1, m);
ans = (ans * ans) % m;
if (b & 1)
ans = (ans * a) % m;
return ans;
}
// Start of code
const int N = 1e5 + 5;
int dp[105][N];
int weight[105];
int val[105];
int n, w;
int solve() {
memset(dp, 0, sizeof dp);
dp[1][weight[1]] = val[1];
int maxg = dp[1][weight[1]];
f(i, 2, n + 1) {
f(j, i, w + 1) {
dp[i][j] = dp[i - 1][j];
if (weight[i] > j)
continue;
dp[i][j] = max(dp[i][j], val[i] + dp[i - 1][j - weight[i]]);
maxg = max(maxg, dp[i][j]);
}
}
return maxg;
}
int32_t main() {
fast;
cin >> n >> w;
f(i, 1, n + 1) cin >> weight[i] >> val[i];
cout << solve() << nl;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"variable_declaration.array_dimensions.change",
"literal.number.change",
"call.arguments.change"
] | 965,932 | 965,933 | u311931982 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define ff first
#define tc \
int ttt; \
cin >> ttt; \
while (ttt--)
#define ss second
#define f(i, a, b) for (int i = a; i < b; i++)
#define rev(i, a, b) for (int i = a; i >= b; i--)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }
int logg(ll x, ll y) {
if (x == 0)
return -1;
return logg(x / y, y) + 1;
}
ll poww(ll a, ll b, ll m) {
if (b == 0)
return 1;
ll ans = 1;
ans = poww(a, b >> 1, m);
ans = (ans * ans) % m;
if (b & 1)
ans = (ans * a) % m;
return ans;
}
// Start of code
const int N = 1e5 + 5;
int dp[105][105];
int weight[105];
int val[105];
int n, w;
int solve() {
memset(dp, -1, sizeof dp);
dp[1][weight[1]] = val[1];
int maxg = dp[1][weight[1]];
f(i, 2, n + 1) {
f(j, 0, w + 1) {
dp[i][j] = dp[i - 1][j];
if (weight[i] > j)
continue;
dp[i][j] = max(dp[i][j], val[i] + dp[i - 1][j - weight[i]]);
maxg = max(maxg, dp[i][j]);
}
}
return maxg;
}
int32_t main() {
fast;
cin >> n >> w;
f(i, 1, n + 1) cin >> weight[i] >> val[i];
cout << solve() << nl;
}
| #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define int long long
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define ff first
#define tc \
int ttt; \
cin >> ttt; \
while (ttt--)
#define ss second
#define f(i, a, b) for (int i = a; i < b; i++)
#define rev(i, a, b) for (int i = a; i >= b; i--)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); }
int logg(ll x, ll y) {
if (x == 0)
return -1;
return logg(x / y, y) + 1;
}
ll poww(ll a, ll b, ll m) {
if (b == 0)
return 1;
ll ans = 1;
ans = poww(a, b >> 1, m);
ans = (ans * ans) % m;
if (b & 1)
ans = (ans * a) % m;
return ans;
}
// Start of code
const int N = 1e5 + 5;
int dp[105][N];
int weight[105];
int val[105];
int n, w;
int solve() {
memset(dp, 0, sizeof dp);
dp[1][weight[1]] = val[1];
int maxg = dp[1][weight[1]];
f(i, 2, n + 1) {
f(j, 0, w + 1) {
dp[i][j] = dp[i - 1][j];
if (weight[i] > j)
continue;
dp[i][j] = max(dp[i][j], val[i] + dp[i - 1][j - weight[i]]);
maxg = max(maxg, dp[i][j]);
}
}
return maxg;
}
int32_t main() {
fast;
cin >> n >> w;
f(i, 1, n + 1) cin >> weight[i] >> val[i];
cout << solve() << nl;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"variable_declaration.array_dimensions.change",
"literal.number.change",
"call.arguments.change"
] | 965,932 | 965,934 | u311931982 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout << #x << " is " << x << endl;
#define ffor(i, a, b) for (int i = a; i < b; i++)
#define bfor(i, a, b) for (int i = b; i >= a; i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double, double>>
#define vpp vector<pair<int, pair<int, int>>>
#define pp pair<int, int>
int knapsack(vector<pair<int, int>> &v, int n, int w) {
long long int dp[n + 1][w + 1];
ffor(i, 0, w + 1) dp[0][i] = 0;
ffor(i, 0, n + 1) dp[i][0] = 0;
// ffor(i,0,n)
// cout<<v[i].ff<<" "<<v[i].ss<<endl;
ffor(i, 1, n + 1) {
ffor(j, 1, w + 1) {
if (j >= v[i - 1].ff)
dp[i][j] = max(dp[i - 1][j - v[i - 1].ff] + v[i - 1].ss, dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][w];
}
int main() {
int n, w;
cin >> n >> w;
vector<pair<int, int>> v;
ffor(i, 0, n) {
int a, b;
cin >> a >> b;
v.pb(mp(a, b));
}
cout << knapsack(v, n, w);
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout << #x << " is " << x << endl;
#define ffor(i, a, b) for (int i = a; i < b; i++)
#define bfor(i, a, b) for (int i = b; i >= a; i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double, double>>
#define vpp vector<pair<int, pair<int, int>>>
#define pp pair<int, int>
long long int knapsack(vector<pair<int, int>> &v, int n, int w) {
long long int dp[n + 1][w + 1];
ffor(i, 0, w + 1) dp[0][i] = 0;
ffor(i, 0, n + 1) dp[i][0] = 0;
// ffor(i,0,n)
// cout<<v[i].ff<<" "<<v[i].ss<<endl;
ffor(i, 1, n + 1) {
ffor(j, 1, w + 1) {
if (j >= v[i - 1].ff)
dp[i][j] = max(dp[i - 1][j - v[i - 1].ff] + v[i - 1].ss, dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][w];
}
int main() {
int n, w;
cin >> n >> w;
vector<pair<int, int>> v;
ffor(i, 0, n) {
int a, b;
cin >> a >> b;
v.pb(mp(a, b));
}
cout << knapsack(v, n, w);
} | [
"variable_declaration.type.widen.change"
] | 965,935 | 965,936 | u972619069 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout << #x << " is " << x << endl;
#define ffor(i, a, b) for (int i = a; i < b; i++)
#define bfor(i, a, b) for (int i = b; i >= a; i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double, double>>
#define vpp vector<pair<int, pair<int, int>>>
#define pp pair<int, int>
int knapsack(vector<pair<int, int>> &v, int n, int w) {
int dp[n + 1][w + 1];
ffor(i, 0, w + 1) dp[0][i] = 0;
ffor(i, 0, n + 1) dp[i][0] = 0;
// ffor(i,0,n)
// cout<<v[i].ff<<" "<<v[i].ss<<endl;
ffor(i, 1, n + 1) {
ffor(j, 1, w + 1) {
if (j >= v[i - 1].ff)
dp[i][j] = max(dp[i - 1][j - v[i - 1].ff] + v[i - 1].ss, dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][w];
}
int main() {
int n, w;
cin >> n >> w;
vector<pair<int, int>> v;
ffor(i, 0, n) {
int a, b;
cin >> a >> b;
v.pb(mp(a, b));
}
cout << knapsack(v, n, w);
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout << #x << " is " << x << endl;
#define ffor(i, a, b) for (int i = a; i < b; i++)
#define bfor(i, a, b) for (int i = b; i >= a; i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double, double>>
#define vpp vector<pair<int, pair<int, int>>>
#define pp pair<int, int>
long long int knapsack(vector<pair<int, int>> &v, int n, int w) {
long long int dp[n + 1][w + 1];
ffor(i, 0, w + 1) dp[0][i] = 0;
ffor(i, 0, n + 1) dp[i][0] = 0;
// ffor(i,0,n)
// cout<<v[i].ff<<" "<<v[i].ss<<endl;
ffor(i, 1, n + 1) {
ffor(j, 1, w + 1) {
if (j >= v[i - 1].ff)
dp[i][j] = max(dp[i - 1][j - v[i - 1].ff] + v[i - 1].ss, dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][w];
}
int main() {
int n, w;
cin >> n >> w;
vector<pair<int, int>> v;
ffor(i, 0, n) {
int a, b;
cin >> a >> b;
v.pb(mp(a, b));
}
cout << knapsack(v, n, w);
} | [
"variable_declaration.type.widen.change"
] | 965,937 | 965,936 | u972619069 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.