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;
typedef long long ll;
#define f(i, n) for (ll i = 0; i < n; i++)
#define pb push_back
int mod = 1e9 + 7;
int gcd(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
ll fast(ll a, ll n) {
a %= mod;
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int digit_sum(int a) {
int sum = 0;
while (a) {
sum += a % 10;
a /= 10;
}
return sum;
}
// vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n;
// vector<vector<int> >a(n,vector<int>(3,0));
int W;
cin >> W;
int wt[n], v[n];
// int dp[tw+1][n+1];
// memset(dp,-1,sizeof dp);
// f(i,n+1)dp[0][i]=0;
// f(i,tw+1)dp[i][0]=0;
//
f(i, n) cin >> wt[i] >> v[i];
// f(j,n)cin>>v[j];
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] = max(v[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
cout << K[n][W];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i, n) for (ll i = 0; i < n; i++)
#define pb push_back
int mod = 1e9 + 7;
int gcd(int a, int b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
ll fast(ll a, ll n) {
a %= mod;
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int digit_sum(int a) {
int sum = 0;
while (a) {
sum += a % 10;
a /= 10;
}
return sum;
}
// vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n;
// vector<vector<int> >a(n,vector<int>(3,0));
int W;
cin >> W;
int wt[n], v[n];
// int dp[tw+1][n+1];
// memset(dp,-1,sizeof dp);
// f(i,n+1)dp[0][i]=0;
// f(i,tw+1)dp[i][0]=0;
//
f(i, n) cin >> wt[i] >> v[i];
// f(j,n)cin>>v[j];
int i, w;
ll 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] = max(v[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
cout << K[n][W] << endl;
return 0;
}
| [
"variable_declaration.type.change",
"io.output.newline.add"
] | 965,938 | 965,939 | u700590924 | cpp |
p03163 | #include <algorithm>
#include <cmath> // circle math ( sin, con, sinh
#include <iomanip> // input output manipulation
#include <iostream> // input output stream, cin cout( console in console out)
#include <stdio.h> // standard input output
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ll long long
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int dp[101][100001]; // dpテーブル
int v[100], w[100];
int N, W;
int rec(int i, int j) {
if (dp[i][j] > -1) {
return dp[i][j];
}
int res;
if (i == N) {
return 0;
} else if (j < w[i]) {
res = rec(i + 1, j); //入らない時
} else {
res = max(rec(i + 1, j),
rec(i + 1, j - w[i]) + v[i]); //入れると入れないで比較
}
return dp[i][j] = res;
}
int main() {
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
for (int i = 0; i < 101; i++) {
for (int j = 0; j < 100001; j++) {
dp[i][j] = -1;
}
}
cout << rec(0, W) << endl; // 標準出力
}
| #include <algorithm>
#include <cmath> // circle math ( sin, con, sinh
#include <iomanip> // input output manipulation
#include <iostream> // input output stream, cin cout( console in console out)
#include <stdio.h> // standard input output
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define ll long long
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll dp[101][100001]; // dpテーブル
int v[100], w[100];
int N, W;
ll rec(int i, int j) {
if (dp[i][j] > -1) {
return dp[i][j];
}
ll res;
if (i == N) {
res = 0;
} else if (j < w[i]) {
res = rec(i + 1, j); //入らない時
} else {
res = max(rec(i + 1, j),
rec(i + 1, j - w[i]) + v[i]); //入れると入れないで比較
}
return dp[i][j] = res;
}
int main() {
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
for (int i = 0; i < 101; i++) {
for (int j = 0; j < 100001; j++) {
dp[i][j] = -1;
}
}
cout << rec(0, W) << endl; // 標準出力
}
| [
"variable_declaration.type.change",
"assignment.variable.change",
"function.return_value.change"
] | 965,940 | 965,941 | u480059652 | cpp |
p03163 | // In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define MAX 100011
#define ll long long
#define endl '\n'
ll dp[101][MAX], w;
int v[MAX], c[MAX];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> c[i] >> v[i];
for (int i = c[0]; i < n; i++)
dp[0][i] = v[0];
for (int i = 1; i < n; i++) {
for (int j = 1; j <= w; j++) {
if (c[i] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - c[i]] + v[i]);
}
}
cout << dp[n - 1][w];
return 0;
}
| // In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define MAX 100011
#define ll long long
#define endl '\n'
ll dp[101][MAX], w;
int v[MAX], c[MAX];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> c[i] >> v[i];
for (int i = c[0]; i <= w; i++)
dp[0][i] = v[0];
for (int i = 1; i < n; i++) {
for (int j = 1; j <= w; j++) {
if (c[i] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - c[i]] + v[i]);
}
}
// for(int i = 0; i < n ;i++){
// for(int j = 0; j <= w ; j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[n - 1][w];
return 0;
}
| [
"control_flow.loop.for.condition.change"
] | 965,947 | 965,948 | u732350342 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
const double EPS = 1e-10;
int main() {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
vector<vector<lint>> ma(N + 1, vector<lint>(W, -INF));
ma[0][0] = 0;
for (int j = 1; j <= W; j++) {
ma[0][j] = -INF;
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
ma[i][j] = ma[i - 1][j];
if (j - w[i - 1] >= 0) {
ma[i][j] = max(ma[i][j], ma[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
}
lint ans = -1;
for (int j = 0; j <= W; j++) {
ans = max(ans, ma[N][j]);
}
cout << ans << endl;
// dump(v);
// dump(w);
// ddump(ma);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v) \
cerr << #v ":[ "; \
for (auto macro_vi : v) { \
cerr << macro_vi << " "; \
} \
cerr << "]" << endl;
#define ddump(v) \
cerr << #v ":" << endl; \
for (auto macro_row : v) { \
cerr << "["; \
for (auto macro__vi : macro_row) { \
cerr << macro__vi << " "; \
} \
cerr << "]" << endl; \
}
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
const double EPS = 1e-10;
int main() {
int N, W;
cin >> N >> W;
vector<lint> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
vector<vector<lint>> ma(N + 1, vector<lint>(W + 1, -INF));
ma[0][0] = 0;
for (int j = 1; j <= W; j++) {
ma[0][j] = -INF;
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
ma[i][j] = ma[i - 1][j];
if (j - w[i - 1] >= 0) {
ma[i][j] = max(ma[i][j], ma[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
}
lint ans = -1;
for (int j = 0; j <= W; j++) {
ans = max(ans, ma[N][j]);
}
cout << ans << endl;
// dump(v);
// dump(w);
// ddump(ma);
return 0;
} | [
"assignment.change"
] | 965,949 | 965,950 | u784072785 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll knap(ll i, ll w, vector<vector<ll>> &v, ll n, vector<vector<ll>> &dp) {
if (i >= n) {
return 0;
}
if (w == 0) {
return 0;
}
if (dp[i][w] != -1)
return dp[i][w];
ll l, r;
if (v[i][0] <= w) {
l = v[i][1] + knap(i + 1, w - v[i][0], v, n, dp);
r = knap(i + 1, w, v, n, dp);
dp[i][w] = max(l, r);
return dp[i][w];
}
dp[i][w] = knap(i + 1, w, v, n, dp);
return dp[i][w];
}
int main() {
ll n, i, j, k;
cin >> n >> k;
vector<vector<ll>> v(n, vector<ll>(2, 0));
for (i = 0; i < n; i++)
cin >> v[i][0] >> v[i][1];
vector<vector<ll>> dp(k, vector<ll>(n, -1));
cout << knap(0, k, v, n, dp) << "\n";
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll knap(ll i, ll w, vector<vector<ll>> &v, ll n, vector<vector<ll>> &dp) {
if (i >= n) {
return 0;
}
if (w == 0) {
return 0;
}
if (dp[i][w] != -1)
return dp[i][w];
ll l, r;
if (v[i][0] <= w) {
l = v[i][1] + knap(i + 1, w - v[i][0], v, n, dp);
r = knap(i + 1, w, v, n, dp);
dp[i][w] = max(l, r);
return dp[i][w];
}
dp[i][w] = knap(i + 1, w, v, n, dp);
return dp[i][w];
}
int main() {
ll n, i, j, k;
cin >> n >> k;
vector<vector<ll>> v(n, vector<ll>(2, 0));
for (i = 0; i < n; i++)
cin >> v[i][0] >> v[i][1];
vector<vector<ll>> dp(n, vector<ll>(k + 1, -1));
cout << knap(0, k, v, n, dp) << "\n";
return 0;
} | [
"identifier.change",
"call.arguments.change"
] | 965,957 | 965,958 | u401330034 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll knap(ll i, ll w, vector<vector<ll>> &v, ll n, vector<vector<ll>> &dp) {
if (i >= n) {
return 0;
}
if (w <= 0) {
return 0;
}
if (dp[i][w] != -1)
return dp[i][w];
ll l, r;
if (v[i][0] <= w) {
l = v[i][1] + knap(i + 1, w - v[i][0], v, n, dp);
r = knap(i + 1, w, v, n, dp);
dp[i][w] = max(l, r);
return dp[i][w];
}
dp[i][w] = knap(i + 1, w, v, n, dp);
return dp[i][w];
}
int main() {
ll n, i, j, k;
cin >> n >> k;
vector<vector<ll>> v(n, vector<ll>(2, 0));
for (i = 0; i < n; i++)
cin >> v[i][0] >> v[i][1];
vector<vector<ll>> dp(k, vector<ll>(n, -1));
cout << knap(0, k, v, n, dp) << "\n";
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll knap(ll i, ll w, vector<vector<ll>> &v, ll n, vector<vector<ll>> &dp) {
if (i >= n) {
return 0;
}
if (w == 0) {
return 0;
}
if (dp[i][w] != -1)
return dp[i][w];
ll l, r;
if (v[i][0] <= w) {
l = v[i][1] + knap(i + 1, w - v[i][0], v, n, dp);
r = knap(i + 1, w, v, n, dp);
dp[i][w] = max(l, r);
return dp[i][w];
}
dp[i][w] = knap(i + 1, w, v, n, dp);
return dp[i][w];
}
int main() {
ll n, i, j, k;
cin >> n >> k;
vector<vector<ll>> v(n, vector<ll>(2, 0));
for (i = 0; i < n; i++)
cin >> v[i][0] >> v[i][1];
vector<vector<ll>> dp(n, vector<ll>(k + 1, -1));
cout << knap(0, k, v, n, dp) << "\n";
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"identifier.change",
"call.arguments.change"
] | 965,959 | 965,958 | u401330034 | cpp |
p03163 | #include <bits/stdc++.h>
const int mod = 1000000007;
const int modx = 998244353;
#define ll long long
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define rep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bpc(x) __builtin_popcount(x)
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pdd pair<double, double>
#define pic pair<int, char>
#define ddouble long double
#define PI 3.1415926535
#define endl "\n"
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define prod(x, y) ((x % mod) * (y % mod)) % mod
#define add(x, y) ((x % mod) + (y % mod)) % mod
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define pqs priority_queue<int, vector<int>, greater<int>>
#define pqb priority_queue<int>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
// using namespace __gnu_pbds;
/*ll power(ll x, ll y)
{
ll r = 1;
x = x % mod;
while (y > 0)
{
if (y & 1)
r = (r*x) % mod;
y = y>>1;
x = (x*x) % mod;
}
return r;
}*/
void thunder() {
int n, W;
cin >> n >> W;
vi w(n + 1), v(n + 1);
int i, j, k;
rep(i, n) { cin >> w[i] >> v[i]; }
int dp[n + 5][W + 5] = {};
rep1(i, 1, n + 1) {
rep(j, W + 1) {
dp[i][j] = dp[i - 1][j];
if (j - w[i - 1] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
cout << dp[n][W] << endl;
return;
}
int main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
thunder();
}
| #include <bits/stdc++.h>
const int mod = 1000000007;
const int modx = 998244353;
#define ll long long
#define readi(x) scanf("%d", &x)
#define reads(x) scanf("%s", x)
#define readl(x) scanf("%I64d", &x)
#define rep(i, n) for (i = 0; i < n; i++)
#define rep1(i, a, b) for (i = a; i < b; i++)
#define rep2(i, a, b) for (i = b; i >= a; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bpc(x) __builtin_popcount(x)
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pdd pair<double, double>
#define pic pair<int, char>
#define ddouble long double
#define PI 3.1415926535
#define endl "\n"
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define prod(x, y) ((x % mod) * (y % mod)) % mod
#define add(x, y) ((x % mod) + (y % mod)) % mod
#define ub(a, b) upper_bound(all(a), b)
#define lb(a, b) lower_bound(all(a), b)
#define pqs priority_queue<int, vector<int>, greater<int>>
#define pqb priority_queue<int>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
// using namespace __gnu_pbds;
/*ll power(ll x, ll y)
{
ll r = 1;
x = x % mod;
while (y > 0)
{
if (y & 1)
r = (r*x) % mod;
y = y>>1;
x = (x*x) % mod;
}
return r;
}*/
void thunder() {
ll n, W;
cin >> n >> W;
vll w(n + 1), v(n + 1);
ll i, j, k;
rep(i, n) { cin >> w[i] >> v[i]; }
ll dp[n + 5][W + 5] = {};
rep1(i, 1, n + 1) {
rep(j, W + 1) {
dp[i][j] = dp[i - 1][j];
if (j - w[i - 1] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
cout << dp[n][W] << endl;
return;
}
int main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t = 1;
// cin >> t;
while (t--)
thunder();
}
| [
"variable_declaration.type.change"
] | 965,963 | 965,964 | u706547107 | cpp |
p03163 | using namespace std;
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll, ll>
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll, ll>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
typedef long long int ll;
// stringstream convert;
// convert << number;
// string s = convert.str();
ll fact[500005], invfact[500005];
ll power(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2 == 1)
z = (z * x) % MOD;
x = (x * x) % MOD;
y /= 2;
}
return z;
}
ll inv(ll x) { return power(x, MOD - 2); }
ll divide(ll x, ll y) { return (x * inv(y)) % MOD; }
ll C(ll n, ll k) {
if (k > n)
return 0;
return divide(fact[n], (fact[n - k] * fact[k]) % MOD);
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
void init() {
ll p = MOD;
fact[0] = 1;
ll i;
for (i = 1; i < 500005; i++) {
fact[i] = (i * fact[i - 1]) % p;
}
i--;
invfact[i] = power(fact[i], p - 2);
for (i--; i >= 0; i--) {
invfact[i] = (invfact[i + 1] * (i + 1)) % p;
}
}
ll s;
ll fun(ll a) {
if (a == 0)
return 0;
return a + fun(a - 1);
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> gq;
#define MAXN 10000001
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
set<ll> getFactorization(ll x) {
set<ll> ret;
while (x != 1) {
ret.insert(spf[x]);
x = x / spf[x];
}
return ret;
}
ll sm(ll n) {
ll i;
ll k = 0;
while (n > 0) {
k = k + n % 10;
n = n / 10;
}
return k;
}
void ghost() {
ll i = 0, j = 0, k = 0, l = 0, n, r = 0, q = 0, t, y = 100000000000, m, w;
cin >> n >> k;
ll a[n];
ll b[n];
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
ll dp[n + 1][k + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= k; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j >= a[i])
dp[i][j] = max(dp[i - 1][j - a[i - 1]] + b[i - 1], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][k];
}
signed main() {
int test = 1;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
fast
// cin>>test;
while (test--) ghost();
return 0;
}
| using namespace std;
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define vect vector<ll>
#define maap map<ll, ll>
#define MOD 1000000007
#define mit map::iterator
#define pii pair<ll, ll>
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
typedef long long int ll;
// stringstream convert;
// convert << number;
// string s = convert.str();
ll fact[500005], invfact[500005];
ll power(ll x, ll y) {
ll z = 1;
while (y > 0) {
if (y % 2 == 1)
z = (z * x) % MOD;
x = (x * x) % MOD;
y /= 2;
}
return z;
}
ll inv(ll x) { return power(x, MOD - 2); }
ll divide(ll x, ll y) { return (x * inv(y)) % MOD; }
ll C(ll n, ll k) {
if (k > n)
return 0;
return divide(fact[n], (fact[n - k] * fact[k]) % MOD);
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
bool isPrime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
void init() {
ll p = MOD;
fact[0] = 1;
ll i;
for (i = 1; i < 500005; i++) {
fact[i] = (i * fact[i - 1]) % p;
}
i--;
invfact[i] = power(fact[i], p - 2);
for (i--; i >= 0; i--) {
invfact[i] = (invfact[i + 1] * (i + 1)) % p;
}
}
ll s;
ll fun(ll a) {
if (a == 0)
return 0;
return a + fun(a - 1);
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> gq;
#define MAXN 10000001
ll spf[MAXN];
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
set<ll> getFactorization(ll x) {
set<ll> ret;
while (x != 1) {
ret.insert(spf[x]);
x = x / spf[x];
}
return ret;
}
ll sm(ll n) {
ll i;
ll k = 0;
while (n > 0) {
k = k + n % 10;
n = n / 10;
}
return k;
}
void ghost() {
ll i = 0, j = 0, k = 0, l = 0, n, r = 0, q = 0, t, y = 100000000000, m, w;
cin >> n >> k;
ll a[n];
ll b[n];
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
ll dp[n + 1][k + 1];
for (i = 0; i <= n; i++) {
for (j = 0; j <= k; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j >= a[i - 1])
dp[i][j] = max(dp[i - 1][j - a[i - 1]] + b[i - 1], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][k];
}
signed main() {
int test = 1;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
fast
// cin>>test;
while (test--) ghost();
return 0;
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 965,965 | 965,966 | u379844185 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
long long int knapsack(int W, int wt[], long long int val[], int n) {
long long 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 (j >= wt[i - 1]) {
k[i][j] = max(val[i - 1] + k[i - 1][j - wt[i - 1]], k[i - 1][j]);
} else {
k[i][j] = k[i - 1][j];
}
}
}
return k[n][n];
}
int main() {
int n, w;
cin >> n >> w;
int wt[n];
long long int val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
long long int res = knapsack(w, wt, val, n);
cout << res;
} | #include <bits/stdc++.h>
using namespace std;
long long int knapsack(int W, int wt[], long long int val[], int n) {
long long 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 (j >= wt[i - 1]) {
k[i][j] = max(val[i - 1] + k[i - 1][j - wt[i - 1]], k[i - 1][j]);
} else {
k[i][j] = k[i - 1][j];
}
}
}
return k[n][W];
}
int main() {
int n, w;
cin >> n >> w;
int wt[n];
long long int val[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
long long int res = knapsack(w, wt, val, n);
cout << res;
} | [
"identifier.change",
"variable_access.subscript.index.change",
"function.return_value.change"
] | 965,971 | 965,972 | u961774311 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int mx = 101, mxW = 1e5 + 1;
int w[mx], v[mx], tWeiht, n;
long long dp[mx][mxW];
long long solve(int i, int cWeight) // i->item
{
if (i > n)
return 0;
if (dp[i][cWeight] != -1)
return dp[i][cWeight];
int ret1 = solve(i + 1, cWeight);
int ret2 = 0;
if (w[i] + cWeight <= tWeiht)
ret2 = v[i] + solve(i + 1, cWeight + w[i]);
return dp[i][cWeight] = max(ret1, ret2);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
cin >> n >> tWeiht;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof dp);
cout << solve(1, 0);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int mx = 101, mxW = 1e5 + 1;
int w[mx], v[mx], tWeiht, n;
long long dp[mx][mxW];
long long solve(int i, int cWeight) // i->item
{
if (i > n)
return 0;
if (dp[i][cWeight] != -1)
return dp[i][cWeight];
long long ret1 = solve(i + 1, cWeight);
long long ret2 = 0;
if (w[i] + cWeight <= tWeiht)
ret2 = v[i] + solve(i + 1, cWeight + w[i]);
return dp[i][cWeight] = max(ret1, ret2);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
cin >> n >> tWeiht;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof dp);
cout << solve(1, 0);
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,973 | 965,974 | u507086371 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int mx = 101, mxW = 1e5 + 1;
int w[mx], v[mx], tWeiht, n;
int dp[mx][mxW];
long long solve(int i, int cWeight) // i->item
{
if (i > n)
return 0;
if (dp[i][cWeight] != -1)
return dp[i][cWeight];
int ret1 = solve(i + 1, cWeight);
int ret2 = 0;
if (w[i] + cWeight <= tWeiht)
ret2 = v[i] + solve(i + 1, cWeight + w[i]);
return dp[i][cWeight] = max(ret1, ret2);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
cin >> n >> tWeiht;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof dp);
cout << solve(1, 0);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int mx = 101, mxW = 1e5 + 1;
int w[mx], v[mx], tWeiht, n;
long long dp[mx][mxW];
long long solve(int i, int cWeight) // i->item
{
if (i > n)
return 0;
if (dp[i][cWeight] != -1)
return dp[i][cWeight];
long long ret1 = solve(i + 1, cWeight);
long long ret2 = 0;
if (w[i] + cWeight <= tWeiht)
ret2 = v[i] + solve(i + 1, cWeight + w[i]);
return dp[i][cWeight] = max(ret1, ret2);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt","r",stdin);
cin >> n >> tWeiht;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof dp);
cout << solve(1, 0);
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,975 | 965,974 | u507086371 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ll long long
#define N 100005
#define M 1000000007
#define pb push_back
#define p_q priority_queue
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define endl '\n'
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a, n, b) \
for (ll int i = 0; i < n; i++) \
a[i] = 0;
#define cset(a) __builtin_popcountll(a)
#define hell (ull)1e9
#define re resize
signed main(void) {
ios int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, W;
cin >> n >> W;
int v[n + 1];
int w[n + 1];
rep(i, 1, n + 1) { cin >> w[i] >> v[i]; }
int dp[n + 1][W];
rep(i, 0, W) dp[0][i] = 0;
rep(i, 1, n + 1) {
rep(j, 0, W + 1) {
if (w[i] <= j)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W];
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ull unsigned long long
#define ll long long
#define N 100005
#define M 1000000007
#define pb push_back
#define p_q priority_queue
#define pii pair<ll, ll>
#define vi vector<ll>
#define vii vector<pii>
#define mi map<ll, ll>
#define mii map<pii, ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define endl '\n'
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ini(a, n, b) \
for (ll int i = 0; i < n; i++) \
a[i] = 0;
#define cset(a) __builtin_popcountll(a)
#define hell (ull)1e9
#define re resize
signed main(void) {
ios int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, W;
cin >> n >> W;
int v[n + 1];
int w[n + 1];
rep(i, 1, n + 1) { cin >> w[i] >> v[i]; }
int dp[n + 1][W + 1];
rep(i, 0, W + 1) dp[0][i] = 0;
rep(i, 1, n + 1) {
rep(j, 0, W + 1) {
if (w[i] <= j)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W];
}
} | [
"assignment.change"
] | 965,978 | 965,979 | u719660991 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()
const int N = 110;
const int M = 100010;
int w[N], v[N], f[N][M], n, max_w;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> max_w;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= max_w; i++) {
f[n - 1][i] = (w[n - 1] <= i) * v[n - 1];
}
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j <= max_w; j++) {
f[i][j] = f[i + 1][j];
if (j >= w[i]) {
int t = v[i] + f[i + 1][j - w[i]];
f[i][j] = max(f[i][j], t);
}
}
}
cout << f[0][max_w] << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()
const int N = 110;
const int M = 100010;
ll w[N], v[N], f[N][M], n, max_w;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> max_w;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= max_w; i++) {
f[n - 1][i] = (w[n - 1] <= i) * v[n - 1];
}
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j <= max_w; j++) {
f[i][j] = f[i + 1][j];
if (j >= w[i]) {
ll t = v[i] + f[i + 1][j - w[i]];
f[i][j] = max(f[i][j], t);
}
}
}
cout << f[0][max_w] << "\n";
}
| [
"variable_declaration.type.change"
] | 965,980 | 965,981 | u350267480 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const long long INF = 1e15;
int main() {
long long n, w;
cin >> n >> w;
long long dp[n + 1][w + 1] = {0};
vector<long long> weight(n), value(n);
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= w; j++) {
if (weight[i] <= j)
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]);
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
}
}
long long ans = dp[n][w];
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const long long INF = 1e15;
int main() {
long long n, w;
cin >> n >> w;
long long dp[n + 1][w + 1] = {};
vector<long long> weight(n), value(n);
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= w; j++) {
if (weight[i] <= j)
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]);
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
}
}
long long ans = dp[n][w];
cout << ans << endl;
return 0;
} | [] | 965,988 | 965,989 | u191484928 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define sz 100005
typedef long long ll;
int arr[101];
int brr[101];
ll dp[101][sz];
int cal(int n, int val) {
if (n <= 0)
return 0;
if (val <= 0)
return 0;
if (dp[n][val] != -1)
return dp[n][val];
ll a = cal(n - 1, val);
ll b = 0;
if (val - arr[n] >= 0) {
b = brr[n] + cal(n - 1, val - arr[n]);
}
return dp[n][val] = max(a, b);
}
int main() {
int n, val;
cin >> n >> val;
for (int i = 1; i <= n; i++) {
cin >> arr[i] >> brr[i];
}
memset(dp, -1, sizeof(dp));
cout << cal(n, val);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define sz 100005
typedef long long ll;
int arr[101];
int brr[101];
ll dp[101][sz];
ll cal(int n, int val) {
if (n <= 0)
return 0;
if (val <= 0)
return 0;
if (dp[n][val] != -1)
return dp[n][val];
ll a = cal(n - 1, val);
ll b = 0;
if (val - arr[n] >= 0) {
b = brr[n] + cal(n - 1, val - arr[n]);
}
return dp[n][val] = max(a, b);
}
int main() {
int n, val;
cin >> n >> val;
for (int i = 1; i <= n; i++) {
cin >> arr[i] >> brr[i];
}
memset(dp, -1, sizeof(dp));
cout << cal(n, val);
return 0;
}
| [] | 965,992 | 965,993 | u842204282 | cpp |
p03163 | // Space O(C)
#include <iostream>
#include <vector>
using namespace std;
int n, c;
int main() {
scanf("%d %d", &n, &c);
vector<int> w(n), v(n);
for (int i = 0; i < n; ++i) {
scanf("%d %d", &w[i], &v[i]);
}
// dp[i][j] := maximum total value of a subset of the first i items, with
// total size at most j
vector<long long> dp(c + 1, 0);
for (int j = 0; j <= c; ++j) {
dp[j] = 0;
}
for (int i = 1; i <= n; ++i) {
vector<long long> cur(c + 1, 0);
for (int j = 0; j <= c; ++j) {
if (j < w[i - 1])
cur[j] = dp[j];
else
cur[j] = max(dp[j], dp[j - w[i - 1]] + v[i - 1]);
}
}
printf("%lld\n", dp[c]);
return 0;
}
| // Space O(C), Time O(NC)
#include <iostream>
#include <vector>
using namespace std;
int n, c;
int main() {
scanf("%d %d", &n, &c);
vector<int> w(n), v(n);
for (int i = 0; i < n; ++i) {
scanf("%d %d", &w[i], &v[i]);
}
// dp[i][j] := maximum total value of a subset of the first i items, with
// total size at most j
vector<long long> dp(c + 1, 0);
for (int j = 0; j <= c; ++j) {
dp[j] = 0;
}
for (int i = 1; i <= n; ++i) {
vector<long long> cur(c + 1, 0);
for (int j = 0; j <= c; ++j) {
if (j < w[i - 1])
cur[j] = dp[j];
else
cur[j] = max(dp[j], dp[j - w[i - 1]] + v[i - 1]);
}
dp = cur;
}
printf("%lld\n", dp[c]);
return 0;
} | [
"assignment.add"
] | 965,994 | 965,995 | u773308454 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
struct item {
int w;
int v;
};
long long int knapsack(vector<item> arr, int c, int n) {
long long int dp[n + 1][c + 1];
memset(dp, 0, sizeof dp);
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 0; i <= c; i++) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= c; j++) {
if (j >= arr[i - 1].w)
dp[i][j] = max(dp[i][j], arr[i - 1].v + dp[i - 1][j - arr[i - 1].w]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][c];
}
int main() {
int n;
cin >> n;
int c;
cin >> c;
vector<item> arr;
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
item t;
t.w = w;
t.v = v;
arr.push_back(t);
}
cout << knapsack(arr, c, n);
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
struct item {
int w;
int v;
};
long long int knapsack(vector<item> arr, int c, int n) {
long long int dp[n + 1][c + 1];
memset(dp, 0, sizeof dp);
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 0; i <= c; i++) {
dp[0][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= c; j++) {
if (j >= arr[i - 1].w)
dp[i][j] =
max(dp[i - 1][j], arr[i - 1].v + dp[i - 1][j - arr[i - 1].w]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][c];
}
int main() {
int n;
cin >> n;
int c;
cin >> c;
vector<item> arr;
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
item t;
t.w = w;
t.v = v;
arr.push_back(t);
}
cout << knapsack(arr, c, n);
return 0;
}
| [
"assignment.change"
] | 965,998 | 965,999 | u737527091 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int floor(int a, int b) { return (a + b - 1) / b; };
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
int dp[100][100001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << setiosflags(ios::fixed);
int n, W;
cin >> n >> W;
vi w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
rep(i, n) rep(j, W + 1) {
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]);
}
}
cout << dp[n][W] << en;
} | #include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int floor(int a, int b) { return (a + b - 1) / b; };
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
ll dp[101][100001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << setiosflags(ios::fixed);
int n, W;
cin >> n >> W;
vi w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
rep(i, n) rep(j, W + 1) {
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]);
}
}
cout << dp[n][W] << en;
} | [
"variable_declaration.type.change",
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 966,000 | 966,001 | u225388820 | cpp |
p03163 | /* Simplicity and Goodness */
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int N = 2e5 + 2;
int dp[102][N];
void solve() {
int n, w;
scn(n);
scn(w);
vi wt(n + 1), val(n + 1);
rep(i, 1, n + 1) {
scn(wt[i]);
scn(val[i]);
}
rep(i, 1, N) dp[0][i] = 0;
rep(i, 1, n + 1) {
rep(j, 0, w + 1) {
if (j == 0) {
dp[i][j] = 0;
} else {
if (j >= wt[i]) {
dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - wt[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
}
int mx = dp[n][w];
prin(mx);
}
int main() {
int t = 1;
// scn(t);
while (t--) {
solve();
}
return 0;
} | /* Simplicity and Goodness */
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int N = 2e5 + 2;
ll dp[102][N];
void solve() {
int n, w;
scn(n);
scn(w);
vi wt(n + 1), val(n + 1);
rep(i, 1, n + 1) {
scn(wt[i]);
scn(val[i]);
}
rep(i, 1, N) dp[0][i] = 0;
rep(i, 1, n + 1) {
rep(j, 0, w + 1) {
if (j == 0) {
dp[i][j] = 0;
} else {
if (j >= wt[i]) {
dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - wt[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
}
ll mx = dp[n][w];
lprin(mx);
}
int main() {
int t = 1;
// scn(t);
while (t--) {
solve();
}
return 0;
} | [
"variable_declaration.type.change",
"identifier.change",
"call.function.change"
] | 966,004 | 966,005 | u777549027 | cpp |
p03163 | #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = int(a); i < int(n); i++)
#define OUT freopen("output.txt", "w", stdout)
#define IN freopen("input.txt", "r", stdin)
#define mem(a, b) memset((a), (b), sizeof(a))
#define NumofDigits(n) ((int)log10(n) + 1)
#define NumofBits(n) ((int)log2(n) + 1)
#define PI 3.14159265358979323846264
#define vii vector<pair<int, int>>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define nl cout << "\n"
#define pb push_back
#define mp make_pair
#define ll long long
#define ss second
#define ff first
#define endl "\n"
#define sp " "
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1; // cin>>t;
while (t--) {
ll n, W;
cin >> n >> W;
ll w[n], val[n];
rep(i, 0, n) cin >> w[i] >> val[i];
ll ar[n + 1][W + 1];
rep(i, 0, n + 1) ar[i][0] = 0;
rep(i, 0, W + 1) ar[0][i] = 0;
rep(i, 1, n + 1) {
rep(j, 1, W + 1) {
if (w[i - 1] <= j)
ar[i][j] = max(val[i - 1] + ar[i - 1][W - w[i - 1]], ar[i - 1][W]);
else
ar[i][j] = ar[i - 1][W];
}
}
/*rep(i,0,n+1){rep(j,0,W+1)cout<<ar[i][j]<<sp;nl;}*/
cout << ar[n][W];
}
}
| #include <bits/stdc++.h>
#define rep(i, a, n) for (int i = int(a); i < int(n); i++)
#define OUT freopen("output.txt", "w", stdout)
#define IN freopen("input.txt", "r", stdin)
#define mem(a, b) memset((a), (b), sizeof(a))
#define NumofDigits(n) ((int)log10(n) + 1)
#define NumofBits(n) ((int)log2(n) + 1)
#define PI 3.14159265358979323846264
#define vii vector<pair<int, int>>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define nl cout << "\n"
#define pb push_back
#define mp make_pair
#define ll long long
#define ss second
#define ff first
#define endl "\n"
#define sp " "
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t = 1; // cin>>t;
while (t--) {
ll n, W;
cin >> n >> W;
ll w[n], val[n];
rep(i, 0, n) cin >> w[i] >> val[i];
ll ar[n + 1][W + 1];
rep(i, 0, n + 1) ar[i][0] = 0;
rep(i, 0, W + 1) ar[0][i] = 0;
rep(i, 1, n + 1) {
rep(j, 1, W + 1) {
if (w[i - 1] <= j)
ar[i][j] = max(val[i - 1] + ar[i - 1][j - w[i - 1]], ar[i - 1][j]);
else
ar[i][j] = ar[i - 1][j];
}
}
/*rep(i,0,n+1){rep(j,0,W+1)cout<<ar[i][j]<<sp;nl;}*/
cout << ar[n][W];
}
}
| [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 966,017 | 966,018 | u055038081 | cpp |
p03163 | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int mx = 1e5 + 123;
#define mem(a, b) memset(a, b, sizeof(a));
int w[120], v[120], W, n;
long long dp[120][mx];
long long solve(int i, int j) {
if (i > n)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
long long left = 0, right = 0;
if (j + w[i] <= W)
3;
left = v[i] + solve(i + 1, j + w[i]);
right = solve(i + 1, j);
return dp[i][j] = max(left, right);
}
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
mem(dp, -1);
cout << solve(1, 0) << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int mx = 1e5 + 123;
#define mem(a, b) memset(a, b, sizeof(a));
int w[120], v[120], W, n;
long long dp[120][mx];
long long solve(int i, int j) {
if (i > n)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
long long left = 0, right = 0;
if (j + w[i] <= W)
left = v[i] + solve(i + 1, j + w[i]);
right = solve(i + 1, j);
return dp[i][j] = max(left, right);
}
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
mem(dp, -1);
cout << solve(1, 0) << endl;
return 0;
} | [] | 966,030 | 966,031 | u866491819 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i, n, k) for (int i = 0; i < n; i = i + k)
#define forpn(p, n, k) for (int i = p; i < n; i += k)
#define for0(n) for (int i = 0; i < n; i++)
#define for1(n) for (int i = 1; i <= n; i++)
using namespace std;
int no_of_bits(long long n) {
int count = 0;
while (n > 0) {
n = n >> 1;
count++;
}
return count;
}
long long gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isPrime(int n) {
if (n == 1) {
return false;
}
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
return false;
}
i += 1;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
int t;
// cin>>t;
t = 1;
cin.tie(0);
cout.tie(0);
while (t--) {
int n, w;
cin >> n >> w;
vector<ll> dp(w + 1);
for (int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
for (ll j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[n] << endl;
}
}
| #include <bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i, n, k) for (int i = 0; i < n; i = i + k)
#define forpn(p, n, k) for (int i = p; i < n; i += k)
#define for0(n) for (int i = 0; i < n; i++)
#define for1(n) for (int i = 1; i <= n; i++)
using namespace std;
int no_of_bits(long long n) {
int count = 0;
while (n > 0) {
n = n >> 1;
count++;
}
return count;
}
long long gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isPrime(int n) {
if (n == 1) {
return false;
}
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
return false;
}
i += 1;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
int t;
// cin>>t;
t = 1;
cin.tie(0);
cout.tie(0);
while (t--) {
int n, w;
cin >> n >> w;
vector<ll> dp(w + 1);
for (ll i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
for (ll j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[w] << endl;
}
}
| [
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change",
"identifier.change",
"variable_access.subscript.index.change",
"io.output.change"
] | 965,785 | 965,786 | u883528203 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i, n, k) for (int i = 0; i < n; i = i + k)
#define forpn(p, n, k) for (int i = p; i < n; i += k)
#define for0(n) for (int i = 0; i < n; i++)
#define for1(n) for (int i = 1; i <= n; i++)
using namespace std;
int no_of_bits(long long n) {
int count = 0;
while (n > 0) {
n = n >> 1;
count++;
}
return count;
}
long long gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isPrime(int n) {
if (n == 1) {
return false;
}
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
return false;
}
i += 1;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
int t;
// cin>>t;
t = 1;
cin.tie(0);
cout.tie(0);
while (t--) {
int n, w;
cin >> n >> w;
vector<int> dp(w + 1);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
for (int j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[w] << endl;
}
}
| #include <bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i, n, k) for (int i = 0; i < n; i = i + k)
#define forpn(p, n, k) for (int i = p; i < n; i += k)
#define for0(n) for (int i = 0; i < n; i++)
#define for1(n) for (int i = 1; i <= n; i++)
using namespace std;
int no_of_bits(long long n) {
int count = 0;
while (n > 0) {
n = n >> 1;
count++;
}
return count;
}
long long gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isPrime(int n) {
if (n == 1) {
return false;
}
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
return false;
}
i += 1;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
int t;
// cin>>t;
t = 1;
cin.tie(0);
cout.tie(0);
while (t--) {
int n, w;
cin >> n >> w;
vector<ll> dp(w + 1);
for (ll i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
for (ll j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[w] << endl;
}
}
| [
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change"
] | 965,787 | 965,786 | u883528203 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i, n, k) for (int i = 0; i < n; i = i + k)
#define forpn(p, n, k) for (int i = p; i < n; i += k)
#define for0(n) for (int i = 0; i < n; i++)
#define for1(n) for (int i = 1; i <= n; i++)
using namespace std;
int no_of_bits(long long n) {
int count = 0;
while (n > 0) {
n = n >> 1;
count++;
}
return count;
}
long long gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isPrime(int n) {
if (n == 1) {
return false;
}
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
return false;
}
i += 1;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
int t;
// cin>>t;
t = 1;
cin.tie(0);
cout.tie(0);
while (t--) {
int n, w;
cin >> n >> w;
vector<int> dp(n + 1);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
for (int j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[n] << endl;
}
}
| #include <bits/stdc++.h>
#define ll long long
#define dbl double
#define forn(i, n, k) for (int i = 0; i < n; i = i + k)
#define forpn(p, n, k) for (int i = p; i < n; i += k)
#define for0(n) for (int i = 0; i < n; i++)
#define for1(n) for (int i = 1; i <= n; i++)
using namespace std;
int no_of_bits(long long n) {
int count = 0;
while (n > 0) {
n = n >> 1;
count++;
}
return count;
}
long long gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isPrime(int n) {
if (n == 1) {
return false;
}
int i = 2;
while (i * i <= n) {
if (n % i == 0) {
return false;
}
i += 1;
}
return true;
}
int main() {
ios::sync_with_stdio(0);
int t;
// cin>>t;
t = 1;
cin.tie(0);
cout.tie(0);
while (t--) {
int n, w;
cin >> n >> w;
vector<ll> dp(w + 1);
for (ll i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
for (ll j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[w] << endl;
}
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change",
"variable_access.subscript.index.change",
"io.output.change"
] | 965,788 | 965,786 | u883528203 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<int> dp(200005);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
for (int j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[w] << " ";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<long long> dp(200005);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
for (int j = w - a; j >= 0; j--) {
dp[j + a] = max(dp[j + a], dp[j] + b);
}
}
cout << dp[w] << " ";
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,789 | 965,790 | u883528203 | 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] = 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() {
// your code goes here
int n, w;
cin >> n >> w;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> b[i] >> a[i];
}
cout << knapSack(w, b, a, n) << endl;
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] = 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() {
// your code goes here
int n, w;
cin >> n >> w;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> b[i] >> a[i];
}
cout << knapSack(w, b, a, n) << endl;
return 0;
} | [
"variable_declaration.type.widen.change"
] | 965,801 | 965,802 | u219874809 | cpp |
p03163 | #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int wi[100001], vi[100001];
long long dp[105][100005];
int solve(int n, int w) {
if (n == 0 || w == 0)
return 0;
if (dp[n - 1][w] != -1)
return dp[n - 1][w];
if (wi[n - 1] > w) {
return dp[n - 1][w] = solve(n - 1, w);
}
return dp[n - 1][w] =
max(solve(n - 1, w), solve(n - 1, w - wi[n - 1]) + vi[n - 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> wi[i] >> vi[i];
};
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i][j] = -1;
}
}
cout << solve(n, w) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int wi[100001], vi[100001];
long long dp[105][100005];
long long solve(int n, int w) {
if (n == 0 || w == 0)
return 0;
if (dp[n - 1][w] != -1)
return dp[n - 1][w];
if (wi[n - 1] > w) {
return dp[n - 1][w] = solve(n - 1, w);
}
return dp[n - 1][w] =
max(solve(n - 1, w), solve(n - 1, w - wi[n - 1]) + vi[n - 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> wi[i] >> vi[i];
};
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i][j] = -1;
}
}
cout << solve(n, w) << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,803 | 965,804 | u928828066 | cpp |
p03163 | #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int wi[100001], vi[100001];
int dp[105][100005];
int solve(int n, int w) {
if (n == 0 || w == 0)
return 0;
if (dp[n - 1][w] != -1)
return dp[n - 1][w];
if (wi[n - 1] > w) {
return dp[n - 1][w] = solve(n - 1, w);
}
return dp[n - 1][w] =
max(solve(n - 1, w), solve(n - 1, w - wi[n - 1]) + vi[n - 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> wi[i] >> vi[i];
};
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i][j] = -1;
}
}
cout << solve(n, w) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int wi[100001], vi[100001];
long long dp[105][100005];
long long solve(int n, int w) {
if (n == 0 || w == 0)
return 0;
if (dp[n - 1][w] != -1)
return dp[n - 1][w];
if (wi[n - 1] > w) {
return dp[n - 1][w] = solve(n - 1, w);
}
return dp[n - 1][w] =
max(solve(n - 1, w), solve(n - 1, w - wi[n - 1]) + vi[n - 1]);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> wi[i] >> vi[i];
};
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i][j] = -1;
}
}
cout << solve(n, w) << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,805 | 965,804 | u928828066 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
class item {
public:
int weight;
ll value;
};
ll Knapsack1(vector<item> v, int n, int w) {
ll dp[n + 1][w + 1];
for (int wt = 0; wt <= w; wt++)
dp[1][wt] = 0;
dp[1][v[1].weight] = v[1].value;
for (int i = 2; i <= n; i++) {
for (int wt = 0; wt <= w; wt++) {
dp[i][wt] = dp[i - 1][wt];
if (v[i].weight > w)
continue;
dp[i][wt] = max(dp[i][wt], v[i].value + dp[i - 1][w - v[i].weight]);
}
}
return *max_element(dp[n], dp[n] + w + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<item> v(n + 1); // 1 based indexing
for (int i = 1; i <= n; i++)
cin >> v[i].weight >> v[i].value;
cout << Knapsack1(v, n, w) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
class item {
public:
int weight;
ll value;
};
ll Knapsack1(vector<item> v, int n, int w) {
ll dp[n + 1][w + 1];
for (int wt = 0; wt <= w; wt++)
dp[1][wt] = 0;
dp[1][v[1].weight] = v[1].value;
for (int i = 2; i <= n; i++) {
for (int wt = 0; wt <= w; wt++) {
dp[i][wt] = dp[i - 1][wt];
if (v[i].weight > wt)
continue;
dp[i][wt] = max(dp[i][wt], v[i].value + dp[i - 1][wt - v[i].weight]);
}
}
return *max_element(dp[n], dp[n] + w + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<item> v(n + 1); // 1 based indexing
for (int i = 1; i <= n; i++)
cin >> v[i].weight >> v[i].value;
cout << Knapsack1(v, n, w) << endl;
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,806 | 965,807 | u519412059 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, j;
ll n, goal_weight;
ll w[105], v[105];
ll ans;
ll dp[105][100005];
ll fun(ll count, ll current_weight) {
if (count == n)
return 0;
if (dp[count][current_weight] != -1) {
return dp[count][current_weight];
}
ans = fun(count + 1, current_weight);
if (w[count] + current_weight <= goal_weight) {
ans = max(ans, fun(count + 1, current_weight + w[count]) + v[count]);
}
return dp[count][current_weight] = ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> goal_weight;
memset(dp, -1, sizeof dp);
for (i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << fun(0, 0) << endl;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, j;
ll n, goal_weight;
ll w[105], v[105];
ll dp[105][100005];
ll fun(ll count, ll current_weight) {
if (count == n)
return 0;
if (dp[count][current_weight] != -1) {
return dp[count][current_weight];
}
ll ans = fun(count + 1, current_weight);
if (w[count] + current_weight <= goal_weight) {
ans = max(ans, fun(count + 1, current_weight + w[count]) + v[count]);
}
return dp[count][current_weight] = ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> goal_weight;
memset(dp, -1, sizeof dp);
for (i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << fun(0, 0) << endl;
}
| [
"variable_declaration.remove"
] | 965,810 | 965,811 | u075311636 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int mxN = 1e2 + 5;
const int mxM = 1e5 + 5;
int dp[mxN][mxM];
int n, w, wei[mxN], val[mxN];
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> wei[i] >> val[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (j - wei[i] >= 0 && i - 1 >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wei[i]] + val[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
int ans = 0;
// for(int i =1; i<=n; i++){
// for(int j = 1; j<=w; j++){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
for (int i = 0; i <= n; i++) {
ans = max(ans, dp[i][w]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const int mxN = 1e2 + 5;
const int mxM = 1e5 + 5;
long long dp[mxN][mxM];
long long n, w, wei[mxN], val[mxN];
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> wei[i] >> val[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (j - wei[i] >= 0 && i - 1 >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wei[i]] + val[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
long long ans = 0;
// for(int i =1; i<=n; i++){
// for(int j = 1; j<=w; j++){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
for (int i = 0; i <= n; i++) {
ans = max(ans, dp[i][w]);
}
cout << ans << endl;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,816 | 965,817 | u464846946 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int w;
cin >> n >> w;
int wt[n];
int 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 = 0; 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(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];
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int w;
cin >> n >> w;
long long int wt[n];
long long int 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 = 0; 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(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];
}
| [
"variable_declaration.type.widen.change"
] | 965,829 | 965,830 | u348267046 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int l;
l knapsack(l wt[], l v[], l W, l n) {
l dp[n + 1][W + 1];
for (l i = 0; i <= n; i++) {
for (l w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (wt[i - 1] <= W) {
dp[i][w] = max(v[i - 1] + dp[i - 1][W - wt[i - 1]], dp[i - 1][w]);
} else
dp[i][w] = dp[i - 1][w];
}
}
return dp[n][W];
}
int main() {
l n, W;
cin >> n >> W;
l v[n], w[n];
for (l i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(w, v, W, n) << "\n";
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long int l;
l knapsack(l wt[], l v[], l W, l n) {
l dp[n + 1][W + 1];
for (l i = 0; i <= n; i++) {
for (l w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (wt[i - 1] <= w) {
dp[i][w] = max(v[i - 1] + dp[i - 1][w - wt[i - 1]], dp[i - 1][w]);
} else
dp[i][w] = dp[i - 1][w];
}
}
return dp[n][W];
}
int main() {
l n, W;
cin >> n >> W;
l v[n], w[n];
for (l i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(w, v, W, n) << "\n";
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,831 | 965,832 | u947215968 | cpp |
p03163 | // R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
void solve() {
int n, w;
cin >> n >> w;
int wt[n], val[n];
rep(i, n) cin >> wt[i] >> val[i];
int dp[n + 1][w + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 0;
rep(i, n + 1) dp[i][0] = 0;
rep(i, w + 1) dp[0][i] = 0;
repA(i, 1, n) {
repA(j, 1, w) {
if (j - wt[i - 1] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| // R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
void solve() {
int n, w;
cin >> n >> w;
int wt[n], val[n];
rep(i, n) cin >> wt[i] >> val[i];
int dp[n + 1][w + 1];
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
rep(i, n + 1) dp[i][0] = 0;
rep(i, w + 1) dp[0][i] = 0;
repA(i, 1, n) {
repA(j, 1, w) {
if (j - wt[i - 1] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| [
"literal.number.change",
"call.arguments.change",
"assignment.change"
] | 965,835 | 965,836 | u229122754 | cpp |
p03163 | // R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
void solve() {
int n, w;
cin >> n >> w;
int wt[n], val[n];
rep(i, n) cin >> wt[i] >> val[i];
int dp[n + 1][w + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 0;
repA(i, 0, n) {
repA(j, 0, w) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (j - wt[i - 1] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[3][8];
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| // R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
void solve() {
int n, w;
cin >> n >> w;
int wt[n], val[n];
rep(i, n) cin >> wt[i] >> val[i];
int dp[n + 1][w + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 0;
repA(i, 0, n) {
repA(j, 0, w) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (j - wt[i - 1] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"io.output.change"
] | 965,838 | 965,839 | u229122754 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define puts(i) cout << i << endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
ll divisor = 1000000007;
int main() {
int n, m;
cin >> n >> m;
int w[n], v[n];
rep(i, n) cin >> w[i] >> v[i];
int dp[m + 1][n + 1] = {};
rep(i, m + 1) {
if (i == 0)
continue;
rep(j, n + 1) {
if (j == 0)
continue;
if (i < w[j - 1]) {
dp[i][j] = dp[i][j - 1];
continue;
}
dp[i][j] = max(dp[i][j - 1], dp[i - w[j - 1]][j - 1] + v[j - 1]);
}
}
puts(dp[m][n]);
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define puts(i) cout << i << endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
#define inf 10000
using ll = long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
ll divisor = 1000000007;
int main() {
ll n, m;
cin >> n >> m;
ll w[n], v[n];
rep(i, n) cin >> w[i] >> v[i];
ll dp[m + 1][n + 1] = {};
rep(i, m + 1) {
if (i == 0)
continue;
rep(j, n + 1) {
if (j == 0)
continue;
if (i < w[j - 1]) {
dp[i][j] = dp[i][j - 1];
continue;
}
dp[i][j] = max(dp[i][j - 1], dp[i - w[j - 1]][j - 1] + v[j - 1]);
}
}
puts(dp[m][n]);
}
| [
"variable_declaration.type.change"
] | 965,840 | 965,841 | u827974318 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int knapscak(ll a[], ll b[], ll n, ll w) {
ll t[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
t[i][j] = 0;
}
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= w; j++) {
if (a[i - 1] <= j) {
t[i][j] = max(b[i - 1] + t[i - 1][j - a[i - 1]], t[i - 1][j]);
} else
t[i][j] = t[i - 1][j];
}
}
return t[n][w];
}
int main() {
ll n, w;
cin >> n >> w;
ll a[n + 1], b[n + 1];
for (ll i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
ll k;
k = knapscak(a, b, n, w);
cout << k << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll knapscak(ll a[], ll b[], ll n, ll w) {
ll t[n + 2][w + 2];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
t[i][j] = 0;
}
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= w; j++) {
if (a[i - 1] <= j) {
t[i][j] = max(b[i - 1] + t[i - 1][j - a[i - 1]], t[i - 1][j]);
} else
t[i][j] = t[i - 1][j];
}
}
return t[n][w];
}
int main() {
ll n, w;
cin >> n >> w;
ll a[n + 1], b[n + 1];
for (ll i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
ll k;
k = knapscak(a, b, n, w);
cout << k << endl;
return 0;
} | [
"literal.number.change",
"expression.operation.binary.change"
] | 965,844 | 965,845 | u814623049 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<int> DP(W + 1);
for (int w, v; cin >> w >> v;) {
for (int i = W; i - w >= 0; i--) {
DP.at(i) = max(DP.at(i), DP.at(i - w) + v);
}
}
cout << *max_element(DP.begin(), DP.end()) << "\n";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<long> DP(W + 1);
for (int w, v; cin >> w >> v;) {
for (int i = W; i - w >= 0; i--) {
DP.at(i) = max(DP.at(i), DP.at(i - w) + v);
}
}
cout << *max_element(DP.begin(), DP.end()) << "\n";
} | [
"variable_declaration.type.primitive.change"
] | 965,847 | 965,848 | u045289115 | cpp |
p03163 | #include <bits/stdc++.h>
#define PB push_back
#define ld long double
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define ios ios_base::sync_with_stdio(0);
#define ll long long
#define open(name) \
freopen(name ".in", "r", stdin); \
freopen(name ".out", "w", stdout);
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int N = 2e5 + 7;
;
const int INF = 2e9 + 7;
const int logg = 20;
const double PI = 3.14;
using namespace std;
void solve() {
int n, sum;
cin >> n >> sum;
int m[n + 7], p[n + 7], dp[n + 7][sum + 7];
for (int i = 1; i <= n; i++)
cin >> m[i] >> p[i];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= sum; j++)
dp[i][j] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= sum; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= m[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - m[i]] + p[i]);
}
}
}
cout << dp[n][sum];
}
int main() {
ios;
solve();
}
| #include <bits/stdc++.h>
#define PB push_back
#define ld long double
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
#define ios ios_base::sync_with_stdio(0);
#define ll long long
#define open(name) \
freopen(name ".in", "r", stdin); \
freopen(name ".out", "w", stdout);
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int N = 2e5 + 7;
;
const int INF = 2e9 + 7;
const int logg = 20;
const double PI = 3.14;
using namespace std;
void solve() {
int n, sum;
cin >> n >> sum;
ll m[n + 7], p[n + 7], dp[n + 7][sum + 7];
for (int i = 1; i <= n; i++)
cin >> m[i] >> p[i];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= sum; j++)
dp[i][j] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= sum; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= m[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - m[i]] + p[i]);
}
}
}
cout << dp[n][sum];
}
int main() {
ios;
solve();
}
| [
"variable_declaration.type.change"
] | 965,852 | 965,853 | u791636240 | cpp |
p03163 | #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
using namespace std;
int root(int arr[], int i) {
while (arr[i] != i) {
arr[i] = arr[arr[i]];
i = arr[i];
}
return i;
}
void Union(int arr[], int Size[], int a, int b) {
int rootA = root(arr, a);
int rootB = root(arr, b);
if (Size[rootA] < Size[rootB]) {
arr[rootA] = arr[rootB];
Size[rootB] += Size[rootA];
} else {
arr[rootB] = arr[rootA];
Size[rootA] += Size[rootB];
}
}
bool findRoot(int a, int b, int arr[]) {
if (root(arr, a) == root(arr, b))
return true;
else
return false;
}
vector<vector<int>> adj(105);
bool nCyc = false;
/*void dijkstra(int v,long long dis[]){
dis[v]=0;
multiset<pair<int,int> >s;
s.insert({0,v});
while(!s.empty()){
pair<int,int>p= *s.begin();
s.erase(s.begin());
int x=p.second;
if(vis[x])continue;
vis[x]=1;
for(int i=0;i<adj[x].size();i++){
int e=adj[x][i].first,w=adj[x][i].second;
// cout<<dis[e]<<" "<<dis[x]+w<<endl;
if(dis[e]>dis[x]+w){
dis[e]=dis[x]+w;
s.insert(make_pair(dis[e],e));
}
}
}
}*/
/*void bfs(int s){
queue<int>q;
q.push(s);
while(!q.empty()){
int v=q.front();
q.pop();
for(int i=0;i<adj[v].size();i++){
if(!vis[adj[v][i]]){
q.push(adj[v][i]);
vis[adj[v][i]]=1;
}
}
}
}*/
int vis[55][55];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*bool isVal(int i,int j){
if(i<0 || j<0 || j>=m || i>=n)return false;
return true;
}*/
/*void dfs(int i,int j) {
if(!isVal(i,j) || vis[i][j] || arr[i][j]=='#')return;
vis[i][j]=1;
if(arr[i][j]=='G'){
check++;
}
if(arr[i][j]=='B'){
b=1;
return;
}
for(int k=0;k<4;k++){
int pos1=i+dx[k],pos2=j+dy[k];
// cout<<pos1<<" "<<pos2<<endl;
if( isVal(pos1,pos2) && (arr[pos1][pos2]=='#'))continue;
dfs(pos1,pos2);
}
}
void dfs2(int i,int j){
if(isVal(i,j)==false || arr[i][j]!='.')return;
arr[i][j]='#';
}*/
/*
double prim(int x){
priority_queue<pair<double,int>,vector<pair<double,int>
>,greater<pair<double,int> > >q; double min_cost=0.0; pair<double,int>p;
q.push(make_pair(0.0,x));
while(!q.empty()){
p=q.top();
q.pop();
x=p.second;
if(vis[x])continue;
min_cost+=p.first;
vis[x]=1;
for(int i=0;i<adj[x].size();i++){
int y=adj[x][i].second;
if(!vis[y]){
q.push(adj[x][i]);
}
}
}
return min_cost;
}*/
int n;
int dp[105][100005];
vector<pair<long long, long long>> v(105);
long long solve(int i, int W) {
if (i == n || W == 0)
return 0;
if (dp[i][W] != -1)
return dp[i][W];
if (v[i].first > W)
return solve(i + 1, W);
return dp[i][W] =
max(v[i].second + solve(i + 1, W - v[i].first), solve(i + 1, W));
}
int freq[1000005], check[1000005];
int main() {
int W;
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> v[i].first >> v[i].second;
memset(dp, -1, sizeof dp);
cout << solve(0, W);
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
using namespace std;
int root(int arr[], int i) {
while (arr[i] != i) {
arr[i] = arr[arr[i]];
i = arr[i];
}
return i;
}
void Union(int arr[], int Size[], int a, int b) {
int rootA = root(arr, a);
int rootB = root(arr, b);
if (Size[rootA] < Size[rootB]) {
arr[rootA] = arr[rootB];
Size[rootB] += Size[rootA];
} else {
arr[rootB] = arr[rootA];
Size[rootA] += Size[rootB];
}
}
bool findRoot(int a, int b, int arr[]) {
if (root(arr, a) == root(arr, b))
return true;
else
return false;
}
vector<vector<int>> adj(105);
bool nCyc = false;
/*void dijkstra(int v,long long dis[]){
dis[v]=0;
multiset<pair<int,int> >s;
s.insert({0,v});
while(!s.empty()){
pair<int,int>p= *s.begin();
s.erase(s.begin());
int x=p.second;
if(vis[x])continue;
vis[x]=1;
for(int i=0;i<adj[x].size();i++){
int e=adj[x][i].first,w=adj[x][i].second;
// cout<<dis[e]<<" "<<dis[x]+w<<endl;
if(dis[e]>dis[x]+w){
dis[e]=dis[x]+w;
s.insert(make_pair(dis[e],e));
}
}
}
}*/
/*void bfs(int s){
queue<int>q;
q.push(s);
while(!q.empty()){
int v=q.front();
q.pop();
for(int i=0;i<adj[v].size();i++){
if(!vis[adj[v][i]]){
q.push(adj[v][i]);
vis[adj[v][i]]=1;
}
}
}
}*/
int vis[55][55];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*bool isVal(int i,int j){
if(i<0 || j<0 || j>=m || i>=n)return false;
return true;
}*/
/*void dfs(int i,int j) {
if(!isVal(i,j) || vis[i][j] || arr[i][j]=='#')return;
vis[i][j]=1;
if(arr[i][j]=='G'){
check++;
}
if(arr[i][j]=='B'){
b=1;
return;
}
for(int k=0;k<4;k++){
int pos1=i+dx[k],pos2=j+dy[k];
// cout<<pos1<<" "<<pos2<<endl;
if( isVal(pos1,pos2) && (arr[pos1][pos2]=='#'))continue;
dfs(pos1,pos2);
}
}
void dfs2(int i,int j){
if(isVal(i,j)==false || arr[i][j]!='.')return;
arr[i][j]='#';
}*/
/*
double prim(int x){
priority_queue<pair<double,int>,vector<pair<double,int>
>,greater<pair<double,int> > >q; double min_cost=0.0; pair<double,int>p;
q.push(make_pair(0.0,x));
while(!q.empty()){
p=q.top();
q.pop();
x=p.second;
if(vis[x])continue;
min_cost+=p.first;
vis[x]=1;
for(int i=0;i<adj[x].size();i++){
int y=adj[x][i].second;
if(!vis[y]){
q.push(adj[x][i]);
}
}
}
return min_cost;
}*/
int n;
long long dp[105][100005];
vector<pair<long long, long long>> v(105);
long long solve(int i, int W) {
if (i == n || W == 0)
return 0;
if (dp[i][W] != -1)
return dp[i][W];
if (v[i].first > W)
return solve(i + 1, W);
return dp[i][W] =
max(v[i].second + solve(i + 1, W - v[i].first), solve(i + 1, W));
}
int freq[1000005], check[1000005];
int main() {
int W;
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> v[i].first >> v[i].second;
memset(dp, -1, sizeof dp);
cout << solve(0, W);
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,856 | 965,857 | u377640743 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(), v.end()
#define vil vector<long int>
#define vi vector<int>
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007
#define MOD 998244353
void solve(ll T) {
int n, w;
cin >> n >> w;
vi a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> b[i] >> a[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 >= b[i - 1]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
} else {
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);
ll T;
T = 1;
// cin>>T;
while (T--) {
solve(T);
return 0;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(), v.end()
#define vil vector<long int>
#define vi vector<int>
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007
#define MOD 998244353
void solve(ll T) {
int n, w;
cin >> n >> w;
vil a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> b[i] >> a[i];
}
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 (j >= b[i - 1]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
} else {
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);
ll T;
T = 1;
// cin>>T;
while (T--) {
solve(T);
return 0;
}
} | [
"variable_declaration.type.change"
] | 965,863 | 965,864 | u206487738 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(), v.end()
#define vil vector<long int>
#define vi vector<int>
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007
#define MOD 998244353
void solve(ll T) {
int n, w;
cin >> n >> w;
vi a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[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 >= b[i - 1]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
} else {
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);
ll T;
T = 1;
// cin>>T;
while (T--) {
solve(T);
return 0;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(), v.end()
#define vil vector<long int>
#define vi vector<int>
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007
#define MOD 998244353
void solve(ll T) {
int n, w;
cin >> n >> w;
vil a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> b[i] >> a[i];
}
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 (j >= b[i - 1]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
} else {
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);
ll T;
T = 1;
// cin>>T;
while (T--) {
solve(T);
return 0;
}
} | [
"variable_declaration.type.change",
"identifier.change",
"expression.operation.binary.change"
] | 965,865 | 965,864 | u206487738 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(), v.end()
#define vil vector<long int>
#define vi vector<int>
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007
#define MOD 998244353
void solve(ll T) {
int n, w;
cin >> n >> w;
vi a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[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 >= b[i - 1]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i]] + a[i - 1]);
} else {
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);
ll T;
T = 1;
// cin>>T;
while (T--) {
solve(T);
return 0;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.14159265359
#define all(v) v.begin(), v.end()
#define vil vector<long int>
#define vi vector<int>
#define pb(x) push_back(x)
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ub upper_bound
#define lb lower_bound
#define INF 1000000007
#define MOD 998244353
void solve(ll T) {
int n, w;
cin >> n >> w;
vil a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> b[i] >> a[i];
}
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 (j >= b[i - 1]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]);
} else {
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);
ll T;
T = 1;
// cin>>T;
while (T--) {
solve(T);
return 0;
}
} | [
"variable_declaration.type.change",
"identifier.change",
"expression.operation.binary.change",
"assignment.change"
] | 965,866 | 965,864 | u206487738 | cpp |
p03163 | // A Dynamic Programming based solution for Knapsack problem
#include <iomanip>
#include <iostream>
using namespace std;
long long knapSack01(long long W, int weight[], int val[], int n) {
long long F[n + 1][W + 1];
// Build table K[][] in bottom up manner
for (int k = 0; k <= n; k++) {
for (int w = 0; w <= W; w++) {
if (k == 0 || w == 0)
F[k][w] = 0;
else if (weight[k - 1] <= w)
F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]);
else
F[k][w] = F[k - 1][w];
}
}
return F[n][W];
}
int main() {
std::ios::sync_with_stdio(false);
long long n, W;
std::cin >> W >> n;
int *val = new int[n];
int *wt = new int[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
std::cout << knapSack01(W, wt, val, n) << endl;
delete[] val;
delete[] wt;
return 0;
} | // A Dynamic Programming based solution for Knapsack problem
#include <iomanip>
#include <iostream>
using namespace std;
long long knapSack01(long long W, int weight[], int val[], int n) {
long long F[n + 1][W + 1];
// Build table K[][] in bottom up manner
for (int k = 0; k <= n; k++) {
for (int w = 0; w <= W; w++) {
if (k == 0 || w == 0)
F[k][w] = 0;
else if (weight[k - 1] <= w)
F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]);
else
F[k][w] = F[k - 1][w];
}
}
return F[n][W];
}
int main() {
std::ios::sync_with_stdio(false);
long long n, W;
std::cin >> n >> W;
int *val = new int[n];
int *wt = new int[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
std::cout << knapSack01(W, wt, val, n) << endl;
delete[] val;
delete[] wt;
return 0;
} | [
"expression.operation.binary.remove"
] | 966,042 | 966,043 | u930153819 | cpp |
p03163 | // A Dynamic Programming based solution for Knapsack problem
#include <iomanip>
#include <iostream>
using namespace std;
// A utility function that returns maximum of two integers
// int max(int a, int b) { return (a > b)? a : b; }
// Returns the maximum value that can be put in a knapsack of capacity W
// long long knapSack01(int W, int weight[], int val[], int n)
//{
// int k, w;
// long long **F = new long long *[n+1];
// for(int i=0;i<n+1;i++)
// F[i]= new long long[W+1];
//
// // Build table K[][] in bottom up manner
// for (k = 0; k <= n; k++)
// {
// for (w = 0; w <= W; w++)
// {
// if (k==0 || w==0)
// F[k][w] = 0;
// else if (weight[k-1] <= w)
// F[k][w] = max(F[k-1][w],
//F[k-1][w-weight[k-1]]+val[k-1]); else F[k][w] = F[k-1][w];
// //cout<<std::setw(2)<<F[k][w]<<" ";
// }
// //cout<<endl;
// }
// long long result = F[n][W];
// for(int i=0;i<n+1;i++)
// delete []F[i];
// delete []F;
// return result;
//}
long long knapSack01(int W, int weight[], int val[], int n) {
long long F[n + 1][W + 1];
// Build table K[][] in bottom up manner
for (int k = 0; k <= n; k++) {
for (int w = 0; w <= W; w++) {
if (k == 0 || w == 0)
F[k][w] = 0;
else if (weight[k - 1] <= w)
F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]);
else
F[k][w] = F[k - 1][w];
}
}
return F[n][W];
}
int main() {
std::ios::sync_with_stdio(false);
long long n, W;
std::cin >> W >> n;
int *val = new int[n];
int *wt = new int[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
std::cout << knapSack01(W, wt, val, n) << endl;
delete[] val;
delete[] wt;
return 0;
} | // A Dynamic Programming based solution for Knapsack problem
#include <iomanip>
#include <iostream>
using namespace std;
long long knapSack01(long long W, int weight[], int val[], int n) {
long long F[n + 1][W + 1];
// Build table K[][] in bottom up manner
for (int k = 0; k <= n; k++) {
for (int w = 0; w <= W; w++) {
if (k == 0 || w == 0)
F[k][w] = 0;
else if (weight[k - 1] <= w)
F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]);
else
F[k][w] = F[k - 1][w];
}
}
return F[n][W];
}
int main() {
std::ios::sync_with_stdio(false);
long long n, W;
std::cin >> n >> W;
int *val = new int[n];
int *wt = new int[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
std::cout << knapSack01(W, wt, val, n) << endl;
delete[] val;
delete[] wt;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"expression.operation.binary.remove"
] | 966,044 | 966,043 | u930153819 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
long long int res(vector<long long int> &va, vector<long long int> &we,
long long int n, long long int w) {
long long int a[n + 1][w + 1];
for (long long int i = 0; i <= w; i++) {
a[0][i] = 0;
}
for (long long int i = 1; i <= n; i++) {
for (long long int j = 0; j <= w; j++) {
if (j >= we[i - 1])
a[i][j] = max(a[i - 1][j], a[i - 1][j - we[i - 1]] + va[i - 1]);
else
a[i][j] = a[i - 1][j];
}
}
return a[n][w];
}
int main() {
long long int n, w;
cin >> n >> w;
vector<long long int> we(n);
vector<long long int> va(n);
for (long long int i = 0; i < n; i++) {
cin >> we[i] >> va[i];
}
cout << res(va, we, n - 1, w) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long int res(vector<long long int> &va, vector<long long int> &we,
long long int n, long long int w) {
long long int a[n + 1][w + 1];
for (long long int i = 0; i <= w; i++) {
a[0][i] = 0;
}
for (long long int i = 1; i <= n; i++) {
for (long long int j = 0; j <= w; j++) {
if (j >= we[i - 1])
a[i][j] = max(a[i - 1][j], a[i - 1][j - we[i - 1]] + va[i - 1]);
else
a[i][j] = a[i - 1][j];
}
}
return a[n][w];
}
int main() {
long long int n, w;
cin >> n >> w;
vector<long long int> we(n);
vector<long long int> va(n);
for (long long int i = 0; i < n; i++) {
cin >> we[i] >> va[i];
}
cout << res(va, we, n, w) << endl;
return 0;
} | [
"expression.operation.binary.remove"
] | 966,051 | 966,052 | u498786935 | cpp |
p03163 | /// Bismillahir Rahmanir Rahim
// Author: Tanvir Hussain
// ICE,NSTU
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x, m, n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x, false, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define CLR2d(x, m, n) memset(x, -1, sizeof(x[0][0]) * m * n)
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(), x.end()
#define pb push_back
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(), v.end())
#define maxv(v) *max_element(v.begin(), v.end())
#define cases(cs, t) for (int cs = 1; cs <= t; cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) \
vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end())))
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it, s) for (auto it : s)
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define rep(i, a) for (int i = 0; i < a; i++)
#define rep1(i, a, b) for (int i = (a); i <= (b); ++i)
#define irep(i, b, a) for (int i = (b); i >= (a); --i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx = 100005;
// this fuction sorts vector pair according to first element in descending
// order.
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return a.first > b.first;
}
template <typename T> inline T Bigmod(T base, T power, T MOD) {
T ret = 1;
while (power) {
if (power & 1)
ret = (ret * base) % MOD;
base = (base * base) % MOD;
power >>= 1;
}
return ret;
}
double sq(double x) { return x * x; }
ll po(ll b, ll p) {
ll res = 1;
while (p) {
res *= b;
p--;
}
return res;
}
ll lg2(ll x) {
ll res = 0;
while (x > 1) {
res++;
x /= 2ll;
}
return res;
}
int n, w;
vi wei(maxx), cost(maxx);
int dp[maxx][105];
ll sol(ll w, ll item) {
if (w == 0 or item == 0)
return 0;
if (dp[w][item] != -1)
return dp[w][item];
if (wei[item - 1] <= w)
return dp[w][item] = max(cost[item - 1] + sol(w - wei[item - 1], item - 1),
sol(w, item - 1));
return dp[w][item] = sol(w, item - 1);
}
void solve() {
CLR2d(dp, maxx, 105);
cin >> n >> w;
rep(i, n) { cin >> wei[i] >> cost[i]; }
// sort(wei.begin(),wei.begin()+n);
ll res = sol(w, n);
cout << res << endl;
}
signed main()
{
IOS;
/*#ifndef ONLINE_JUDGE
freopen ("data.in","r",stdin);
freopen ("data.out","w",stdout);
#endif*/
int t;
t = 1;
while (t--) {
solve();
}
return 0;
}
/// Alhamdulillah
| /// Bismillahir Rahmanir Rahim
// Author: Tanvir Hussain
// ICE,NSTU
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x, m, n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x, false, sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define CLR2d(x, m, n) memset(x, -1, sizeof(x[0][0]) * m * n)
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(), x.end()
#define pb push_back
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(), v.end())
#define maxv(v) *max_element(v.begin(), v.end())
#define cases(cs, t) for (int cs = 1; cs <= t; cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) \
vec.resize(distance(vec.begin(), unique(vec.begin(), vec.end())))
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it, s) for (auto it : s)
#define each(it, s) for (auto it = s.begin(); it != s.end(); ++it)
#define rep(i, a) for (int i = 0; i < a; i++)
#define rep1(i, a, b) for (int i = (a); i <= (b); ++i)
#define irep(i, b, a) for (int i = (b); i >= (a); --i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx = 100005;
// this fuction sorts vector pair according to first element in descending
// order.
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return a.first > b.first;
}
template <typename T> inline T Bigmod(T base, T power, T MOD) {
T ret = 1;
while (power) {
if (power & 1)
ret = (ret * base) % MOD;
base = (base * base) % MOD;
power >>= 1;
}
return ret;
}
double sq(double x) { return x * x; }
ll po(ll b, ll p) {
ll res = 1;
while (p) {
res *= b;
p--;
}
return res;
}
ll lg2(ll x) {
ll res = 0;
while (x > 1) {
res++;
x /= 2ll;
}
return res;
}
int n, w;
vi wei(maxx), cost(maxx);
ll dp[maxx][105];
ll sol(ll w, ll item) {
if (w == 0 or item == 0)
return 0;
if (dp[w][item] != -1)
return dp[w][item];
if (wei[item - 1] <= w)
return dp[w][item] = max(cost[item - 1] + sol(w - wei[item - 1], item - 1),
sol(w, item - 1));
return dp[w][item] = sol(w, item - 1);
}
void solve() {
CLR2d(dp, maxx, 105);
cin >> n >> w;
rep(i, n) { cin >> wei[i] >> cost[i]; }
// sort(wei.begin(),wei.begin()+n);
ll res = sol(w, n);
cout << res << endl;
}
signed main()
{
IOS;
/*#ifndef ONLINE_JUDGE
freopen ("data.in","r",stdin);
freopen ("data.out","w",stdout);
#endif*/
int t;
t = 1;
while (t--) {
solve();
}
return 0;
}
/// Alhamdulillah
| [
"variable_declaration.type.change"
] | 966,059 | 966,060 | u341368129 | cpp |
p03163 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef vector<int> vi;
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
void usacoio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
ll dp[105][100005];
int n, maxw;
int w[105];
ll v[105];
int solve(int idx, int ww) {
if (idx == 0)
return 0;
if (dp[idx][ww] >= 0)
return dp[idx][ww];
dp[idx][ww] = solve(idx - 1, ww);
if (w[idx - 1] <= ww)
dp[idx][ww] =
max(dp[idx][ww], v[idx - 1] + solve(idx - 1, ww - w[idx - 1]));
return dp[idx][ww];
}
void solve() {
cin >> n >> maxw;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << solve(n, maxw) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef vector<int> vi;
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
void usacoio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
ll dp[105][100005];
int n, maxw;
int w[105];
ll v[105];
ll solve(int idx, int ww) {
if (idx == 0)
return 0;
if (dp[idx][ww] >= 0)
return dp[idx][ww];
dp[idx][ww] = solve(idx - 1, ww);
if (w[idx - 1] <= ww)
dp[idx][ww] =
max(dp[idx][ww], v[idx - 1] + solve(idx - 1, ww - w[idx - 1]));
return dp[idx][ww];
}
void solve() {
cin >> n >> maxw;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << solve(n, maxw) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
| [] | 966,061 | 966,062 | u109256064 | cpp |
p03163 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef vector<int> vi;
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
void usacoio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int dp[105][100005];
int n, maxw;
int w[105];
int v[105];
int solve(int idx, int ww) {
if (idx == 0)
return 0;
if (dp[idx][ww] >= 0)
return dp[idx][ww];
dp[idx][ww] = solve(idx - 1, ww);
if (w[idx - 1] <= ww)
dp[idx][ww] =
max(dp[idx][ww], v[idx - 1] + solve(idx - 1, ww - w[idx - 1]));
return dp[idx][ww];
}
void solve() {
cin >> n >> maxw;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << solve(n, maxw) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
// BEGIN NO SAD
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef vector<int> vi;
// END NO SAD
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<ll>> matrix;
void usacoio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
ll dp[105][100005];
int n, maxw;
int w[105];
ll v[105];
ll solve(int idx, int ww) {
if (idx == 0)
return 0;
if (dp[idx][ww] >= 0)
return dp[idx][ww];
dp[idx][ww] = solve(idx - 1, ww);
if (w[idx - 1] <= ww)
dp[idx][ww] =
max(dp[idx][ww], v[idx - 1] + solve(idx - 1, ww - w[idx - 1]));
return dp[idx][ww];
}
void solve() {
cin >> n >> maxw;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << solve(n, maxw) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
| [
"variable_declaration.type.change"
] | 966,063 | 966,062 | u109256064 | cpp |
p03163 | /*#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;*/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll int64_t
#define f first
#define s second
#define vll vector<ll>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod (ll)1e18
#define pb push_back
#define N 100000 + 5
#define N 100000 + 5
// cout << fixed << setprecision(12);
#define deb(x) cout << #x << " " << x << endl;
#define forab(i, a, b, c) for (ll(i) = a; (i) <= (b); (i) += (c))
#define forabr(i, a, b, c) for (ll(i) = a; (i) >= (b); (i) -= (c))
void arrinitialize(ll n, ll a[], ll x) {
forab(i, 0, n - 1, 1) { a[i] = x; }
}
void start() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
gcd(b, a % b);
}
ll prime[100000 + 3], prod[100000 + 3];
void seive() {
arrinitialize(100001, prod, 1);
forab(i, 2, 100000, 1) {
forab(j, 2 * i, 100000, i) {
if (!prime[j]) {
prime[j] = i;
} else {
prod[j] *= i;
}
}
}
}
int main() {
start();
fastio;
ll n, w;
cin >> n >> w;
vll a(n, 0), b(n, 0);
ll dp[n + 1][w + 1] = {0};
ll x;
forab(i, 0, n - 1, 1) cin >> x, a[i] = x, cin >> x, b[i] = x;
forab(i, 0, n, 1) {
forab(j, 0, w, 1) {
if (i == 0)
dp[i][j] = 0;
else if (j == 0)
dp[i][j] = 0;
else {
ll x = 0;
if (a[i - 1] <= j)
x = (dp[i - 1][j - a[i - 1]]) + b[i - 1];
dp[i][j] = max(x, dp[i - 1][j]);
}
}
}
cout << dp[n][w];
} | /*#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;*/
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll int64_t
#define f first
#define s second
#define vll vector<ll>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod (ll)1e18
#define pb push_back
#define N 100000 + 5
#define N 100000 + 5
// cout << fixed << setprecision(12);
#define deb(x) cout << #x << " " << x << endl;
#define forab(i, a, b, c) for (ll(i) = a; (i) <= (b); (i) += (c))
#define forabr(i, a, b, c) for (ll(i) = a; (i) >= (b); (i) -= (c))
void arrinitialize(ll n, ll a[], ll x) {
forab(i, 0, n - 1, 1) { a[i] = x; }
}
void start() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
gcd(b, a % b);
}
ll prime[100000 + 3], prod[100000 + 3];
void seive() {
arrinitialize(100001, prod, 1);
forab(i, 2, 100000, 1) {
forab(j, 2 * i, 100000, i) {
if (!prime[j]) {
prime[j] = i;
} else {
prod[j] *= i;
}
}
}
}
int main() {
// start();
fastio;
ll n, w;
cin >> n >> w;
vll a(n, 0), b(n, 0);
ll dp[n + 1][w + 1] = {0};
ll x;
forab(i, 0, n - 1, 1) cin >> x, a[i] = x, cin >> x, b[i] = x;
forab(i, 0, n, 1) {
forab(j, 0, w, 1) {
if (i == 0)
dp[i][j] = 0;
else if (j == 0)
dp[i][j] = 0;
else {
ll x = 0;
if (a[i - 1] <= j)
x = (dp[i - 1][j - a[i - 1]]) + b[i - 1];
dp[i][j] = max(x, dp[i - 1][j]);
}
}
}
cout << dp[n][w];
} | [
"call.remove"
] | 966,068 | 966,069 | u953269735 | cpp |
p03163 | /**
* purpose :
* author : kyomukyomupurin
* created :
**/
// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template <typename T> inline void chmin(T &a, T b) {
if (a > b)
a = b;
return;
}
template <typename T> inline void chmax(T &a, T b) {
if (a < b)
a = b;
return;
}
int64 dp[101][101010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, W;
cin >> n >> W;
vector<int64> w(n), v(n);
for (int i = 0; i < n; ++i)
cin >> w[i] >> v[i];
fill(dp[0], dp[101], (int64)0);
for (int i = 0; i < n; ++i) {
for (int64 j = 0; j <= W; ++j) {
if (j - w[i] < 0)
dp[i + 1][j] = dp[i][j];
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
print(dp[n][W]);
return 0;
} | #pragma region kyomukyomupurin
/**
* author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
* created : 2020-06-17 12:20:49
**/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
template <class T> inline void eraque(std::vector<T> &vec) {
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
return;
}
template <class T>
inline int lower_position(const std::vector<T> &vec, T value) {
return static_cast<int>(
distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), value)));
}
template <class T>
inline int upper_position(const std::vector<T> &vec, T value) {
return static_cast<int>(
distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), value)));
}
template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
#if __cplusplus >= 201703L
template <class Ch, class Tr, class Tuple, std::size_t... Is>
void tuple_out(std::basic_ostream<Ch, Tr> &os, const Tuple &tp,
std::index_sequence<Is...>) {
((os << (Is ? ", " : "(") << std::get<Is>(tp)), ...) << ")";
}
template <class Ch, class Tr, class... Args>
auto &operator<<(std::basic_ostream<Ch, Tr> &os,
const std::tuple<Args...> &tp) {
tuple_out(os, tp, std::index_sequence_for<Args...>{});
return os;
}
#endif
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
int n = 0;
for (auto e : vec)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T, class Compare>
std::ostream &operator<<(std::ostream &os, const std::set<T, Compare> &st) {
int n = 0;
for (auto e : st)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T, class U, class Compare>
std::ostream &operator<<(std::ostream &os, const std::map<T, U, Compare> &mp) {
int n = 0;
for (auto e : mp)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
for (T &e : vec)
is >> e;
return is;
}
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
return is >> p.first >> p.second;
}
#if __cplusplus >= 201703L
template <class Tuple, std::size_t... Is>
void tuple_in(std::istream &is, Tuple &tp, std::index_sequence<Is...>) {
((is >> std::get<Is>(tp)), ...);
}
template <class... Args>
std::istream &operator>>(std::istream &is, std::tuple<Args...> &tp) {
tuple_in(is, tp, std::index_sequence_for<Args...>{});
return is;
}
#endif
#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() { std::cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
std::cerr << head;
if (sizeof...(Tail) != 0)
std::cerr << ", ";
debug_out(std::forward<Tail>(tail)...);
}
#pragma endregion kyomukyomupurin
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, W;
cin >> n >> W;
vector<int64> dp(101010, 0);
for (int i = 0; i < n; ++i) {
int64 w, v;
cin >> w >> v;
for (int j = W; j >= 0; --j) {
if (j - w < 0)
continue;
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << *max_element(all(dp)) << endl;
return 0;
}
| [] | 966,070 | 966,071 | u095266283 | cpp |
p03163 | /**
* purpose :
* author : kyomukyomupurin
* created :
**/
// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template <typename T> inline void chmin(T &a, T b) {
if (a > b)
a = b;
return;
}
template <typename T> inline void chmax(T &a, T b) {
if (a < b)
a = b;
return;
}
int64 dp[101][101010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, W;
cin >> n >> W;
vector<int64> w(n), v(n);
for (int i = 0; i < n; ++i)
cin >> w[i] >> v[i];
fill(dp[0], dp[101], (int64)0);
for (int i = 0; i < n; ++i) {
for (int64 j = 0; j <= W; ++j) {
if (j - w[i] < 0)
continue;
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
print(dp[n][W]);
return 0;
} | #pragma region kyomukyomupurin
/**
* author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
* created : 2020-06-17 12:20:49
**/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
template <class T> inline void eraque(std::vector<T> &vec) {
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
return;
}
template <class T>
inline int lower_position(const std::vector<T> &vec, T value) {
return static_cast<int>(
distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), value)));
}
template <class T>
inline int upper_position(const std::vector<T> &vec, T value) {
return static_cast<int>(
distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), value)));
}
template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
#if __cplusplus >= 201703L
template <class Ch, class Tr, class Tuple, std::size_t... Is>
void tuple_out(std::basic_ostream<Ch, Tr> &os, const Tuple &tp,
std::index_sequence<Is...>) {
((os << (Is ? ", " : "(") << std::get<Is>(tp)), ...) << ")";
}
template <class Ch, class Tr, class... Args>
auto &operator<<(std::basic_ostream<Ch, Tr> &os,
const std::tuple<Args...> &tp) {
tuple_out(os, tp, std::index_sequence_for<Args...>{});
return os;
}
#endif
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
int n = 0;
for (auto e : vec)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T, class Compare>
std::ostream &operator<<(std::ostream &os, const std::set<T, Compare> &st) {
int n = 0;
for (auto e : st)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T, class U, class Compare>
std::ostream &operator<<(std::ostream &os, const std::map<T, U, Compare> &mp) {
int n = 0;
for (auto e : mp)
os << (n++ ? ", " : "{") << e;
return os << (n ? "}" : "{}");
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
for (T &e : vec)
is >> e;
return is;
}
template <class T, class U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
return is >> p.first >> p.second;
}
#if __cplusplus >= 201703L
template <class Tuple, std::size_t... Is>
void tuple_in(std::istream &is, Tuple &tp, std::index_sequence<Is...>) {
((is >> std::get<Is>(tp)), ...);
}
template <class... Args>
std::istream &operator>>(std::istream &is, std::tuple<Args...> &tp) {
tuple_in(is, tp, std::index_sequence_for<Args...>{});
return is;
}
#endif
#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() { std::cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
std::cerr << head;
if (sizeof...(Tail) != 0)
std::cerr << ", ";
debug_out(std::forward<Tail>(tail)...);
}
#pragma endregion kyomukyomupurin
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, W;
cin >> n >> W;
vector<int64> dp(101010, 0);
for (int i = 0; i < n; ++i) {
int64 w, v;
cin >> w >> v;
for (int j = W; j >= 0; --j) {
if (j - w < 0)
continue;
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << *max_element(all(dp)) << endl;
return 0;
}
| [] | 966,072 | 966,071 | u095266283 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = -2000000000;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));
for (int i = 0; i < n; i++) {
for (int sum_w = 0; sum_w <= W; sum_w++) {
if (sum_w - w[i] >= 0) {
dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]);
}
dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w]);
}
}
cout << dp[n][W] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = -2000000000;
int main() {
ll n, W;
cin >> n >> W;
vector<ll> w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, 0));
for (int i = 0; i < n; i++) {
for (int sum_w = 0; sum_w <= W; sum_w++) {
if (sum_w - w[i] >= 0) {
dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]);
}
dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w]);
}
}
cout << dp[n][W] << endl;
} | [
"variable_declaration.type.change",
"call.arguments.change"
] | 966,075 | 966,076 | u796877631 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int ans[100005];
int a[100005], b[100005];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
int fans = 0;
for (int i = 1; i <= n; i++) {
for (int j = k; j >= a[i]; j--) {
ans[j] = max(ans[j], b[i] + ans[j - a[i]]);
}
}
for (int i = 1; i <= k; i++)
fans = max(fans, ans[i]);
cout << fans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long ans[100005];
long long a[100005], b[100005];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
long long fans = 0;
for (int i = 1; i <= n; i++) {
for (int j = k; j >= a[i]; j--) {
ans[j] = max(ans[j], b[i] + ans[j - a[i]]);
}
}
for (int i = 1; i <= k; i++)
fans = max(fans, ans[i]);
cout << fans;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 966,077 | 966,078 | u652662440 | cpp |
p03163 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;
int main() {
ll n, W;
cin >> n >> W;
vector<ll> w(n + 1, 0), v(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n + 1);
for (int i = 0; i <= n; i++) {
dp[i].resize(W);
}
for (int i = 1; i <= n; i++) {
for (int j = W; j >= 0; j--) {
dp[i][j] =
max(dp[i - 1][j], (j - w[i] >= 0 ? dp[i - 1][j - w[i]] + v[i] : 0));
}
}
cout << dp[n][W] << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;
int main() {
ll n, W;
cin >> n >> W;
vector<ll> w(n + 1, 0), v(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n + 1);
for (int i = 0; i <= n; i++) {
dp[i].resize(W + 1, 0);
}
for (int i = 1; i <= n; i++) {
for (int j = W; j >= 0; j--) {
dp[i][j] =
max(dp[i - 1][j], (j - w[i] >= 0 ? dp[i - 1][j - w[i]] + v[i] : 0));
}
}
cout << dp[n][W] << endl;
return 0;
} | [
"call.arguments.add"
] | 966,081 | 966,082 | u700986952 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, l, n) for (long long i = (l); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i <= (long long)(n); i++)
using namespace std;
/*
long long rec(long long i, long long j) {
if (dp[i][j] > -1) {
return dp[i][j];
}
long long res;
if (i == N) {
res = 0;
} else if (j < w[i]) {
res = rec(i+1, j);
} else {
res = max(rec(i+1, j), rec(i+1, j-w[i]) + v[i]);
}
return dp[i][j] = res;
}
*/
int main() {
long long N, W;
cin >> N >> W;
vector<int> w(N);
vector<int> v(N);
vector<vector<long>> dp(N + 1, vector<long>(W + 1, 0));
rep(i, 0, N) { cin >> w[i] >> v[i]; }
rep(i, 1, N) {
rep(j, 0, W + 1) {
if (j - w[i - 1] >= 0)
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];
}
}
long long ans = dp[N - 1][W];
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#define rep(i, l, n) for (long long i = (l); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i <= (long long)(n); i++)
using namespace std;
/*
long long rec(long long i, long long j) {
if (dp[i][j] > -1) {
return dp[i][j];
}
long long res;
if (i == N) {
res = 0;
} else if (j < w[i]) {
res = rec(i+1, j);
} else {
res = max(rec(i+1, j), rec(i+1, j-w[i]) + v[i]);
}
return dp[i][j] = res;
}
*/
int main() {
long long N, W;
cin >> N >> W;
vector<int> w(N);
vector<int> v(N);
vector<vector<long>> dp(N + 1, vector<long>(W + 1, 0));
rep(i, 0, N) { cin >> w[i] >> v[i]; }
rep(i, 1, N + 1) {
rep(j, 0, W + 1) {
if (j - w[i - 1] >= 0)
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];
}
}
long long ans = dp[N][W];
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 966,085 | 966,086 | u041662998 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
ll w[n + 1], v[n + 1];
w[0] = 0;
v[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> w[i] >> v[i];
}
ll dp[n][k];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
if (j == 0 || i == 0)
dp[i][j] = 0;
else if (j >= w[i]) {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][k];
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
ll w[n + 1], v[n + 1];
w[0] = 0;
v[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> w[i] >> v[i];
}
ll dp[n + 1][k + 1];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
if (j == 0 || i == 0)
dp[i][j] = 0;
else if (j >= w[i]) {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][k];
}
| [
"variable_declaration.array_dimensions.change",
"expression.operation.binary.add"
] | 966,089 | 966,090 | u483794341 | cpp |
p03163 | #include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pp pair<ll, ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
using namespace std;
int knapsack(vi &profit, vi &wt, ll maxwt) {
vvi dp(profit.size() + 1, vi(maxwt + 1, 0));
for (int i = 1; i <= profit.size(); i++) {
for (int j = 1; j <= maxwt; j++) {
if (j - wt[i - 1] >= 0) {
dp[i][j] = max(dp[i - 1][j], profit[i - 1] + dp[i - 1][j - wt[i - 1]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
ll ans = dp[wt.size()][0];
for (int i = 1; i <= maxwt; i++) {
ans = max(ans, dp[wt.size()][i]);
}
return ans;
}
int main() {
ll n, W;
cin >> n >> W;
vector<ll> p(n);
vector<ll> w(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> p[i];
}
cout << knapsack(p, w, W);
}
| #include <bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pp pair<ll, ll>
#define vi vector<ll>
#define vvi vector<vi>
#define vb vector<bool>
#define vvb vector<vb>
using namespace std;
ll knapsack(vi &profit, vi &wt, ll maxwt) {
vvi dp(profit.size() + 1, vi(maxwt + 1, 0));
for (int i = 1; i <= profit.size(); i++) {
for (int j = 1; j <= maxwt; j++) {
if (j - wt[i - 1] >= 0) {
dp[i][j] = max(dp[i - 1][j], profit[i - 1] + dp[i - 1][j - wt[i - 1]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
ll ans = dp[wt.size()][0];
for (int i = 1; i <= maxwt; i++) {
ans = max(ans, dp[wt.size()][i]);
}
return ans;
}
int main() {
ll n, W;
cin >> n >> W;
vector<ll> p(n);
vector<ll> w(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> p[i];
}
cout << knapsack(p, w, W);
}
| [] | 966,100 | 966,101 | u704524932 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define LD long double
#define LL long long int
#define ULL unsigned long long
#define vi vector<int>
#define mod 1000000007
int main() {
int N, W;
cin >> N >> W;
vector<int> weights;
vector<int> values;
weights.push_back(0);
values.push_back(0);
for (int i = 0; i < N; i++) {
int w, v;
cin >> w >> v;
weights.push_back(w);
values.push_back(v);
}
vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= W; j++) {
if (j >= weights[i]) {
dp[i][j] = max(dp[i - 1][j], values[i] + dp[i - 1][j - weights[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
std::cout << dp[N][W] << std::endl;
} | #include <bits/stdc++.h>
using namespace std;
#define LD long double
#define LL long long int
#define ULL unsigned long long
#define vi vector<int>
#define mod 1000000007
int main() {
int N, W;
cin >> N >> W;
vector<ULL> weights;
vector<ULL> values;
weights.push_back(0);
values.push_back(0);
for (int i = 0; i < N; i++) {
int w, v;
cin >> w >> v;
weights.push_back(w);
values.push_back(v);
}
vector<vector<ULL>> dp(N + 1, vector<ULL>(W + 1, 0));
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= W; j++) {
if (j >= weights[i]) {
dp[i][j] = max(dp[i - 1][j], values[i] + dp[i - 1][j - weights[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
std::cout << dp[N][W] << std::endl;
} | [
"call.arguments.change"
] | 966,103 | 966,104 | u833101561 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, W;
cin >> n >> W;
int dp[n + 1][W + 1];
int w[n], v[n];
for (i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (i = 0; i <= n; i++) {
for (j = 0; j <= W; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
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];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long i, j, n, W;
cin >> n >> W;
long dp[n + 1][W + 1];
long w[n], v[n];
for (i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (i = 0; i <= n; i++) {
for (j = 0; j <= W; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
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];
return 0;
}
| [
"variable_declaration.type.primitive.change"
] | 966,105 | 966,106 | u496722670 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define MP make_pair
#define S second
#define F first
//#define D cout<<"*\n";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 1000000007
const double pi = 3.14159265358979323846;
int dp[2][100000004];
int knapsack(int value[], int weight[], int n, int W) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
if (i & 1) {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[1][j] = dp[0][j];
else {
dp[1][j] = max(dp[0][j], dp[0][j - weight[i - 1]] + value[i - 1]);
}
}
} else {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[0][j] = dp[1][j];
else {
dp[0][j] = max(dp[1][j], dp[1][j - weight[i - 1]] + value[i - 1]);
}
}
}
}
if (n & 1)
return dp[1][W];
return dp[0][W];
}
signed main() {
fast int t = 1;
// cin>>t;
while (t--) {
int n, W;
cin >> n >> W;
int value[n], weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
cout << knapsack(value, weight, n, W);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define MP make_pair
#define S second
#define F first
//#define D cout<<"*\n";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 1000000007
const double pi = 3.14159265358979323846;
int dp[2][1000004];
int knapsack(int value[], int weight[], int n, int W) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
if (i & 1) {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[1][j] = dp[0][j];
else {
dp[1][j] = max(dp[0][j], dp[0][j - weight[i - 1]] + value[i - 1]);
}
}
} else {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[0][j] = dp[1][j];
else {
dp[0][j] = max(dp[1][j], dp[1][j - weight[i - 1]] + value[i - 1]);
}
}
}
}
if (n & 1)
return dp[1][W];
return dp[0][W];
}
signed main() {
fast int t = 1;
// cin>>t;
while (t--) {
int n, W;
cin >> n >> W;
int value[n], weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
cout << knapsack(value, weight, n, W);
}
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 966,110 | 966,111 | u693178143 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 1e5 + 10;
int N, W, v[111], w[111], mem[111][maxN];
int dp(int i, int cap) {
if (i == N)
return 0;
if (mem[i][cap] != -1)
return mem[i][cap];
int path1 = dp(i + 1, cap);
int path2 = 0;
if (cap + w[i] <= W)
path2 = v[i] + dp(i + 1, w[i] + cap);
return mem[i][cap] = max(path1, path2);
}
int main() {
memset(mem, -1, sizeof(mem));
scanf("%d%d", &N, &W);
for (int i = 0; i < N; i++)
scanf("%d%d", &w[i], &v[i]);
printf("%d", dp(0, 0));
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 1e5 + 10;
int N, W, v[111], w[111];
ll mem[111][maxN];
ll dp(int i, int cap) {
if (i == N)
return 0;
if (mem[i][cap] != -1)
return mem[i][cap];
ll path1 = dp(i + 1, cap);
ll path2 = 0;
if (cap + w[i] <= W)
path2 = v[i] + dp(i + 1, w[i] + cap);
return mem[i][cap] = max(path1, path2);
}
int main() {
memset(mem, -1, sizeof(mem));
scanf("%d%d", &N, &W);
for (int i = 0; i < N; i++)
scanf("%d%d", &w[i], &v[i]);
printf("%lld", dp(0, 0));
} | [
"variable_declaration.type.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 966,112 | 966,113 | u027405444 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int knapsack(int wt[], int val[], int n, int w) {
long int dp[n + 1][w + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (wt[i - 1] <= j) {
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];
}
}
return dp[n][w];
}
int main() {
int N, W;
cin >> N >> W;
int wt[N];
int val[N];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
cout << knapsack(wt, val, N, W) << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long int knapsack(int wt[], int val[], int n, int w) {
long long int dp[n + 1][w + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (wt[i - 1] <= j) {
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];
}
}
return dp[n][w];
}
int main() {
int N, W;
cin >> N >> W;
int wt[N];
int val[N];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
cout << knapsack(wt, val, N, W) << endl;
} | [
"variable_declaration.type.widen.change"
] | 966,114 | 966,115 | u910056155 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int knapsack(int wt[], int val[], int n, int w) {
int dp[n + 1][w + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (wt[i - 1] <= j) {
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];
}
}
return dp[n][w];
}
int main() {
int N, W;
cin >> N >> W;
int wt[N];
int val[N];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
cout << knapsack(wt, val, N, W) << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long int knapsack(int wt[], int val[], int n, int w) {
long long int dp[n + 1][w + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (wt[i - 1] <= j) {
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];
}
}
return dp[n][w];
}
int main() {
int N, W;
cin >> N >> W;
int wt[N];
int val[N];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
cout << knapsack(wt, val, N, W) << endl;
} | [
"variable_declaration.type.widen.change"
] | 966,116 | 966,115 | u910056155 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int knapsack(int wt[], int val[], int n, int w) {
int dp[n + 1][w + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (wt[i - 1] <= j) {
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];
}
}
return dp[n][w];
}
int main() {
int N, W;
cin >> N >> W;
int wt[N];
int val[N];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
cout << knapsack(wt, val, N, W) << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long int knapsack(int wt[], int val[], int n, int w) {
long long int dp[n + 1][w + 1];
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < w + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j < w + 1; j++) {
if (wt[i - 1] <= j) {
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];
}
}
return dp[n][w];
}
int main() {
int N, W;
cin >> N >> W;
int wt[N];
int val[N];
for (int i = 0; i < N; i++) {
cin >> wt[i] >> val[i];
}
cout << knapsack(wt, val, N, W) << endl;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 966,117 | 966,115 | u910056155 | cpp |
p03163 |
// secreterror
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rev(i, n) for (ll i = n - 1; i >= 0; i--)
#define forr(i, x, y) for (ll i = x; i < y; i++)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int, int>>
int main() {
ll n, w;
cin >> n >> w;
vector<ll> wigh(n);
vector<ll> val(n);
for (int i = 0; i < n; i++) {
cin >> wigh[i] >> val[i];
}
ll dp[n + 1][w + 1] = {0};
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 (wigh[i - 1] > w) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][w - wigh[i - 1]] + val[i - 1]);
}
}
}
cout << dp[n][w] << endl;
} |
// secreterror
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rev(i, n) for (ll i = n - 1; i >= 0; i--)
#define forr(i, x, y) for (ll i = x; i < y; i++)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int, int>>
int main() {
ll n, w;
cin >> n >> w;
vector<ll> wigh(n);
vector<ll> val(n);
for (int i = 0; i < n; i++) {
cin >> wigh[i] >> val[i];
}
ll dp[n + 1][w + 1] = {0};
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 (wigh[i - 1] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wigh[i - 1]] + val[i - 1]);
}
}
}
cout << dp[n][w] << endl;
} | [
"identifier.change",
"control_flow.branch.if.condition.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 966,134 | 966,135 | u878396672 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
pair<long long int, long long int> w[n];
for (int i = 0; i < n; i++) {
cin >> w[i].first >> w[i].second;
}
sort(w, w + n);
vector<vector<long long int>> dp(n + 1, vector<long long int>(k + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= k; j++) {
if (w[i - 1].first <= j) {
dp[i][j] =
max(dp[i - 1][j - w[i - 1].first] + w[i - 1].second, dp[i][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
/*for(int i=0;i<=n;i++) {
for(int j=0; j<=k; j++) {
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
cout << dp[n][k];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
pair<long long int, long long int> w[n];
for (int i = 0; i < n; i++) {
cin >> w[i].first >> w[i].second;
}
sort(w, w + n);
vector<vector<long long int>> dp(n + 1, vector<long long int>(k + 1, 0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (w[i - 1].first <= j) {
dp[i][j] =
max(dp[i - 1][j - w[i - 1].first] + w[i - 1].second, dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
/*for(int i=0;i<=n;i++) {
for(int j=0; j<=k; j++) {
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
cout << dp[n][k];
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"assignment.change"
] | 966,140 | 966,141 | u022396000 | cpp |
p03163 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[5000][5000];
ll fun(ll *w, ll *v, ll i, ll n, ll W) {
if (i >= n) {
return 0;
}
if (dp[i][W] != -1) {
return dp[i][W];
}
if (W - w[i] >= 0) {
return dp[i][W] = max(v[i] + fun(w, v, i + 1, n, W - w[i]),
fun(w, v, i + 1, n, W));
}
return dp[i][W] = fun(w, v, i + 1, n, W);
}
int main() {
ll n, W;
cin >> n >> W;
ll w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, -1, sizeof(dp));
cout << fun(w, v, 0, n, W);
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100][100000];
ll fun(ll *w, ll *v, ll i, ll n, ll W) {
if (i >= n) {
return 0;
}
if (dp[i][W] != -1) {
return dp[i][W];
}
if (W - w[i] >= 0) {
return dp[i][W] = max(v[i] + fun(w, v, i + 1, n, W - w[i]),
fun(w, v, i + 1, n, W));
}
return dp[i][W] = fun(w, v, i + 1, n, W);
}
int main() {
ll n, W;
cin >> n >> W;
ll w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, -1, sizeof(dp));
cout << fun(w, v, 0, n, W);
}
| [
"variable_declaration.type.change",
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 966,142 | 966,143 | u402612387 | cpp |
p03163 | // dp_d.cc
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, W;
scanf("%d%d", &a, &W);
vector<int> w(a), v(a);
vector<int> dp(W + 1, 0);
for (int i = 0; i < a; i++) {
scanf("%d%d", &w[i], &v[i]);
// }
// for (int i = 0; i < a; i++) {
for (int j = W - w[i]; j >= 0; j--) {
if (j + w[i] <= W)
dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
}
}
int ans = 0;
for (int i = 0; i <= W; i++)
ans = max(ans, dp[i]);
printf("%d\n", ans);
} | // dp_d.cc
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, W;
scanf("%d%d", &a, &W);
vector<int> w(a), v(a);
vector<long long> dp(W + 1, 0);
for (int i = 0; i < a; i++) {
scanf("%d%d", &w[i], &v[i]);
// }
// for (int i = 0; i < a; i++) {
for (int j = W - w[i]; j >= 0; j--) {
if (j + w[i] <= W)
dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
}
}
long long ans = 0;
for (int i = 0; i <= W; i++)
ans = max(ans, dp[i]);
printf("%lld\n", ans);
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 966,144 | 966,145 | u349225213 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long
// #define pb push_back
// #define vi vector<int>
// #define usi unordered_set<int>
// #define si set<int>
// #define umii unordered_map<int, int>
// #define mii map<int, int>
// #define all(a) a.begin(), a.end()
// #define vii vector<pair<int, int>>
// #define pii pair<int, int>
// #define mod (int)(1e9+7)
// #define INF INT_MAX
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> v(n), w(n);
vector<vector<int>> dp(n + 1, vector<int>(k + 1, 0));
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j < k + 1; j++) {
if (i == 0 or j == 0)
continue;
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][k];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> v(n), w(n);
vector<vector<int>> dp(n + 1, vector<int>(k + 1, 0));
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j < k + 1; j++) {
if (i == 0 or j == 0)
continue;
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][k];
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 966,146 | 966,147 | u091408899 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int N = 200, W = 1e5 + 100;
int v[N], w[N];
long long dp[N][W];
int main() {
int n, we;
cin >> n >> we;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
for (int i = n - 1; i >= 0; i--)
for (int j = 0; j <= we; j++)
dp[i][j] =
max(dp[i + 1][j], (j - w[i] >= 0 ? dp[i + 1][j - w[i]] + v[i] : -1));
cout << dp[0][0];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 200, W = 1e5 + 100;
int v[N], w[N];
long long dp[N][W];
int main() {
int n, we;
cin >> n >> we;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
for (int i = n - 1; i >= 0; i--)
for (int j = 0; j <= we; j++)
dp[i][j] =
max(dp[i + 1][j], (j - w[i] >= 0 ? dp[i + 1][j - w[i]] + v[i] : -1));
cout << dp[0][we];
return 0;
} | [
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change",
"io.output.change"
] | 966,152 | 966,153 | u872069739 | cpp |
p03163 | #include <iostream>
using namespace std;
void dp(int wt[], int val[], int n, int w) {
int matrix[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
matrix[i][j] = 0;
else if (j >= wt[i])
matrix[i][j] = max(val[i] + matrix[i - 1][j - wt[i]], matrix[i - 1][j]);
else
matrix[i][j] = matrix[i - 1][j];
}
}
cout << matrix[n][w];
}
int main() {
int n, w;
cin >> n >> w;
int wt[n + 1], val[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wt[i];
cin >> val[i];
}
dp(wt, val, n, w);
return 0;
} | #include <iostream>
using namespace std;
void dp(int wt[], int val[], int n, int w) {
long int matrix[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
matrix[i][j] = 0;
else if (j >= wt[i])
matrix[i][j] = max(val[i] + matrix[i - 1][j - wt[i]], matrix[i - 1][j]);
else
matrix[i][j] = matrix[i - 1][j];
}
}
cout << matrix[n][w];
}
int main() {
int n, w;
cin >> n >> w;
int wt[n + 1], val[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wt[i];
cin >> val[i];
}
dp(wt, val, n, w);
return 0;
} | [
"variable_declaration.type.widen.change"
] | 966,158 | 966,159 | u452103000 | cpp |
p03163 | /// @pSaurabh
#include <bits/stdc++.h>
using namespace std;
#define read(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define print(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " ";
typedef long long ll;
const ll mod = 1e9 + 7;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct item {
int wt;
int val;
};
bool comp(item i, item j) { return i.wt < j.wt; }
int main() {
// fast();
int n, w;
cin >> n >> w;
item a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i].wt >> a[i].val;
}
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;
continue;
}
if (a[i].wt <= j) {
// cout << "Exec1 ";
dp[i][j] = max(dp[i - 1][j], a[i].val + dp[i - 1][j - a[i].wt]);
// cout << dp[i][j] << "\n";
} else {
// cout << "Exec2 ";
dp[i][j] = dp[i - 1][j];
// cout << dp[i][j] << "\n";
}
}
}
// for(int i = 0; i <= n; i++){
// for(int j = 0; j <= w; j++){
// cout << dp[i][j] << "\t";
// }
// cout << "\n";
// }
cout << dp[n][w];
return 0;
}
| /// @pSaurabh
#include <bits/stdc++.h>
using namespace std;
#define read(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define print(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " ";
typedef long long ll;
const ll mod = 1e9 + 7;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
struct item {
ll wt;
ll val;
};
bool comp(item i, item j) { return i.wt < j.wt; }
int main() {
// fast();
ll n, w;
cin >> n >> w;
item a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i].wt >> a[i].val;
}
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;
continue;
}
if (a[i].wt <= j) {
// cout << "Exec1 ";
dp[i][j] = max(dp[i - 1][j], a[i].val + dp[i - 1][j - a[i].wt]);
// cout << dp[i][j] << "\n";
} else {
// cout << "Exec2 ";
dp[i][j] = dp[i - 1][j];
// cout << dp[i][j] << "\n";
}
}
}
// for(int i = 0; i <= n; i++){
// for(int j = 0; j <= w; j++){
// cout << dp[i][j] << "\t";
// }
// cout << "\n";
// }
cout << dp[n][w];
return 0;
}
| [
"variable_declaration.type.change",
"control_flow.loop.for.initializer.change"
] | 966,164 | 966,165 | u920545417 | cpp |
p03163 | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int a[n][2];
vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0));
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (a[i - 1][0] <= j) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i - 1][0]] + a[i - 1][1]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
long int a[n][2];
vector<vector<long int>> dp(n + 1, vector<long int>(w + 1, 0));
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (a[i - 1][0] <= j) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i - 1][0]] + a[i - 1][1]);
} else
dp[i][j] = dp[i - 1][j];
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
cout << dp[n][w] << endl;
}
| [
"variable_declaration.type.widen.change"
] | 966,166 | 966,167 | u983194109 | cpp |
p03163 | #include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
#define INF 1000000000
#define MOD 1000000007
#define itr ::iterator it
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define remin(a, b) (a) = min((a), (b))
#define remax(a, b) (a) = max((a), (b))
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w, i, j;
cin >> n >> w;
int a[n + 1], b[n + 1];
for (i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
int dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (i = 1; i <= n; i++) {
for (j = 1; j <= w; j++) {
if (a[i] <= j) {
dp[i][j] = max(dp[i - 1][j], b[i] + dp[i - 1][j - a[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w];
} | #include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
#define INF 1000000000
#define MOD 1000000007
#define itr ::iterator it
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) * (b)) / gcd((a), (b))
#define remin(a, b) (a) = min((a), (b))
#define remax(a, b) (a) = max((a), (b))
#define ll long long
#define db double
#define el "\n"
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w, i, j;
cin >> n >> w;
int a[n + 1], b[n + 1];
for (i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
ll int dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (i = 1; i <= n; i++) {
for (j = 1; j <= w; j++) {
if (a[i] <= j) {
dp[i][j] = max(dp[i - 1][j], b[i] + dp[i - 1][j - a[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w];
} | [] | 966,178 | 966,179 | u551630432 | cpp |
p03163 | using namespace std;
#include <bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i)
#define FORD(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i)
#define TR(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define removeDuplicate(a) \
sort(a.begin(), a.end()); \
a.resize(distance(a.begin(), unique(a.begin(), a.end())))
const int N = 1e2 + 1;
const int W = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 100;
int dp[N][W];
int main() {
#define TASK "TASK"
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w;
cin >> n >> w;
vector<int> weights(n + 1), values(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> weights[i] >> values[i];
}
for (int i = 0; i <= n; ++i)
dp[i][0] = 0;
for (int i = 0; i <= w; ++i)
dp[0][i] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (j >= weights[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + values[i]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << endl;
return 0;
} | using namespace std;
#include <bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i)
#define FORD(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i)
#define TR(c, it) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define removeDuplicate(a) \
sort(a.begin(), a.end()); \
a.resize(distance(a.begin(), unique(a.begin(), a.end())))
const int N = 1e2 + 1;
const int W = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 100;
long long dp[N][W];
int main() {
#define TASK "TASK"
// freopen(TASK".inp","r",stdin);
// freopen(TASK".out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w;
cin >> n >> w;
vector<int> weights(n + 1), values(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> weights[i] >> values[i];
}
for (int i = 0; i <= n; ++i)
dp[i][0] = 0;
for (int i = 0; i <= w; ++i)
dp[0][i] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (j >= weights[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + values[i]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 966,180 | 966,181 | u617431891 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, w;
cin >> n >> w;
vector<int> wi(n, 0);
vector<int> vi(n, 0);
for (int i = 0; i < n; ++i) {
int w_tmp, v_tmp;
cin >> w_tmp >> v_tmp;
wi.at(i) = w_tmp;
vi.at(i) = v_tmp;
}
vector<vector<long long int>> vt(n + 1, vector<long long int>(w + 1, 0));
for (int i = 0; i < n - 1; ++i) {
for (int j = 0; j <= w; ++j) {
if (j - wi.at(i) >= 0) {
vt.at(i + 1).at(j) =
max(vt.at(i + 1).at(j), vt.at(i).at(j - wi.at(i)) + vi.at(i));
}
vt.at(i + 1).at(j) = max(vt.at(i).at(j), vt.at(i + 1).at(j));
}
}
cout << vt.at(n - 1).at(w) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, w;
cin >> n >> w;
vector<int> wi(n, 0);
vector<int> vi(n, 0);
for (int i = 0; i < n; ++i) {
int w_tmp, v_tmp;
cin >> w_tmp >> v_tmp;
wi.at(i) = w_tmp;
vi.at(i) = v_tmp;
}
vector<vector<long long int>> vt(n + 1, vector<long long int>(w + 1, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= w; ++j) {
if (j - wi.at(i) >= 0) {
vt.at(i + 1).at(j) =
max(vt.at(i + 1).at(j), vt.at(i).at(j - wi.at(i)) + vi.at(i));
}
vt.at(i + 1).at(j) = max(vt.at(i).at(j), vt.at(i + 1).at(j));
}
}
cout << vt.at(n).at(w) << endl;
return 0;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 966,184 | 966,185 | u150012595 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PI double PPPPPP = 3.14159265358979323846;
void run() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
struct M {
int w, v;
};
vector<M> v;
int cap, n;
ll dp[100 + 3][int(1e5 + 5)];
ll sol(int i, int cap) {
//// base
if (i == n)
return 0;
/// node => (i,cap)
ll &ret = dp[i][cap];
if (ret != -1)
return ret;
ret = sol(i + 1, cap); /// leave
if (cap >= v[i].w) {
ret = max(ret, v[i].v + sol(i + 1, cap - v[i].w));
}
return ret;
}
int main() {
run();
cin >> n;
v.resize(n);
for (auto &i : v) {
cin >> i.w >> i.v;
}
memset(dp, -1, sizeof(dp));
cout << sol(0, cap);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define PI double PPPPPP = 3.14159265358979323846;
void run() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
struct M {
int w, v;
};
vector<M> v;
int cap, n;
ll dp[100 + 3][int(1e5 + 5)];
ll sol(int i, int cap) {
//// base
if (i == n)
return 0;
/// node => (i,cap)
ll &ret = dp[i][cap];
if (ret != -1)
return ret;
ret = sol(i + 1, cap); /// leave
if (cap >= v[i].w) {
ret = max(ret, v[i].v + sol(i + 1, cap - v[i].w));
}
return ret;
}
int main() {
run();
cin >> n >> cap;
v.resize(n);
for (auto &i : v) {
cin >> i.w >> i.v;
}
memset(dp, -1, sizeof(dp));
cout << sol(0, cap);
return 0;
} | [
"expression.operation.binary.add"
] | 966,193 | 966,194 | u657470843 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define ull unsigned long long
const double PI = 2 * acos(0.0);
void run() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
const int M = 1e5;
int n, k;
vii v;
int dp[100 + 9][M + 9];
ll sol(int i, int w) {
if (w < 0)
return -1e9;
if (i == n)
return 0;
int &ret = dp[i][w];
if (~ret)
return ret;
return ret = max(v[i].second + sol(i + 1, w - v[i].first), sol(i + 1, w));
}
int main() {
run();
int w;
cin >> n >> w;
v.resize(n);
lp(i, n) cin >> v[i].first >> v[i].second;
clr(dp, -1);
cout << sol(0, w);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define vi vector<int>
#define vl vector<ll>
#define ii pair<ll, ll>
#define vii vector<ii>
#define ull unsigned long long
const double PI = 2 * acos(0.0);
void run() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
}
const int M = 1e5;
int n, k;
vii v;
ll dp[100 + 9][M + 9];
ll sol(int i, int w) {
if (w < 0)
return -1e9;
if (i == n)
return 0;
ll &ret = dp[i][w];
if (~ret)
return ret;
return ret = max(v[i].second + sol(i + 1, w - v[i].first), sol(i + 1, w));
}
int main() {
run();
int w;
cin >> n >> w;
v.resize(n);
lp(i, n) cin >> v[i].first >> v[i].second;
clr(dp, -1);
cout << sol(0, w);
return 0;
}
| [
"variable_declaration.type.change"
] | 966,195 | 966,196 | u657470843 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll N, W;
cin >> N >> W;
int weights[N], values[N];
for (int i = 0; i < N; i++) {
cin >> weights[i] >> values[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 >= weights[i - 1]) {
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];
}
}
}
}
cout << dp[N][W];
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll N, W;
cin >> N >> W;
int weights[N], values[N];
for (int i = 0; i < N; i++) {
cin >> weights[i] >> values[i];
}
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 (j >= weights[i - 1]) {
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];
}
}
}
}
cout << dp[N][W];
} | [
"variable_declaration.type.change"
] | 966,197 | 966,198 | u303461239 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int INF = 1e9 + 5;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, w;
cin >> n >> w;
vector<int> item(w + 1);
for (int i = 0; i < n; i++) {
int weight, val;
cin >> weight >> val;
for (int j = w; j >= weight; j--) {
item[j] = max(item[j], val + item[j - weight]);
}
}
cout << item[w] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int INF = 1e9 + 5;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, w;
cin >> n >> w;
vector<long long> item(w + 1);
for (int i = 0; i < n; i++) {
int weight, val;
cin >> weight >> val;
for (int j = w; j >= weight; j--) {
item[j] = max(item[j], val + item[j - weight]);
}
}
cout << item[w] << endl;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 966,207 | 966,208 | u353706368 | cpp |
p03163 |
#include <bits/stdc++.h>
#include <dirent.h>
#include <stdlib.h>
using namespace std;
#define sp << " " <<
typedef vector<int> vi;
typedef vector<long int> vli;
typedef vector<long long int> vlli;
typedef long int li;
typedef long long int lli;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<lli, lli>> vplli;
typedef unordered_map<int, int> ump;
int main() {
int n, w;
cin >> n >> w;
vector<pair<long long int, int>> arr;
// vector<int> value;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
arr.push_back({b, a});
}
// sort(arr.begin(), arr.end());
vector<vector<long long int>> dp(w + 1, vector<long long int>(n, -1));
for (int i = 0; i < n; i++) {
dp[0][i] = 0;
}
for (int i = 0; i < w + 1; i++) {
if (arr[0].second <= i) {
dp[i][0] = arr[0].first;
} else {
dp[i][0] = 0;
}
}
// for(int i=0;i<w+1;i++){
// for(int j=0;j<n;j++){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
for (int i = 1; i < n; i++) {
for (int j = 1; j < w + 1; j++) {
if (arr[i].second <= j) {
// cout << "Entering" << i sp j << endl;
// cout << dp[j][i-1] sp arr[i].first+dp[j-arr[i].second][i-1] << endl;
dp[j][i] =
max(dp[j][i - 1], arr[i].first + dp[j - arr[i].second][i - 1]);
} else {
dp[j][i] = dp[j][i - 1];
}
}
}
// for(int i=0;i<w+1;i++){
// for(int j=0;j<n;j++){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
// cout << dp[w][n-1];
return dp[w][n - 1];
} |
#include <bits/stdc++.h>
#include <dirent.h>
#include <stdlib.h>
using namespace std;
#define sp << " " <<
typedef vector<int> vi;
typedef vector<long int> vli;
typedef vector<long long int> vlli;
typedef long int li;
typedef long long int lli;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<lli, lli>> vplli;
typedef unordered_map<int, int> ump;
int main() {
int n, w;
cin >> n >> w;
vector<pair<long long int, int>> arr;
// vector<int> value;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
arr.push_back({b, a});
}
// sort(arr.begin(), arr.end());
vector<vector<long long int>> dp(w + 1, vector<long long int>(n, -1));
for (int i = 0; i < n; i++) {
dp[0][i] = 0;
}
for (int i = 0; i < w + 1; i++) {
if (arr[0].second <= i) {
dp[i][0] = arr[0].first;
} else {
dp[i][0] = 0;
}
}
// for(int i=0;i<w+1;i++){
// for(int j=0;j<n;j++){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
for (int i = 1; i < n; i++) {
for (int j = 1; j < w + 1; j++) {
if (arr[i].second <= j) {
// cout << "Entering" << i sp j << endl;
// cout << dp[j][i-1] sp arr[i].first+dp[j-arr[i].second][i-1] << endl;
dp[j][i] =
max(dp[j][i - 1], arr[i].first + dp[j - arr[i].second][i - 1]);
} else {
dp[j][i] = dp[j][i - 1];
}
}
}
// for(int i=0;i<w+1;i++){
// for(int j=0;j<n;j++){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
cout << dp[w][n - 1];
return 0;
} | [
"io.output.change",
"control_flow.return.add",
"control_flow.return.0.add"
] | 966,209 | 966,210 | u083076249 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n, W;
cin >> n >> W;
int w[n + 1], v[n + 1];
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
int a[n + 1][W + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= W; j++) {
if (i == 0 || j == 0) {
a[i][j] = 0;
continue;
}
if (j - w[i] < 0) {
a[i][j] = a[i - 1][j];
} else {
a[i][j] = max(a[i - 1][j], v[i] + a[i - 1][j - w[i]]);
}
}
}
cout << a[n][W];
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ll n, W;
cin >> n >> W;
ll w[n + 1], v[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
ll a[n + 1][W + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= W; j++) {
if (i == 0 || j == 0) {
a[i][j] = 0;
continue;
}
if (j - w[i] < 0) {
a[i][j] = a[i - 1][j];
} else {
a[i][j] = max(a[i - 1][j], v[i] + a[i - 1][j - w[i]]);
}
}
}
cout << a[n][W];
return 0;
} | [
"variable_declaration.type.change",
"control_flow.loop.for.initializer.change"
] | 966,213 | 966,214 | u948379857 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define fo(i, n) for (int i = 0; i < n; i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int, int>
#define mp make_pair
#define mapi map<int, int>
lli t[101][100001];
lli dp(lli val[], int w[], int W, int n) {
if (n == 0 || W == 0)
return 0;
if (t[n][W] != -1)
return t[n][W];
if (w[n - 1] <= W)
return t[n][W] = max(val[n - 1] + dp(val, w, W - w[n - 1], n - 1),
dp(val, w, W, n - 1));
else
return t[n][W] = dp(val, w, W, n - 1);
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
memset(t, -1, sizeof(t));
int n, W;
cin >> n >> W;
int w[n];
lli val[n];
for (int i = 0; i < n; i++)
cin >> w[i] >> val[i];
cout << dp(val, w, W, 5);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define fo(i, n) for (int i = 0; i < n; i++)
#define eb emplace_back
#define M 1000000007
#define vi vector<int>
#define vlli vector<lli>
#define pi pair<int, int>
#define mp make_pair
#define mapi map<int, int>
lli t[101][100001];
lli dp(lli val[], int w[], int W, int n) {
if (n == 0 || W == 0)
return 0;
if (t[n][W] != -1)
return t[n][W];
if (w[n - 1] <= W)
return t[n][W] = max(val[n - 1] + dp(val, w, W - w[n - 1], n - 1),
dp(val, w, W, n - 1));
else
return t[n][W] = dp(val, w, W, n - 1);
}
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
memset(t, -1, sizeof(t));
int n, W;
cin >> n >> W;
int w[n];
lli val[n];
for (int i = 0; i < n; i++)
cin >> w[i] >> val[i];
cout << dp(val, w, W, n);
return 0;
}
| [
"identifier.replace.add",
"literal.replace.remove",
"io.output.change"
] | 966,215 | 966,216 | u308644372 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef int ll;
int main() {
ll n, W;
cin >> n >> W;
ll i, j;
ll w[n + 1], v[n + 1];
w[0] = 0;
v[0] = 0;
for (i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
ll dp[n + 1][W + 1];
for (i = 0; i < W + 1; i++)
dp[0][i] = 0;
for (i = 0; i < n + 1; i++)
dp[i][0] = 0;
for (i = 1; i < n + 1; i++) {
for (j = 1; j < W + 1; j++) {
if (w[i] <= j)
dp[i][j] = max(v[i] + dp[i - 1][j - w[i]], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll n, W;
cin >> n >> W;
ll i, j;
ll w[n + 1], v[n + 1];
w[0] = 0;
v[0] = 0;
for (i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
ll dp[n + 1][W + 1];
for (i = 0; i < W + 1; i++)
dp[0][i] = 0;
for (i = 0; i < n + 1; i++)
dp[i][0] = 0;
for (i = 1; i < n + 1; i++) {
for (j = 1; j < W + 1; j++) {
if (w[i] <= j)
dp[i][j] = max(v[i] + dp[i - 1][j - w[i]], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W] << endl;
return 0;
} | [
"variable_declaration.type.widen.change"
] | 966,222 | 966,223 | u850089425 | cpp |
p03163 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
ll exp(ll x, ll y) {
if (y == 0)
return 1;
if (y % 2 == 1)
return x * exp(x, y / 2) * exp(x, y / 2);
return exp(x, y / 2) * exp(x, y / 2);
}
ll exp(ll x, ll y, ll modd) {
if (y == 0)
return 1;
ll t = exp(x, y / 2, modd);
t = t % modd;
t = t * t;
t = t % modd;
if (y % 2 == 1)
return (x * t) % modd;
return t % modd;
}
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("sse4")
#define ios \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear();
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el \
endl; \
cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x, 0ll, so x)
#define all(x) (x).be, (x).en
#define acc(x) accumulate((x).be, (x).en, 0ll)
#define forn(i, a, b) for (ll i = a; i <= b; ++i)
#define revn(i, a, b) for (ll i = a; i >= b; --i)
#define rng_58 \
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string, int>>
#define vll vector<pair<ll, ll>>
#define vlll vector<pair<ll, pair<ll, ll>>>
#define vlvl vector<pair<pair<ll, ll>, ll>> >
#define pll pair<ll, ll>
#define plll pair<ll, pair<ll, ll>>
#define plvl pair<pair<ll, ll>, ll>
#define mp make_pair
#define trace3(a, b, c) \
cerr << "a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a, b, c, d) \
cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d << el;
#define trace5(a, b, c, d, e) \
cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \
<< " e is " << e << el;
#define trace6(a, b, c, d, e, f) \
cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \
<< " e is " << e << " f is " << f << el;
int main() {
ios;
int n, w;
cin >> n >> w;
vector<int> val(n), wt(n);
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
vector<vector<int>> dp(n, vector<int>(w + 1, 0));
for (int i = 0; i <= w; i++)
if (wt[0] <= w)
dp[0][i] = val[0];
for (int i = 1; i < n; i++)
for (int j = 1; j <= w; j++) {
int p1 = 0;
if (j >= wt[i])
p1 = dp[i - 1][j - wt[i]] + val[i];
dp[i][j] = max(dp[i - 1][j], p1);
}
cout << dp[n - 1][w];
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef long double ld;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
ll exp(ll x, ll y) {
if (y == 0)
return 1;
if (y % 2 == 1)
return x * exp(x, y / 2) * exp(x, y / 2);
return exp(x, y / 2) * exp(x, y / 2);
}
ll exp(ll x, ll y, ll modd) {
if (y == 0)
return 1;
ll t = exp(x, y / 2, modd);
t = t % modd;
t = t * t;
t = t % modd;
if (y % 2 == 1)
return (x * t) % modd;
return t % modd;
}
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("sse4")
#define ios \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear();
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el \
endl; \
cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x, 0ll, so x)
#define all(x) (x).be, (x).en
#define acc(x) accumulate((x).be, (x).en, 0ll)
#define forn(i, a, b) for (ll i = a; i <= b; ++i)
#define revn(i, a, b) for (ll i = a; i >= b; --i)
#define rng_58 \
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vs vector<string>
#define vsi vector<pair<string, int>>
#define vll vector<pair<ll, ll>>
#define vlll vector<pair<ll, pair<ll, ll>>>
#define vlvl vector<pair<pair<ll, ll>, ll>> >
#define pll pair<ll, ll>
#define plll pair<ll, pair<ll, ll>>
#define plvl pair<pair<ll, ll>, ll>
#define mp make_pair
#define trace3(a, b, c) \
cerr << "a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a, b, c, d) \
cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d << el;
#define trace5(a, b, c, d, e) \
cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \
<< " e is " << e << el;
#define trace6(a, b, c, d, e, f) \
cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \
<< " e is " << e << " f is " << f << el;
int main() {
ios;
int n, w;
cin >> n >> w;
vector<ll> val(n), wt(n);
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
vector<vector<ll>> dp(n, vector<ll>(w + 1, 0));
for (int i = 0; i <= w; i++)
if (wt[0] <= i)
dp[0][i] = val[0];
for (int i = 1; i < n; i++)
for (int j = 1; j <= w; j++) {
ll p1 = 0;
if (j >= wt[i])
p1 = dp[i - 1][j - wt[i]] + val[i];
dp[i][j] = max(dp[i - 1][j], p1);
}
cout << dp[n - 1][w];
return 0;
} | [
"call.arguments.change",
"identifier.change",
"control_flow.branch.if.condition.change",
"variable_declaration.type.change"
] | 966,231 | 966,232 | u330328563 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
int w[n], val[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> val[i];
}
int dp[2][wt + 1];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < wt + 1; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < wt + 1; j++) {
if (w[i - 1] <= j) {
dp[1][j] = max(dp[0][j], val[i - 1] + dp[0][j - w[i - 1]]);
} else
dp[1][j] = dp[0][j];
}
for (int k = 0; k < wt + 1; k++) {
dp[0][k] = dp[1][k];
dp[1][k] = 0;
}
}
cout << dp[0][wt] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, wt;
cin >> n >> wt;
long long w[n], val[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> val[i];
}
long long dp[2][wt + 1];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < wt + 1; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < wt + 1; j++) {
if (w[i - 1] <= j) {
dp[1][j] = max(dp[0][j], val[i - 1] + dp[0][j - w[i - 1]]);
} else
dp[1][j] = dp[0][j];
}
for (int k = 0; k < wt + 1; k++) {
dp[0][k] = dp[1][k];
dp[1][k] = 0;
}
}
cout << dp[0][wt] << endl;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 966,239 | 966,240 | u320677093 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
int knapsack(vector<long long int> &wt, vector<long long int> &val, int n,
int Weight) {
vector<long long int> dp(10e5);
for (int i = 1; i <= n; i++) {
for (int w = Weight; w >= 0; w--) {
if (w >= wt[i - 1])
dp[w] = max(dp[w - wt[i - 1]] + val[i - 1], dp[w]);
}
}
return dp[Weight];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<long long int> wt(n), val(n);
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << knapsack(wt, val, n, w) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O3")
long long int knapsack(vector<long long int> &wt, vector<long long int> &val,
int n, int Weight) {
vector<long long int> dp(10e5);
for (int i = 1; i <= n; i++) {
for (int w = Weight; w >= 0; w--) {
if (w >= wt[i - 1])
dp[w] = max(dp[w - wt[i - 1]] + val[i - 1], dp[w]);
}
}
return dp[Weight];
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<long long int> wt(n), val(n);
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << knapsack(wt, val, n, w) << endl;
return 0;
} | [
"variable_declaration.type.widen.change"
] | 966,241 | 966,242 | u898200089 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF (long long int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define ll long long int
#define ret return
#define NUM 100020
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
fastio();
// input();
ll n, w;
cin >> n >> w;
vector<int> val, wt;
for (ll i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
val.push_back(b);
wt.push_back(a);
}
int dp[n + 1][w + 1];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0) {
if (wt[i] > j)
dp[i][j] = 0;
else
dp[i][j] = val[i];
} else {
if (wt[i] > j)
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] = max(val[i] + dp[i - 1][j - wt[i]], dp[i - 1][j]);
}
}
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<=w;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
cout << dp[n - 1][w] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF (long long int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define ll long long int
#define ret return
#define NUM 100020
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
fastio();
// input();
ll n, w;
cin >> n >> w;
vector<ll> val, wt;
for (ll i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
val.push_back(b);
wt.push_back(a);
}
ll dp[n + 1][w + 1];
for (ll i = 0; i < n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0) {
if (wt[i] > j)
dp[i][j] = 0;
else
dp[i][j] = val[i];
} else {
if (wt[i] > j)
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] = max(val[i] + dp[i - 1][j - wt[i]], dp[i - 1][j]);
}
}
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<=w;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
cout << dp[n - 1][w] << endl;
return 0;
} | [
"variable_declaration.type.change",
"control_flow.loop.for.initializer.change"
] | 966,243 | 966,244 | u168216888 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first // For pairs
#define ss second // For pairs
#define sz(a) int((a).size()) // Function to determine size of any container
#define pb push_back // Pushback to vector
#define mp make_pair // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()
#define tr(container, it) \
for (auto it = container.begin(); it != container.end(); \
it++) // traversing macro
#define lp(it, it1, it2) for (auto it = it1; it < it2; it++) // loop
#define present(c, x) (c.find(x) != c.end())
using namespace std;
using namespace std::chrono;
typedef vector<ll> vi; // Vector of long long
typedef vector<vi> vvi; // Vector of vi
typedef vector<pair<ll, ll>> ii; // Vector of pairs
typedef vector<ii> vii; // Vector of ii
int main() {
ll n, k;
cin >> n >> k;
vi v(n + 1), w(n + 1);
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
vvi dp(n + 1, vi(k + 1));
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
if (i - w[j] >= 0)
dp[j][i] = max(dp[j - 1][i - w[j]] + v[j], dp[j - 1][i]);
else
dp[j][i] = dp[j - 1][i];
}
}
cout << dp[n - 1][k] << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first // For pairs
#define ss second // For pairs
#define sz(a) int((a).size()) // Function to determine size of any container
#define pb push_back // Pushback to vector
#define mp make_pair // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()
#define tr(container, it) \
for (auto it = container.begin(); it != container.end(); \
it++) // traversing macro
#define lp(it, it1, it2) for (auto it = it1; it < it2; it++) // loop
#define present(c, x) (c.find(x) != c.end())
using namespace std;
using namespace std::chrono;
typedef vector<ll> vi; // Vector of long long
typedef vector<vi> vvi; // Vector of vi
typedef vector<pair<ll, ll>> ii; // Vector of pairs
typedef vector<ii> vii; // Vector of ii
int main() {
ll n, k;
cin >> n >> k;
vi v(n + 1), w(n + 1);
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
vvi dp(n + 1, vi(k + 1));
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= n; j++) {
if (i - w[j] >= 0)
dp[j][i] = max(dp[j - 1][i - w[j]] + v[j], dp[j - 1][i]);
else
dp[j][i] = dp[j - 1][i];
}
}
cout << dp[n][k] << "\n";
return 0;
}
| [
"expression.operation.binary.remove"
] | 966,249 | 966,250 | u159748458 | cpp |
p03163 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int INF = 1e9;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
vector<int> dp(W + 1);
dp[0] = 0;
rep(i, n) {
for (int j = W; j >= w[i]; j--) {
dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
}
}
cout << dp[W] << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int INF = 1e9;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n);
vector<ll> v(n);
rep(i, n) cin >> w[i] >> v[i];
vector<ll> dp(W + 1);
dp[0] = 0;
rep(i, n) {
for (int j = W; j >= w[i]; j--) {
dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
}
}
cout << dp[W] << endl;
} | [] | 966,265 | 966,266 | u648009244 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define fi first
#define si second
#define mp make_pair
#define f(n) for (ll i = 0; i < n; i++)
#define ff(m) for (ll j = 0; j < m; j++)
#define fr(i, p, n) for (ll i = p; i < n; i++)
#define in insert
ll exp(ll a, ll b, ll m);
#define vl vector<ll>
#define pll pair<ll, ll>
void solve() {
int n, W;
cin >> n >> W;
vl v(n + 1, 0);
vl w(n + 1, 0);
fr(i, 1, n + 1) { cin >> w[i] >> v[i]; }
ll dp[n + 1][n + 1];
memset(dp, 0, sizeof(dp));
fr(i, 1, n + 1) {
fr(j, 1, W + 1) {
if (j < w[i])
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
}
}
// dp(i,j)=max(dp(i-1,j),v[i]+dp(i-1,j-w[i]))
cout << dp[n][W] << endl;
}
int main() {
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
ll exp(ll a, ll b, ll m) {
if (b == 0) {
return 1;
}
ll temp = exp(a, b / 2, m);
temp = (temp * temp) % m;
if (b & 1) {
return (temp * (a % m)) % m;
}
return temp;
} | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define fi first
#define si second
#define mp make_pair
#define f(n) for (ll i = 0; i < n; i++)
#define ff(m) for (ll j = 0; j < m; j++)
#define fr(i, p, n) for (ll i = p; i < n; i++)
#define in insert
ll exp(ll a, ll b, ll m);
#define vl vector<ll>
#define pll pair<ll, ll>
void solve() {
int n, W;
cin >> n >> W;
vl v(n + 1, 0);
vl w(n + 1, 0);
fr(i, 1, n + 1) { cin >> w[i] >> v[i]; }
ll dp[n + 1][W + 1];
memset(dp, 0, sizeof(dp));
fr(i, 1, n + 1) {
fr(j, 1, W + 1) {
if (j < w[i])
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
}
}
// dp(i,j)=max(dp(i-1,j),v[i]+dp(i-1,j-w[i]))
cout << dp[n][W] << endl;
}
int main() {
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
ll exp(ll a, ll b, ll m) {
if (b == 0) {
return 1;
}
ll temp = exp(a, b / 2, m);
temp = (temp * temp) % m;
if (b & 1) {
return (temp * (a % m)) % m;
}
return temp;
} | [
"identifier.change",
"expression.operation.binary.change"
] | 966,270 | 966,271 | u339112743 | cpp |
p03163 | #include <iostream>
using namespace std;
int main() {
int n, w, dp[2][200000];
cin >> n >> w;
for (int i = 0; i < w; i++) {
dp[0][i] = 0;
dp[1][i] = 0;
}
for (int i = 0; i < n; i++) {
int tmpw, tmpv;
cin >> tmpw >> tmpv;
for (int j = 1; j <= w; j++) {
// new=dp[n%2] old=dp[(n+1)%2]
if (tmpw <= j) {
dp[i % 2][j] =
max(dp[(i + 1) % 2][j], tmpv + dp[(i + 1) % 2][max(0, j - tmpw)]);
} else {
dp[i % 2][j] = dp[(i + 1) % 2][j];
}
}
}
cout << dp[(n - 1) % 2][w] << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int n, w;
long long dp[2][100002];
cin >> n >> w;
for (int i = 0; i < w; i++) {
dp[0][i] = 0;
dp[1][i] = 0;
}
for (int i = 0; i < n; i++) {
int tmpw, tmpv;
cin >> tmpw >> tmpv;
for (int j = 1; j <= w; j++) {
// new=dp[n%2] old=dp[(n+1)%2]
if (tmpw <= j) {
dp[i % 2][j] =
max(dp[(i + 1) % 2][j], tmpv + dp[(i + 1) % 2][max(0, j - tmpw)]);
} else {
dp[i % 2][j] = dp[(i + 1) % 2][j];
}
}
// for (int j=1;j<=w;j++){
// cout << dp[i%2][j]<<" ";
// }
// cout <<endl;
}
cout << dp[(n - 1) % 2][w] << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 966,276 | 966,277 | u499619187 | cpp |
p03163 | #include <iostream>
#include <vector>
using namespace std;
long long solveKnapsack(vector<int> &profits, vector<int> &weights,
int capacity) {
// basic checks
if (capacity <= 0 || profits.empty() || weights.size() != profits.size()) {
return 0;
}
int n = profits.size();
vector<vector<long long>> dp(n, vector<long long>(capacity + 1));
// populate the capacity=0 columns, with '0' capacity we have '0' profit
for (int i = 0; i < n; i++) {
dp[i][0] = 0;
}
// if we have only one weight, we will take it if it is not more than the
// capacity
for (int c = 0; c <= capacity; c++) {
if (weights[0] <= c) {
dp[0][c] = profits[0];
}
}
// process all sub-arrays for all the capacities
for (int i = 1; i < n; i++) {
for (int c = 1; c <= capacity; c++) {
long long profit1 = 0, profit2 = 0;
// include the item, if it is not more than the capacity
if (weights[i] <= c) {
profit1 = profits[i] + dp[i - 1][c - weights[i]];
}
// exclude the item
profit2 = dp[i - 1][c];
// take maximum
dp[i][c] = max(profit1, profit2);
}
}
// maximum profit will be at the bottom-right corner.
return dp[n - 1][capacity];
}
int main() {
int N, W;
cin >> N >> W;
vector<int> v(N);
vector<int> w(N);
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// vector<vector<long long>> memo(N, vector<long longa>(W+1, 0));
long long res = solveKnapsack(w, v, W);
cout << res << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
long long solveKnapsack(vector<int> &weights, vector<int> &profits,
int capacity) {
// basic checks
if (capacity <= 0 || profits.empty() || weights.size() != profits.size()) {
return 0;
}
int n = profits.size();
vector<vector<long long>> dp(n, vector<long long>(capacity + 1));
// populate the capacity=0 columns, with '0' capacity we have '0' profit
for (int i = 0; i < n; i++) {
dp[i][0] = 0;
}
// if we have only one weight, we will take it if it is not more than the
// capacity
for (int c = 0; c <= capacity; c++) {
if (weights[0] <= c) {
dp[0][c] = profits[0];
}
}
// process all sub-arrays for all the capacities
for (int i = 1; i < n; i++) {
for (int c = 1; c <= capacity; c++) {
long long profit1 = 0, profit2 = 0;
// include the item, if it is not more than the capacity
if (weights[i] <= c) {
profit1 = profits[i] + dp[i - 1][c - weights[i]];
}
// exclude the item
profit2 = dp[i - 1][c];
// take maximum
dp[i][c] = max(profit1, profit2);
}
}
// maximum profit will be at the bottom-right corner.
return dp[n - 1][capacity];
}
int main() {
int N, W;
cin >> N >> W;
vector<int> v(N);
vector<int> w(N);
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// vector<vector<long long>> memo(N, vector<long longa>(W+1, 0));
long long res = solveKnapsack(w, v, W);
cout << res << endl;
}
| [
"identifier.change"
] | 966,278 | 966,279 | u638254110 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll int n, w;
cin >> n >> w;
pair<ll int, ll int> values[n];
for (ll int i = 0; i < n; i++) {
cin >> values[i].first >> values[i].second;
}
ll int dp[2][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (j < values[i - 1].first)
dp[i % 2][j] = dp[(i - 1) % 2][j];
else {
dp[i % 2][j] = max(dp[(i - 1) % 2][j],
values[(i - 1) % 2].second +
dp[(i - 1) % 2][j - values[i - 1].first]);
}
}
}
cout << dp[n % 2][w] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll int n, w;
cin >> n >> w;
pair<ll int, ll int> values[n];
for (ll int i = 0; i < n; i++) {
cin >> values[i].first >> values[i].second;
}
ll int dp[2][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (j < values[i - 1].first)
dp[i % 2][j] = dp[(i - 1) % 2][j];
else {
dp[i % 2][j] = max(dp[(i - 1) % 2][j],
values[i - 1].second +
dp[(i - 1) % 2][j - values[i - 1].first]);
}
}
}
cout << dp[n % 2][w] << endl;
}
| [
"call.arguments.change"
] | 966,288 | 966,289 | u266048884 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int val[n], weight[n];
for (int i = 0; i < n; ++i) {
cin >> weight[i] >> val[i];
}
int m[n + 1][w + 1]; // m[i][j] denotes the maximum value taking max weight
// limit of j and considering i elements
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (i == 0 || w == 0)
m[i][j] = 0;
else if (weight[i - 1] <= j) {
m[i][j] = max(m[i - 1][j - weight[i - 1]] + val[i - 1], m[i - 1][j]);
} else
m[i][j] = m[i - 1][j];
// cout<<m[i][j]<<" ";
}
// cout<<endl;
}
cout << m[n][w];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
long long int val[n], weight[n];
for (int i = 0; i < n; ++i) {
cin >> weight[i] >> val[i];
}
long long int m[n + 1][w + 1]; // m[i][j] denotes the maximum value taking max
// weight limit of j and considering i elements
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (i == 0 || w == 0)
m[i][j] = 0;
else if (weight[i - 1] <= j) {
m[i][j] = max(m[i - 1][j - weight[i - 1]] + val[i - 1], m[i - 1][j]);
} else
m[i][j] = m[i - 1][j];
// cout<<m[i][j]<<" ";
}
// cout<<endl;
}
cout << m[n][w];
return 0;
} | [
"variable_declaration.type.widen.change"
] | 966,292 | 966,293 | u867806614 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
int main() {
std::ios::sync_with_stdio(false);
using namespace std;
int n, w, a, b;
cin >> n >> w;
vector<int> A(w + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a >> b;
for (int j = w - a; j >= 0; j--)
A[j + a] = max(A[j + a], A[j] + b);
}
cout << A[w] << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
int main() {
std::ios::sync_with_stdio(false);
using namespace std;
ll n, w, a, b;
cin >> n >> w;
vector<ll> A(w + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a >> b;
for (int j = w - a; j >= 0; j--)
A[j + a] = max(A[j + a], A[j] + b);
}
cout << A[w] << "\n";
return 0;
}
| [
"variable_declaration.type.change"
] | 966,296 | 966,297 | u135880256 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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;
}
using ll = long long;
const ll MOD = 1e9 + 7;
int INF = INT_MAX;
ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1};
vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0};
vector<int> d4y = {0, 1, 0, -1};
//
int main() {
int n, w;
cin >> n >> w;
vector<ll> weight(n);
vector<ll> value(n);
rep(i, n) { cin >> weight[i] >> value[i]; }
vector<vector<ll>> dp(n, vector<ll>(w + 1, 0));
for (ll i = weight[0]; i < w + 1; i++) {
dp[0][i] = value[0];
}
for (ll i = 1; i <= n - 1; i++) {
for (ll j = 0; j < w; j++) {
chmax(dp[i][j], dp[i - 1][j]);
if (j + weight[i] <= w)
chmax(dp[i][j + weight[i]], dp[i - 1][j] + value[i]);
}
}
cout << dp[n - 1][w] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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;
}
using ll = long long;
const ll MOD = 1e9 + 7;
int INF = INT_MAX;
ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1};
vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0};
vector<int> d4y = {0, 1, 0, -1};
//
int main() {
int n, w;
cin >> n >> w;
vector<ll> weight(n);
vector<ll> value(n);
rep(i, n) { cin >> weight[i] >> value[i]; }
vector<vector<ll>> dp(n, vector<ll>(w + 1, 0));
for (ll i = weight[0]; i < w + 1; i++) {
dp[0][i] = value[0];
}
for (ll i = 1; i <= n - 1; i++) {
for (ll j = 0; j <= w; j++) {
chmax(dp[i][j], dp[i - 1][j]);
if (j + weight[i] <= w)
chmax(dp[i][j + weight[i]], dp[i - 1][j] + value[i]);
}
}
cout << dp[n - 1][w] << endl;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 966,300 | 966,301 | u646962247 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int N;
long long W, weight[110], value[110];
long long dp[110][100100] = {0};
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> weight[i] >> value[i];
}
for (int i = 0; i < N; i++) {
for (int w = 0; w <= W; w++) {
if (0 <= w - weight[i]) {
chmax(dp[i + 1][w], dp[i][w - weight[i]] + value[i]);
} else {
chmax(dp[i + 1][w], dp[i][w]);
}
}
}
cout << dp[N][W] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int N;
long long W, weight[110], value[110];
long long dp[110][100100] = {0};
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> weight[i] >> value[i];
}
for (int i = 0; i < N; i++) {
for (int w = 0; w <= W; w++) {
if (0 <= w - weight[i]) {
chmax(dp[i + 1][w], dp[i][w - weight[i]] + value[i]);
}
chmax(dp[i + 1][w], dp[i][w]);
}
}
cout << dp[N][W] << endl;
return 0;
} | [] | 966,308 | 966,309 | u336145516 | cpp |
p03163 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
int n, W;
int w[105], v[105];
int dp[105][105];
int solve(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
int res;
if (i == n)
res = 0;
else if (j < w[i]) {
res = solve(i + 1, j);
} else {
res = max(solve(i + 1, j), solve(i + 1, j - w[i]) + v[i]);
}
return dp[i][j] = res;
}
int main() {
cin >> n >> W;
rep(i, n) cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << solve(0, W) << endl;
;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
int n, W;
int w[105], v[105];
ll dp[105][100100];
ll solve(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
ll res;
if (i == n)
res = 0;
else if (j < w[i]) {
res = solve(i + 1, j);
} else {
res = max(solve(i + 1, j), solve(i + 1, j - w[i]) + v[i]);
}
return dp[i][j] = res;
}
int main() {
cin >> n >> W;
rep(i, n) cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << solve(0, W) << endl;
} | [
"variable_declaration.type.change",
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 966,312 | 966,311 | u259578308 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.