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;
pair<int, int> sac[105]; // first : poids, second : valeur
int dp[2][100010];
int main() {
int nItem;
scanf("%d", &nItem);
int iCapacite;
scanf("%d", &iCapacite);
for (int i = 0; i < nItem; i++) {
scanf("%d %d", &sac[i].first, &sac[i].second);
}
for (int i = 0; i < nItem; i++) {
for (int s = 0; s <= iCapacite; s++) {
dp[(i + 1) % 2][s] =
max(dp[(i + 1) % 2][s], dp[i % 2][s]); // Ne pas prendre
if (s + sac[i].first <= iCapacite) {
dp[(i + 1) % 2][s + sac[i].first] =
max(dp[(i + 1) % 2][s + sac[i].first],
dp[i % 2][s] + sac[i].second); // Prendre
}
}
}
printf("%d", dp[nItem % 2][iCapacite]);
} | #include <bits/stdc++.h>
using namespace std;
pair<int, int> sac[105]; // first : poids, second : valeur
long long dp[2][100010];
int main() {
int nItem;
scanf("%d", &nItem);
int iCapacite;
scanf("%d", &iCapacite);
for (int i = 0; i < nItem; i++) {
scanf("%d %d", &sac[i].first, &sac[i].second);
}
for (int i = 0; i < nItem; i++) {
for (int s = 0; s <= iCapacite; s++) {
dp[(i + 1) % 2][s] =
max(dp[(i + 1) % 2][s], dp[i % 2][s]); // Ne pas prendre
if (s + sac[i].first <= iCapacite) {
dp[(i + 1) % 2][s + sac[i].first] =
max(dp[(i + 1) % 2][s + sac[i].first],
dp[i % 2][s] + sac[i].second); // Prendre
}
}
}
printf("%lld", dp[nItem % 2][iCapacite]);
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 968,750 | 968,751 | u202771336 | cpp |
p03163 | #include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
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 wv[110][2];
long long dp[110][100010];
int main() {
int N, W;
cin >> N >> W;
rep(i, 0, N) {
rep(r, 0, 2) { cin >> wv[i][r]; }
}
rep(i, 0, N) {
rep(sum, 0, W + 1) {
if (sum - wv[sum][0] >= 0) {
chmax(dp[i + 1][sum], dp[i][sum - wv[i][0]] + wv[i][1]);
}
chmax(dp[i + 1][sum], dp[i][sum]);
}
}
cout << dp[N][W] << endl;
}
| #include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
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 wv[110][2];
long long dp[110][100010];
int main() {
int N, W;
cin >> N >> W;
rep(i, 0, N) {
rep(r, 0, 2) { cin >> wv[i][r]; }
}
rep(i, 0, N) {
rep(sum, 0, W + 1) {
if (sum - wv[i][0] >= 0) {
chmax(dp[i + 1][sum], dp[i][sum - wv[i][0]] + wv[i][1]);
}
chmax(dp[i + 1][sum], dp[i][sum]);
}
}
cout << dp[N][W] << endl;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 968,760 | 968,761 | u183971632 | cpp |
p03163 | #include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
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 wv[110][2];
long long dp[110][100010];
int main() {
int N, W;
cin >> N >> W;
rep(i, 0, N) {
rep(r, 0, 2) { cin >> wv[i][r]; }
}
rep(i, 0, N) {
rep(sum, 0, W + 1) {
if (sum - wv[sum][1] >= 0) {
chmax(dp[i + 1][sum], dp[i][sum - wv[i][0]] + wv[i][1]);
}
chmax(dp[i + 1][sum], dp[i][sum]);
}
}
cout << dp[N][W] << endl;
}
| #include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
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 wv[110][2];
long long dp[110][100010];
int main() {
int N, W;
cin >> N >> W;
rep(i, 0, N) {
rep(r, 0, 2) { cin >> wv[i][r]; }
}
rep(i, 0, N) {
rep(sum, 0, W + 1) {
if (sum - wv[i][0] >= 0) {
chmax(dp[i + 1][sum], dp[i][sum - wv[i][0]] + wv[i][1]);
}
chmax(dp[i + 1][sum], dp[i][sum]);
}
}
cout << dp[N][W] << endl;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"literal.number.change"
] | 968,762 | 968,761 | u183971632 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, W;
cin >> n >> W;
long long w[n + 1], v[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
long long mat[n + 1][W + 1];
memset(mat, 0, sizeof(mat));
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j <= W; j++) {
if (!i || !j) {
mat[i][j] = 0;
} else if (j > w[i]) {
mat[i][j] = mat[i - 1][j];
} else {
mat[i][j] = max(mat[i - 1][j], v[i] + mat[i - 1][j - w[i]]);
}
}
}
cout << mat[n][W] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, W;
cin >> n >> W;
long long w[n + 1], v[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
long long mat[n + 1][W + 1];
memset(mat, 0, sizeof(mat));
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j <= W; j++) {
if (!i || !j) {
mat[i][j] = 0;
} else if (j < w[i]) {
mat[i][j] = mat[i - 1][j];
} else {
mat[i][j] = max(mat[i - 1][j], v[i] + mat[i - 1][j - w[i]]);
}
}
}
cout << mat[n][W] << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 968,763 | 968,764 | u430341757 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
inline void Boost() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;
int main() {
Boost();
int n, w;
cin >> n >> w;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i].first >> v[i].second;
vector<int> DP(w + 5);
for (int i = 0; i < n; ++i) {
for (int j = w; j >= v[i].first; --j) {
DP[j] = max(DP[j], DP[j - v[i].first] + v[i].second);
}
}
cout << DP[w];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
inline void Boost() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;
int main() {
Boost();
int n, w;
cin >> n >> w;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; ++i)
cin >> v[i].first >> v[i].second;
vector<ll> DP(w + 5);
for (int i = 0; i < n; ++i) {
for (int j = w; j >= v[i].first; --j) {
DP[j] = max(DP[j], DP[j - v[i].first] + v[i].second);
}
}
cout << DP[w];
return 0;
} | [] | 968,765 | 968,766 | u721819880 | cpp |
p03163 | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, h;
cin >> n >> h;
int w[n], v[n];
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
int z[n + 1][h + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= h; j++) {
if (i == 0 || j == 0)
z[i][j] = 0;
else if (w[i - 1] <= j) {
z[i][j] = max(z[i - 1][j], z[i - 1][j - w[i - 1]] + v[i - 1]);
} else {
z[i][j] = z[i - 1][j];
}
}
}
cout << z[n][h];
} | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, h;
cin >> n >> h;
int w[n], v[n];
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
long long int z[n + 1][h + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= h; j++) {
if (i == 0 || j == 0)
z[i][j] = 0;
else if (w[i - 1] <= j) {
z[i][j] = max(z[i - 1][j], z[i - 1][j - w[i - 1]] + v[i - 1]);
} else {
z[i][j] = z[i - 1][j];
}
}
}
cout << z[n][h];
} | [
"variable_declaration.type.widen.change"
] | 968,773 | 968,774 | u193815565 | cpp |
p03163 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
int v[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
int dp[n + 1][W + 1] = {0};
for (int i = 0; i <= n; i++) {
for (int w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (wt[i - 1] <= w) {
dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - wt[i - 1]] + v[i - 1]);
} else
dp[i][w] = dp[i - 1][w];
}
}
cout << dp[n][W];
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
int v[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
long dp[n + 1][W + 1] = {0};
for (int i = 0; i <= n; i++) {
for (int w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (wt[i - 1] <= w) {
dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - wt[i - 1]] + v[i - 1]);
} else
dp[i][w] = dp[i - 1][w];
}
}
cout << dp[n][W];
} | [
"variable_declaration.type.primitive.change"
] | 968,775 | 968,776 | u241428352 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, W, weight[101], value[101], dp[101][N];
long long int calc(int index, int w) {
if (w < 0)
return -1e12; // base case 1
if (index == n)
return 0; // base case 2
if (dp[index][w] !=
-1) // if we already calculated the case dont calculate it again
return dp[index][w];
int c1, c2;
c1 = calc(index + 1, w); // dont take the item
c2 = calc(index + 1, w - weight[index]) + value[index]; // take the item
return dp[index][w] = max(c1, c2); // store and return the calculated value
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
memset(dp, -1, sizeof(dp)); // set all items in dp[][] to -1
cout << calc(0, W);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, W, weight[101], value[101], dp[101][N];
long long int calc(int index, int w) {
if (w < 0)
return -2e12; // base case 1
if (index == n)
return 0; // base case 2
if (dp[index][w] !=
-1) // if we already calculated the case dont calculate it again
return dp[index][w];
long long int c1, c2;
c1 = calc(index + 1, w); // dont take the item
c2 = calc(index + 1, w - weight[index]) + value[index]; // take the item
return dp[index][w] = max(c1, c2); // store and return the calculated value
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
memset(dp, -1, sizeof(dp)); // set all items in dp[][] to -1
cout << calc(0, W);
return 0;
}
| [
"literal.number.change",
"function.return_value.change"
] | 968,779 | 968,780 | u221592478 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, W, weight[101], value[101], dp[101][N];
long long int calc(int index, int w) {
if (w < 0)
return -1e17; // base case 1
if (index == n)
return 0; // base case 2
if (dp[index][w] !=
-1) // if we already calculated the case dont calculate it again
return dp[index][w];
int c1, c2;
c1 = calc(index + 1, w); // dont take the item
c2 = calc(index + 1, w - weight[index]) + value[index]; // take the item
return dp[index][w] = max(c1, c2); // store and return the calculated value
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
memset(dp, -1, sizeof(dp)); // set all items in dp[][] to -1
cout << calc(0, W);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, W, weight[101], value[101], dp[101][N];
long long int calc(int index, int w) {
if (w < 0)
return -2e12; // base case 1
if (index == n)
return 0; // base case 2
if (dp[index][w] !=
-1) // if we already calculated the case dont calculate it again
return dp[index][w];
long long int c1, c2;
c1 = calc(index + 1, w); // dont take the item
c2 = calc(index + 1, w - weight[index]) + value[index]; // take the item
return dp[index][w] = max(c1, c2); // store and return the calculated value
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
memset(dp, -1, sizeof(dp)); // set all items in dp[][] to -1
cout << calc(0, W);
return 0;
}
| [
"literal.number.change",
"function.return_value.change"
] | 968,781 | 968,780 | u221592478 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, W, weight[101], value[101], dp[101][N];
long long int calc(int index, int w) {
if (w < 0)
return -1e9; // base case 1
if (index == n)
return 0; // base case 2
if (dp[index][w] !=
-1) // if we already calculated the case dont calculate it again
return dp[index][w];
int c1, c2;
c1 = calc(index + 1, w); // dont take the item
c2 = calc(index + 1, w - weight[index]) + value[index]; // take the item
return dp[index][w] = max(c1, c2); // store and return the calculated value
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
memset(dp, -1, sizeof(dp)); // set all items in dp[][] to -1
cout << calc(0, W);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long int n, W, weight[101], value[101], dp[101][N];
long long int calc(int index, int w) {
if (w < 0)
return -2e12; // base case 1
if (index == n)
return 0; // base case 2
if (dp[index][w] !=
-1) // if we already calculated the case dont calculate it again
return dp[index][w];
long long int c1, c2;
c1 = calc(index + 1, w); // dont take the item
c2 = calc(index + 1, w - weight[index]) + value[index]; // take the item
return dp[index][w] = max(c1, c2); // store and return the calculated value
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
memset(dp, -1, sizeof(dp)); // set all items in dp[][] to -1
cout << calc(0, W);
return 0;
}
| [
"literal.number.change",
"function.return_value.change"
] | 968,782 | 968,780 | u221592478 | cpp |
p03163 | #include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mk make_pair
#define pb push_back
#define pp pop_back
using namespace std;
const ll N = 1e5 + 100;
ll a[N], b[N], n, w, dp[101][N];
vector<vector<int>> v;
int cal(int index, int sum) {
if (sum > w) {
return -1e6;
}
if (index == n) {
return 0;
}
if (dp[index][sum] != -1) {
return dp[index][sum];
}
// cout << index << " " << sum << endl;
// return max(cal(index+1,sum+a[index]) + b[index],cal(index+1,sum));
int val22 = cal(index + 1, sum);
int val11 = cal(index + 1, sum + a[index]) + b[index];
return dp[index][sum] = max(val11, val22);
}
int main() {
// cout << "Hello wolrd" ;
cin >> n >> w;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
memset(dp, -1, sizeof dp);
cout << cal(0, 0);
} | #include <bits/stdc++.h>
#define f first
#define s second
#define ll long long
#define mk make_pair
#define pb push_back
#define pp pop_back
using namespace std;
const ll N = 1e5 + 100;
ll a[N], b[N], n, w, dp[101][N];
vector<vector<int>> v;
ll cal(int index, int sum) {
if (sum > w) {
return -1e12;
}
if (index == n) {
return 0;
}
if (dp[index][sum] != -1) {
return dp[index][sum];
}
// cout << index << " " << sum << endl;
// return max(cal(index+1,sum+a[index]) + b[index],cal(index+1,sum));
ll val22 = cal(index + 1, sum);
ll val11 = cal(index + 1, sum + a[index]) + b[index];
return dp[index][sum] = max(val11, val22);
}
int main() {
// cout << "Hello wolrd" ;
cin >> n >> w;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
}
memset(dp, -1, sizeof dp);
cout << cal(0, 0);
} | [
"literal.number.change",
"function.return_value.change",
"variable_declaration.type.change"
] | 968,786 | 968,784 | u463187227 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 123456;
ll dp[110][maxn];
int w[110], v[110];
const int inf = 0x7f7f7f7f;
int main() {
// freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, W;
cin >> n >> W;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
// dp[i][0] = v[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j + w[i] <= W; ++j) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if (w[i] + j <= W) {
dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
}
}
// for(int i = 0; i <= n; ++i){
// for(int j = 0; j <= W; ++j){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
ll res = 0;
for (int i = 0; i <= W; ++i) {
res = max(res, dp[n][i]);
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 123456;
ll dp[110][maxn];
int w[110], v[110];
const int inf = 0x7f7f7f7f;
int main() {
// freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, W;
cin >> n >> W;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
// dp[i][0] = v[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= W; ++j) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if (w[i] + j <= W) {
dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
}
}
// for(int i = 0; i <= n; ++i){
// for(int j = 0; j <= W; ++j){
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
ll res = 0;
for (int i = 0; i <= W; ++i) {
res = max(res, dp[n][i]);
}
cout << res << endl;
return 0;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 968,797 | 968,798 | u608624039 | cpp |
p03163 | // knapsack
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define pb push_back
#define ll long long int
#define mod 1000000007
const int N = 1e5 + 5;
int n, w;
int wt[1000];
int val[1000];
int cache[100 + 5][N];
int dp(int pos, int sum) {
if (pos == n)
return -1e15;
if (cache[pos][sum] != -1)
return cache[pos][sum];
if (sum + wt[pos] > w)
cache[pos][sum] = dp(pos + 1, sum);
else
cache[pos][sum] =
max(dp(pos + 1, sum), dp(pos + 1, sum + wt[pos]) + val[pos]);
return cache[pos][sum];
}
int32_t main() {
fastIO;
int i;
cin >> n >> w;
for (i = 0; i < n; i++)
cin >> wt[i] >> val[i];
memset(cache, -1, sizeof(cache));
cout << dp(0, 0) << "\n";
return 0;
} | // knapsack
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define pb push_back
#define int long long int
#define mod 1000000007
const int N = 1e5 + 5;
int n, w;
int wt[1000];
int val[1000];
int cache[100 + 5][N];
int dp(int pos, int sum) {
if (pos == n)
return 0;
if (cache[pos][sum] != -1)
return cache[pos][sum];
if (sum + wt[pos] > w)
cache[pos][sum] = dp(pos + 1, sum);
else
cache[pos][sum] =
max(dp(pos + 1, sum), dp(pos + 1, sum + wt[pos]) + val[pos]);
return cache[pos][sum];
}
int32_t main() {
fastIO;
int i;
cin >> n >> w;
for (i = 0; i < n; i++)
cin >> wt[i] >> val[i];
memset(cache, -1, sizeof(cache));
cout << dp(0, 0) << "\n";
return 0;
}
| [
"identifier.change",
"literal.number.change",
"function.return_value.change"
] | 968,799 | 968,800 | u534846896 | cpp |
p03163 | // knapsack
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define pb push_back
#define ll long long int
#define mod 1000000007
const int N = 1e5 + 5;
int n, w;
int wt[1000];
int val[1000];
int cache[100 + 5][N];
int dp(int pos, int sum) {
if (pos == n)
return 0;
if (cache[pos][sum] != -1)
return cache[pos][sum];
if (sum + wt[pos] > w)
cache[pos][sum] = dp(pos + 1, sum);
else
cache[pos][sum] =
max(dp(pos + 1, sum), dp(pos + 1, sum + wt[pos]) + val[pos]);
return cache[pos][sum];
}
int32_t main() {
fastIO;
int i;
cin >> n >> w;
for (i = 0; i < n; i++)
cin >> wt[i] >> val[i];
memset(cache, -1, sizeof(cache));
cout << dp(0, 0) << "\n";
return 0;
} | // knapsack
#include <bits/stdc++.h>
using namespace std;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define pb push_back
#define int long long int
#define mod 1000000007
const int N = 1e5 + 5;
int n, w;
int wt[1000];
int val[1000];
int cache[100 + 5][N];
int dp(int pos, int sum) {
if (pos == n)
return 0;
if (cache[pos][sum] != -1)
return cache[pos][sum];
if (sum + wt[pos] > w)
cache[pos][sum] = dp(pos + 1, sum);
else
cache[pos][sum] =
max(dp(pos + 1, sum), dp(pos + 1, sum + wt[pos]) + val[pos]);
return cache[pos][sum];
}
int32_t main() {
fastIO;
int i;
cin >> n >> w;
for (i = 0; i < n; i++)
cin >> wt[i] >> val[i];
memset(cache, -1, sizeof(cache));
cout << dp(0, 0) << "\n";
return 0;
}
| [
"identifier.change"
] | 968,801 | 968,800 | u534846896 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
const int N = 100007;
int A[N], W[N];
int main() {
int n, w;
cin >> n >> w;
int dp[n + 1][w + 1];
for (int i = 0; i < n; ++i)
cin >> W[i] >> A[i];
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 >= W[i - 1])
dp[i][j] = max(dp[i - 1][j], A[i - 1] + dp[i - 1][j - W[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 100007;
long long A[N], W[N];
int main() {
int n, w;
cin >> n >> w;
long long dp[n + 1][w + 1];
for (int i = 0; i < n; ++i)
cin >> W[i] >> A[i];
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 >= W[i - 1])
dp[i][j] = max(dp[i - 1][j], A[i - 1] + dp[i - 1][j - W[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,811 | 968,812 | u588613695 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
W++;
vector<int> v(N), w(N);
vector<vector<int>> dp(N, vector<int>(W, 0));
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int s = w[0]; s < W; s++) {
dp[0][s] = v[0];
}
for (int i = 1; i < N; i++) {
for (int s = 0; s < w[i]; s++) {
dp[i][s] = dp[i - 1][s];
}
for (int s = w[i]; s < W; s++) {
dp[i][s] = max(dp[i - 1][s], dp[i - 1][s - w[i]] + v[i]);
}
}
cout << dp[N - 1][W - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
W++;
vector<int> v(N), w(N);
vector<vector<long>> dp(N, vector<long>(W, 0));
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int s = w[0]; s < W; s++) {
dp[0][s] = v[0];
}
for (int i = 1; i < N; i++) {
for (int s = 0; s < w[i]; s++) {
dp[i][s] = dp[i - 1][s];
}
for (int s = w[i]; s < W; s++) {
dp[i][s] = max(dp[i - 1][s], dp[i - 1][s - w[i]] + v[i]);
}
}
cout << dp[N - 1][W - 1] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change"
] | 968,822 | 968,823 | u506320030 | cpp |
p03163 | #include <bits/stdc++.h>
#define Nmax 100005
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
ifstream f("1.in");
ofstream g("1.out");
int n, k, dp[105][Nmax];
int w, v, W, ans;
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w >> v;
for (int j = 0; j <= W; j++)
if (j >= w)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v);
else
dp[i][j] = dp[i - 1][j];
}
/* for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= W; j++)
cout << dp[i][j] << " ";
cout << '\n';
}*/
for (int i = 1; i <= W; i++)
ans = max(ans, dp[n][i]);
cout << ans;
}
| #include <bits/stdc++.h>
#define Nmax 100005
#include <cmath>
#define INF 0x3f3f3f3f
using namespace std;
ifstream f("1.in");
ofstream g("1.out");
long long n, k, dp[105][Nmax];
long long w, v, W, ans;
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w >> v;
for (int j = 0; j <= W; j++)
if (j >= w)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w] + v);
else
dp[i][j] = dp[i - 1][j];
}
/* for (int i = 1; i <= n; i++)
{
for (int j = 0; j <= W; j++)
cout << dp[i][j] << " ";
cout << '\n';
}*/
for (int i = 1; i <= W; i++)
ans = max(ans, dp[n][i]);
cout << ans;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,824 | 968,825 | u275238097 | cpp |
p03163 | #include <cstdlib>
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, w;
cin >> n >> w;
int d[n], v[n];
int a[w + 1];
for (int i = 0; i < w + 1; i++)
a[i] = 0;
for (int i = 0; i < n; i++)
cin >> d[i] >> v[i];
for (int i = 0; i < n; i++)
for (int j = w; j >= d[i]; j--)
a[j] = max(a[j], a[j - d[i]] + v[i]);
cout << a[w] << endl;
}
| #include <cstdlib>
#include <iostream>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, w;
cin >> n >> w;
long long d[n], v[n];
long long a[w + 1];
for (int i = 0; i < w + 1; i++)
a[i] = 0;
for (int i = 0; i < n; i++)
cin >> d[i] >> v[i];
for (int i = 0; i < n; i++)
for (int j = w; j >= d[i]; j--)
a[j] = max(a[j], a[j - d[i]] + v[i]);
cout << a[w] << endl;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,826 | 968,827 | u276066929 | cpp |
p03163 | /*
solution by :
Beksultan Almazbekov
;
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int w[3546], v[3546], q[123123];
int main() {
int mx = INT_MIN, n, m, i, j;
cin >> n >> m;
for (i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
for (i = 0; i < n; ++i) {
for (j = m; j >= w[i]; --j) {
mx = max(mx, q[j] = max(q[j], q[j - w[i]] + v[i]));
}
}
cout << mx;
} | /*
solution by :
Beksultan Almazbekov
;
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll w[3546], v[3546], q[123123];
int main() {
ll mx = 0, n, m, i, j;
cin >> n >> m;
for (i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
for (i = 0; i < n; ++i) {
for (j = m; j >= w[i]; --j) {
mx = max(mx, q[j] = max(q[j], q[j - w[i]] + v[i]));
}
}
cout << mx;
} | [
"variable_declaration.type.change",
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 968,828 | 968,829 | u330398764 | cpp |
p03163 | // finish date: 2019/2/22
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;
int main() {
int N, W;
cin >> N >> W;
vi w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
vvl dp(N, vl(W + 1, 0));
dp[0][w[0]] = v[0];
ll ma = 0;
FOR(i, 1, N) {
dp[i][w[i]] = v[0];
rep(j, W + 1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j + w[i] <= W && dp[i - 1][j] != 0)
dp[i][j + w[i]] = max(dp[i][j + w[i]], v[i] + dp[i - 1][j]);
}
}
rep(i, N) rep(j, W + 1) ma = max(ma, dp[i][j]);
cout << ma << endl;
return 0;
} | // finish date: 2019/2/22
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;
int main() {
int N, W;
cin >> N >> W;
vi w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
vvl dp(N, vl(W + 1, 0));
dp[0][w[0]] = v[0];
ll ma = 0;
FOR(i, 1, N) {
dp[i][w[i]] = v[i];
rep(j, W + 1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
if (j + w[i] <= W && dp[i - 1][j] != 0)
dp[i][j + w[i]] = max(dp[i][j + w[i]], v[i] + dp[i - 1][j]);
}
}
rep(i, N) rep(j, W + 1) ma = max(ma, dp[i][j]);
cout << ma << endl;
return 0;
} | [
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove",
"variable_access.subscript.index.change"
] | 968,832 | 968,833 | u285660186 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
int w;
cin >> w;
vector<int> wt;
vector<int> val;
for (int i = 0; i < n; i++) {
int u;
cin >> u;
wt.push_back(u);
cin >> u;
val.push_back(u);
}
int dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
}
}
cout << dp[n][w];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
int w;
cin >> w;
vector<int> wt;
vector<int> val;
for (int i = 0; i < n; i++) {
int u;
cin >> u;
wt.push_back(u);
cin >> u;
val.push_back(u);
}
long long int dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
}
}
cout << dp[n][w];
return 0;
} | [
"variable_declaration.type.widen.change"
] | 968,834 | 968,835 | u988725912 | cpp |
p03163 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;
using namespace std;
int n, w;
int wei[101], val[100001];
int dp[101][100001];
ll napzac(int i, int j) {
if (dp[i][j] >= 0) {
return dp[i][j];
}
ll res;
if (i == n) {
res = 0;
} else if (j < wei[i]) {
res = napzac(i + 1, j);
} else {
res = max(napzac(i + 1, j), napzac(i + 1, j - wei[i]) + val[i]);
}
return dp[i][j] = res;
}
int main() {
cin >> n >> w;
REP(i, n) { cin >> wei[i] >> val[i]; }
memset(dp, -1, sizeof(dp));
cout << napzac(0, w);
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;
using namespace std;
int n, w;
int wei[101], val[100001];
ll dp[101][100001];
ll napzac(int i, int j) {
if (dp[i][j] >= 0) {
return dp[i][j];
}
ll res;
if (i == n) {
res = 0;
} else if (j < wei[i]) {
res = napzac(i + 1, j);
} else {
res = max(napzac(i + 1, j), napzac(i + 1, j - wei[i]) + val[i]);
}
return dp[i][j] = res;
}
int main() {
cin >> n >> w;
REP(i, n) { cin >> wei[i] >> val[i]; }
memset(dp, -1, sizeof(dp));
cout << napzac(0, w);
return 0;
} | [
"variable_declaration.type.change"
] | 968,836 | 968,837 | u629194491 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
long long f[101][100001] = {0};
int w[101], v[101];
int main() {
int n, W, i, j;
scanf("%d %d", &n, &W);
for (i = 1; i <= n; i++)
scanf("%d %d", &w[i], &v[i]);
for (i = 1; i <= n; i++) {
for (j = 1; j <= W; j++) {
if (j < w[i])
f[i][j] = f[i - 1][j];
else
f[i][j] = max(f[i - 1][j], f[i - 1][j - w[i]] + v[i]);
}
}
printf("%d", f[n][W]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long f[101][100001] = {0};
int w[101], v[101];
int main() {
int n, W, i, j;
scanf("%d %d", &n, &W);
for (i = 1; i <= n; i++)
scanf("%d %d", &w[i], &v[i]);
for (i = 1; i <= n; i++) {
for (j = 1; j <= W; j++) {
if (j < w[i])
f[i][j] = f[i - 1][j];
else
f[i][j] = max(f[i - 1][j], f[i - 1][j - w[i]] + v[i]);
}
}
printf("%lld", f[n][W]);
return 0;
} | [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 968,849 | 968,850 | u379393519 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int f[101][100001] = {0}, w[101], v[101];
int main() {
int n, W, i, j;
scanf("%d %d", &n, &W);
for (i = 1; i <= n; i++)
scanf("%d %d", &w[i], &v[i]);
for (i = 1; i <= n; i++) {
for (j = 1; j <= W; j++) {
if (j < w[i])
f[i][j] = f[i - 1][j];
else
f[i][j] = max(f[i - 1][j], f[i - 1][j - w[i]] + v[i]);
}
}
printf("%d", f[n][W]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long f[101][100001] = {0};
int w[101], v[101];
int main() {
int n, W, i, j;
scanf("%d %d", &n, &W);
for (i = 1; i <= n; i++)
scanf("%d %d", &w[i], &v[i]);
for (i = 1; i <= n; i++) {
for (j = 1; j <= W; j++) {
if (j < w[i])
f[i][j] = f[i - 1][j];
else
f[i][j] = max(f[i - 1][j], f[i - 1][j - w[i]] + v[i]);
}
}
printf("%lld", f[n][W]);
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 968,851 | 968,850 | u379393519 | cpp |
p03163 | #include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d", &(x))
#define ri2(x, y) scanf("%d %d", &(x), &(y))
#define ri3(x, y, z) scanf("%d %d %d", &(x), &(y), &(z))
#define rll(x) scanf("%lld", &(x))
#define rll2(x, y) scanf("%lld %lld", &(x), &(y))
#define rll3(x, y, z) scanf("%lld %lld %lld", &(x), &(y), &(z))
#define gc(x) ((x) = getchar())
using namespace ::std;
const long double PI = acos(-1);
const long long MOD = 1000000000 + 7;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> tll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll add(ll a, ll b, ll m = MOD) { return (a % m + b % m + 2 * m) % m; }
ll mul(ll a, ll b, ll m = MOD) { return ((a % m + m) * (b % m + m)) % m; }
ll pow_mod(ll a, ll b, ll m = MOD) {
ll res = 1LL;
a = a % m;
while (b) {
if (b & 1)
res = mul(res, a, m);
b >>= 1;
a = mul(a, a, m);
}
return res;
}
ll fastexp(ll a, ll b) {
ll res = 1LL;
while (b) {
if (b & 1)
res = res * a;
b >>= 1;
a *= a;
}
return res;
}
int gcdExtendido(int a, int b, int *x, int *y) {
if (a == 0) {
*x = 0;
*y = 1;
return b;
}
int x1, y1;
int gcd = gcdExtendido(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
int modInverso(int a, int m) {
int x, y;
int g = gcdExtendido(a, m, &x, &y);
if (g != 1)
return -1;
else
return (x % m + m) % m;
}
/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/
const int N = 100 + 5;
const int W = 100000 + 5;
const int inf = 1 << 30;
int n;
int C;
int w[N];
int v[N];
int memo[N][W];
int main() {
ri2(n, C);
for (int i = 1; i <= n; i++) {
ri2(w[i], v[i]);
}
// Inicializar en -inf
// excepto el peso 0, que
// trivialmente cumple con ser 0
// el valor maximo que puede dar
for (int i = 0; i <= C; i++)
memo[0][i] = -inf;
memo[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int c = 0; c <= C; c++) {
memo[i][c] = memo[i - 1][c];
if (c >= w[i]) {
memo[i][c] = max(memo[i][c], memo[i - 1][c - w[i]] + v[i]);
}
}
}
int ans = 0;
for (int i = 0; i <= C; i++) {
ans = max(ans, memo[n][i]);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d", &(x))
#define ri2(x, y) scanf("%d %d", &(x), &(y))
#define ri3(x, y, z) scanf("%d %d %d", &(x), &(y), &(z))
#define rll(x) scanf("%lld", &(x))
#define rll2(x, y) scanf("%lld %lld", &(x), &(y))
#define rll3(x, y, z) scanf("%lld %lld %lld", &(x), &(y), &(z))
#define gc(x) ((x) = getchar())
using namespace ::std;
const long double PI = acos(-1);
const long long MOD = 1000000000 + 7;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> tll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll add(ll a, ll b, ll m = MOD) { return (a % m + b % m + 2 * m) % m; }
ll mul(ll a, ll b, ll m = MOD) { return ((a % m + m) * (b % m + m)) % m; }
ll pow_mod(ll a, ll b, ll m = MOD) {
ll res = 1LL;
a = a % m;
while (b) {
if (b & 1)
res = mul(res, a, m);
b >>= 1;
a = mul(a, a, m);
}
return res;
}
ll fastexp(ll a, ll b) {
ll res = 1LL;
while (b) {
if (b & 1)
res = res * a;
b >>= 1;
a *= a;
}
return res;
}
int gcdExtendido(int a, int b, int *x, int *y) {
if (a == 0) {
*x = 0;
*y = 1;
return b;
}
int x1, y1;
int gcd = gcdExtendido(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
int modInverso(int a, int m) {
int x, y;
int g = gcdExtendido(a, m, &x, &y);
if (g != 1)
return -1;
else
return (x % m + m) % m;
}
/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/
const int N = 100 + 5;
const int W = 100000 + 5;
const ll inf = 1LL << 60;
int n;
int C;
int w[N];
int v[N];
ll memo[N][W];
int main() {
ri2(n, C);
for (int i = 1; i <= n; i++) {
ri2(w[i], v[i]);
}
// Inicializar en -inf
// excepto el peso 0, que
// trivialmente cumple con ser 0
// el valor maximo que puede dar
for (int i = 0; i <= C; i++)
memo[0][i] = -inf;
memo[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int c = 0; c <= C; c++) {
memo[i][c] = memo[i - 1][c];
if (c >= w[i]) {
memo[i][c] = max(memo[i][c], memo[i - 1][c - w[i]] + v[i]);
}
}
}
ll ans = 0;
for (int i = 0; i <= C; i++) {
ans = max(ans, memo[n][i]);
}
cout << ans << endl;
return 0;
}
| [
"variable_declaration.type.change",
"literal.number.type.widen.change",
"literal.number.change",
"expression.operation.binary.change"
] | 968,852 | 968,853 | u200221740 | cpp |
p03163 | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, j, k) for (int(i) = (j); (i) < (int)(k); ++(i))
#define rep(i, j) FOR(i, 0, j)
#define each(x, y) for (auto &(x) : (y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << (x) << endl
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define MEM(x, y) memset((x), (y), sizeof(x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
void solve() {
int N, W;
cin >> N >> W;
vi dp(W + 1);
rep(i, N) {
int w, v;
cin >> w >> v;
for (int j = W - w; j >= 0; --j) {
smax(dp[j + w], dp[j] + v);
}
}
cout << dp.back() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}
| #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, j, k) for (int(i) = (j); (i) < (int)(k); ++(i))
#define rep(i, j) FOR(i, 0, j)
#define each(x, y) for (auto &(x) : (y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << (x) << endl
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define MEM(x, y) memset((x), (y), sizeof(x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
void solve() {
int N, W;
cin >> N >> W;
vll dp(W + 1);
rep(i, N) {
int w, v;
cin >> w >> v;
for (int j = W - w; j >= 0; --j) {
smax(dp[j + w], dp[j] + v);
}
}
cout << dp.back() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}
| [
"variable_declaration.type.change"
] | 968,858 | 968,859 | u750436322 | cpp |
p03163 | #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, j, k) for (int(i) = (j); (i) < (int)(k); ++(i))
#define rep(i, j) FOR(i, 0, j)
#define each(x, y) for (auto &(x) : (y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << (x) << endl
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define MEM(x, y) memset((x), (y), sizeof(x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
void solve() {
int N, W;
cin >> N >> W;
vi dp(W + 1);
rep(i, N) {
int w, v;
cin >> w >> v;
for (int j = W - w; j >= 0; ++j) {
smax(dp[j + w], dp[j] + v);
}
}
cout << dp.back() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}
| #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i, j, k) for (int(i) = (j); (i) < (int)(k); ++(i))
#define rep(i, j) FOR(i, 0, j)
#define each(x, y) for (auto &(x) : (y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << (x) << endl
#define smax(x, y) (x) = max((x), (y))
#define smin(x, y) (x) = min((x), (y))
#define MEM(x, y) memset((x), (y), sizeof(x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
void solve() {
int N, W;
cin >> N >> W;
vll dp(W + 1);
rep(i, N) {
int w, v;
cin >> w >> v;
for (int j = W - w; j >= 0; --j) {
smax(dp[j + w], dp[j] + v);
}
}
cout << dp.back() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
solve();
return 0;
}
| [
"variable_declaration.type.change"
] | 968,860 | 968,859 | u750436322 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long ww;
cin >> ww;
long long w[n];
long long v[n];
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i];
}
long long dp[ww + 1][n + 1];
long long x, y;
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= ww; j++) {
x = dp[i - 1][j];
if (j >= v[i - 1])
y = dp[i - 1][j - v[i - 1]] + w[i - 1];
else
y = 0;
dp[i][j] = max(x, y);
}
} /*
for(int i=0;i<=n;i++){
for(int j=0;j<=ww;j++){
cout<<dp[i][j]<<" ";
}
cout<<"\n";
}*/
cout << dp[n][ww];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
int ww;
cin >> ww;
long long w[n];
long long v[n];
for (int i = 0; i < n; i++) {
cin >> v[i] >> w[i];
}
long long dp[n + 1][ww + 1];
long long x, y;
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= ww; j++) {
x = dp[i - 1][j];
if (j >= v[i - 1])
y = dp[i - 1][j - v[i - 1]] + w[i - 1];
else
y = 0;
dp[i][j] = max(x, y);
}
}
cout << dp[n][ww];
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.narrow.change",
"identifier.change",
"expression.operation.binary.change"
] | 968,861 | 968,862 | u401648470 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) s.size()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define fill(a, v) memset(a, v, sizeof(a))
#define tc \
int T; \
cin >> T; \
while (T--)
#define nl printf("\n")
#define aya printf("yaha aya\n")
#define debug(x, y) printf("%d %d\n", x, y)
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define grt greater<int>()
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 9;
inline int pow_(ll a, int n, int p = mod) {
int r = 1;
while (n) {
if (n & 1)
r = r * a % p;
n >>= 1;
a = a * a % p;
}
return r;
}
int main(void) {
int N, W;
cin >> N >> W;
int w[N], v[N];
rep(i, 0, N - 1) cin >> w[i] >> v[i];
int dp[N + 1][W + 1];
fill(dp, 0);
rep(i, 0, N) rep(j, 0, W) if (i == 0 or j == 0) dp[i][j] = 0;
else if (w[i - 1] > j) dp[i][j] = dp[i - 1][j];
else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
cout << dp[N][W] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) s.size()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define fill(a, v) memset(a, v, sizeof(a))
#define tc \
int T; \
cin >> T; \
while (T--)
#define nl printf("\n")
#define aya printf("yaha aya\n")
#define debug(x, y) printf("%d %d\n", x, y)
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define grt greater<int>()
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 9;
inline int pow_(ll a, int n, int p = mod) {
int r = 1;
while (n) {
if (n & 1)
r = r * a % p;
n >>= 1;
a = a * a % p;
}
return r;
}
int main(void) {
int N, W;
cin >> N >> W;
int w[N], v[N];
rep(i, 0, N - 1) cin >> w[i] >> v[i];
ll dp[N + 1][W + 1];
fill(dp, 0);
rep(i, 0, N) rep(j, 0, W) if (i == 0 or j == 0) dp[i][j] = 0;
else if (w[i - 1] > j) dp[i][j] = dp[i - 1][j];
else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
cout << dp[N][W] << "\n";
} | [
"variable_declaration.type.change"
] | 968,863 | 968,864 | u817703858 | cpp |
p03163 |
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <utility>
#include <vector>
#define MAX_DOUBLE 40000000000.0
#include <math.h>
#include <unistd.h>
using namespace std;
int min(int a, int b) {
if (a > b)
return b;
return a;
}
long long max(long long a, long long b) {
if (a < b)
return b;
return a;
}
long long values[100010];
long long weights[100010];
map<pair<int, int>, long long> res;
int knapSack(int W, int n) {
int i, w;
long long K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (weights[i - 1] <= w)
K[i][w] =
max(values[i - 1] + K[i - 1][w - weights[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
}
cout << knapSack(w, n);
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <utility>
#include <vector>
#define MAX_DOUBLE 40000000000.0
#include <math.h>
#include <unistd.h>
using namespace std;
int min(int a, int b) {
if (a > b)
return b;
return a;
}
long long max(long long a, long long b) {
if (a < b)
return b;
return a;
}
long long values[100010];
long long weights[100010];
map<pair<int, int>, long long> res;
long long knapSack(int W, int n) {
int i, w;
long long K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (weights[i - 1] <= w)
K[i][w] =
max(values[i - 1] + K[i - 1][w - weights[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
}
cout << knapSack(w, n);
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,872 | 968,873 | u492909866 | cpp |
p03163 |
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <utility>
#include <vector>
#define MAX_DOUBLE 40000000000.0
#include <math.h>
#include <unistd.h>
using namespace std;
int min(int a, int b) {
if (a > b)
return b;
return a;
}
long long max(long long a, long long b) {
if (a < b)
return b;
return a;
}
long long values[100010];
long long weights[100010];
map<pair<int, int>, long long> res;
int knapSack(int W, int n) {
int i, w;
int K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (weights[i - 1] <= w)
K[i][w] =
max(values[i - 1] + K[i - 1][w - weights[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
}
cout << knapSack(w, n);
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <utility>
#include <vector>
#define MAX_DOUBLE 40000000000.0
#include <math.h>
#include <unistd.h>
using namespace std;
int min(int a, int b) {
if (a > b)
return b;
return a;
}
long long max(long long a, long long b) {
if (a < b)
return b;
return a;
}
long long values[100010];
long long weights[100010];
map<pair<int, int>, long long> res;
long long knapSack(int W, int n) {
int i, w;
long long K[n + 1][W + 1];
for (i = 0; i <= n; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (weights[i - 1] <= w)
K[i][w] =
max(values[i - 1] + K[i - 1][w - weights[i - 1]], K[i - 1][w]);
else
K[i][w] = K[i - 1][w];
}
}
return K[n][W];
}
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
}
cout << knapSack(w, n);
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,874 | 968,873 | u492909866 | cpp |
p03163 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
int N, W;
cin >> N >> W;
int w[N], v[N];
REP(i, N) { cin >> w[i] >> v[i]; }
llong score[N][W];
REP(i, W) {
if (i >= w[0]) {
score[0][i] = v[0];
} else {
score[0][i] = 0;
}
}
for (int i = 1; i < N; i++) {
REP(j, W) {
if (j >= w[i]) {
score[i][j] = max(score[i - 1][j], score[i - 1][j - w[i]] + v[i]);
} else {
score[i][j] = score[i - 1][j];
}
}
}
cout << score[N - 1][W - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
int N, W;
cin >> N >> W;
W++;
int w[N], v[N];
REP(i, N) { cin >> w[i] >> v[i]; }
llong score[N][W];
REP(i, W) {
if (i >= w[0]) {
score[0][i] = v[0];
} else {
score[0][i] = 0;
}
}
for (int i = 1; i < N; i++) {
REP(j, W) {
if (j >= w[i]) {
score[i][j] = max(score[i - 1][j], score[i - 1][j - w[i]] + v[i]);
} else {
score[i][j] = score[i - 1][j];
}
}
}
cout << score[N - 1][W - 1] << endl;
return 0;
} | [
"expression.unary.arithmetic.add"
] | 968,875 | 968,876 | u118846704 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define all(a) a.begin(), a.end()
#define VV(T) vector<vector<T>>
#define rep(i, N) for (int i = 0; i < N; i++)
#define fill(x, y) memset(x, y, sizeof(x))
#define name(x) #x
using namespace std;
const int INF = INT_MAX - 100;
const int MOD = pow(10, 9) + 7;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef long long ll, LL;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;
// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
}
return os;
}
int main() {
int N, W;
cin >> N >> W;
VV(int) vec(N + 1, vector<int>(2, 0));
for (auto i = 1; i <= N; i++) {
cin >> vec[i];
}
VV(int) dp(N + 1, vector<int>(W + 1, 0));
for (auto i = 1; i <= N; i++) {
for (auto w = 0; w <= W; w++) {
if (w - vec[i][0] >= 0) {
dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - vec[i][0]] + vec[i][1]);
} else {
dp[i][w] = dp[i - 1][w];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define all(a) a.begin(), a.end()
#define VV(T) vector<vector<T>>
#define rep(i, N) for (int i = 0; i < N; i++)
#define fill(x, y) memset(x, y, sizeof(x))
#define name(x) #x
using namespace std;
const int INF = INT_MAX - 100;
const int MOD = pow(10, 9) + 7;
int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef long long ll, LL;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pLL;
// vector入力
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// vector出力
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
}
return os;
}
int main() {
int N, W;
cin >> N >> W;
VV(ll) vec(N + 1, vector<ll>(2, 0));
for (auto i = 1; i <= N; i++) {
cin >> vec[i];
}
VV(ll) dp(N + 1, vector<ll>(W + 1, 0));
for (auto i = 1; i <= N; i++) {
for (auto w = 0; w <= W; w++) {
if (w - vec[i][0] >= 0) {
dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - vec[i][0]] + vec[i][1]);
} else {
dp[i][w] = dp[i - 1][w];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
| [
"call.arguments.change"
] | 968,877 | 968,878 | u966854856 | cpp |
p03163 | #include <algorithm>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, m, n) for (int i = m; i < n; i++)
using namespace std;
using ll = long long;
const ll inf = 1LL << 50;
int main() {
int N, W;
cin >> N >> W;
vector<vector<int>> data;
rep(i, 0, N) {
int w, v;
cin >> w >> v;
data.push_back({w, v});
}
vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
rep(i, 1, N + 1) {
rep(j, 0, W + 1) {
if (j - data[i - 1][0] >= 0) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - data[i - 1][0]] + data[i - 1][1]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
| #include <algorithm>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define rep(i, m, n) for (int i = m; i < n; i++)
using namespace std;
using ll = long long;
const ll inf = 1LL << 50;
int main() {
int N, W;
cin >> N >> W;
vector<vector<ll>> data;
rep(i, 0, N) {
ll w, v;
cin >> w >> v;
data.push_back({w, v});
}
// dp[i][j]:i個の品物の中からjを超えないようにとった時の価値の最大値
vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
rep(i, 1, N + 1) {
rep(j, 0, W + 1) {
if (j - data[i - 1][0] >= 0) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - data[i - 1][0]] + data[i - 1][1]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
| [
"variable_declaration.type.change",
"call.arguments.change"
] | 968,897 | 968,898 | u724732842 | cpp |
p03163 | #include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i + 1])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 968,906 | 968,907 | u010393289 | cpp |
p03163 | #include <algorithm>
#include <iostream>
using namespace std;
int dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,908 | 968,907 | u010393289 | cpp |
p03163 | #include <algorithm>
#include <iostream>
using namespace std;
int dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i + 1])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 968,909 | 968,907 | u010393289 | cpp |
p03163 | #include <algorithm>
#include <iostream>
using namespace std;
int dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,910 | 968,907 | u010393289 | cpp |
p03163 | #include <algorithm>
#include <iostream>
using namespace std;
int dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 1; i <= N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i + 1])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"... | 968,912 | 968,907 | u010393289 | cpp |
p03163 | #include <algorithm>
#include <iostream>
using namespace std;
int dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 1; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 1; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 968,913 | 968,907 | u010393289 | cpp |
p03163 | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, W, w[101], v[101];
int dp[101][201010];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> W;
rep(i, 0, N) cin >> w[i] >> v[i];
rep(i, 0, N) rep(tot, 0, W) {
chmax(dp[i + 1][tot], dp[i][tot]);
chmax(dp[i + 1][tot + w[i]], dp[i][tot] + v[i]);
}
int ans = 0;
rep(tot, 0, W + 1) chmax(ans, dp[N][tot]);
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int N, W, w[101], v[101];
ll dp[101][201010];
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> W;
rep(i, 0, N) cin >> w[i] >> v[i];
rep(i, 0, N) rep(tot, 0, W) {
chmax(dp[i + 1][tot], dp[i][tot]);
chmax(dp[i + 1][tot + w[i]], dp[i][tot] + v[i]);
}
ll ans = 0;
rep(tot, 0, W + 1) chmax(ans, dp[N][tot]);
cout << ans << endl;
}
| [
"variable_declaration.type.change"
] | 968,914 | 968,915 | u141378465 | cpp |
p03163 | /* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of
* doing nothing :/
*/
// Author:: Subash Singha Roy
// Institution:: Jalpaiguri Government Engineering College
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod (int)(1e9 + 7)
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frr(i, a, b) for (ll i = a - 1; i >= b; i--)
#define tc(t) \
int t; \
cin >> t; \
while (t--)
#define pb(i) push_back(i)
#define rr return 0
#define mp make_pair
#define pr pair<ll, ll>
#define ff first
#define ss second
#define inf 999999999999999999
ll mult(ll a, ll b, ll p = mod) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = mod) { return (a % p + b % p) % p; }
ll fpow(ll n, ll k, ll p = mod) {
ll r = 1;
for (; k; k >>= 1) {
if (k & 1)
r = r * n % p;
n = n * n % p;
}
return r;
}
ll inv(ll a, ll p = mod) { return fpow(a, p - 2, p); }
bool sa(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
bool fd(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
bool sd(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second > b.second);
}
int main() {
fio ll n, ww;
cin >> n >> ww;
ll w[n + 5], val[n + 5];
fr(i, 1, n + 1) { cin >> w[i] >> val[i]; }
ll k[n + 5][ww + 5];
fr(i, 0, n + 1) {
fr(j, 0, ww + 1) {
if (i == 0 || j == 0) {
k[i][j] = 0;
} else if (w[i] <= j) {
k[i][j] = max((val[i] + k[i - 1][ww - w[i]]), k[i - 1][j]);
} else {
k[i][j] = k[i - 1][j];
}
}
}
cout << k[n][ww];
rr;
} | /* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of
* doing nothing :/
*/
// Author:: Subash Singha Roy
// Institution:: Jalpaiguri Government Engineering College
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod (int)(1e9 + 7)
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define frr(i, a, b) for (ll i = a - 1; i >= b; i--)
#define tc(t) \
int t; \
cin >> t; \
while (t--)
#define pb(i) push_back(i)
#define rr return 0
#define mp make_pair
#define pr pair<ll, ll>
#define ff first
#define ss second
#define inf 999999999999999999
ll mult(ll a, ll b, ll p = mod) { return ((a % p) * (b % p)) % p; }
ll add(ll a, ll b, ll p = mod) { return (a % p + b % p) % p; }
ll fpow(ll n, ll k, ll p = mod) {
ll r = 1;
for (; k; k >>= 1) {
if (k & 1)
r = r * n % p;
n = n * n % p;
}
return r;
}
ll inv(ll a, ll p = mod) { return fpow(a, p - 2, p); }
bool sa(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
bool fd(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
bool sd(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second > b.second);
}
int main() {
fio ll n, ww;
cin >> n >> ww;
ll w[n + 5], val[n + 5];
fr(i, 1, n + 1) { cin >> w[i] >> val[i]; }
ll k[n + 2][ww + 2];
fr(i, 0, n + 1) {
fr(j, 0, ww + 1) {
if (i == 0 || j == 0) {
k[i][j] = 0;
} else if (w[i] <= j) {
k[i][j] = max((val[i] + k[i - 1][j - w[i]]), k[i - 1][j]);
} else {
k[i][j] = k[i - 1][j];
}
}
}
cout << k[n][ww];
rr;
} | [
"literal.number.change",
"expression.operation.binary.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change"
] | 968,921 | 968,922 | u569396461 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
int d[101][100001];
int main() {
memset(d, 0, sizeof(d));
int n, wt;
cin >> n >> wt;
for (int i = 1; i <= n; i++) {
int w, v;
cin >> w >> v;
for (int j = 1; j < w; j++)
d[i][j] = d[i - 1][j];
for (int j = w; j <= wt; j++)
d[i][j] = max(d[i - 1][j], d[i - 1][j - w] + v);
}
cout << d[n][wt] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string.h>
using namespace std;
long long d[101][100001];
int main() {
memset(d, 0, sizeof(d));
int n, wt;
cin >> n >> wt;
for (int i = 1; i <= n; i++) {
int w, v;
cin >> w >> v;
for (int j = 1; j < w; j++)
d[i][j] = d[i - 1][j];
for (int j = w; j <= wt; j++)
d[i][j] = max(d[i - 1][j], d[i - 1][j - w] + v);
}
cout << d[n][wt] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,923 | 968,924 | u597243424 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
//#define int ll
int N, W, w[101], v[101], dp[101][100001];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> W;
memset(dp, 0, sizeof dp);
for (int i = 1; i <= N; i++) {
cin >> w[i] >> v[i];
}
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 >= w[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W];
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int ll
int N, W, w[101], v[101], dp[101][100001];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> W;
memset(dp, 0, sizeof dp);
for (int i = 1; i <= N; i++) {
cin >> w[i] >> v[i];
}
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 >= w[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W];
} | [] | 968,925 | 968,926 | u192208612 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<long long> f(m + 1, 0);
while (n--) {
int cw, cv;
cin >> cw >> cv;
for (int j = cw; j >= cw; j--)
f[j] = max(f[j], f[j - cw] + cv);
}
cout << *max_element(f.begin(), f.end());
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<long long> f(m + 1, 0);
while (n--) {
int cw, cv;
cin >> cw >> cv;
for (int j = m; j >= cw; j--)
f[j] = max(f[j], f[j - cw] + cv);
}
cout << *max_element(f.begin(), f.end());
}
| [
"variable_declaration.value.change",
"identifier.change",
"control_flow.loop.for.initializer.change"
] | 968,929 | 968,930 | u596976719 | cpp |
p03163 | #include <bits/stdc++.h>
#define fi first
#define se second
const int N = 100100;
const long long mod = 1e9 + 9;
using namespace std;
int n;
int k;
int d[N];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
for (int j = k; j >= x; j--) {
d[j] = max(d[j], d[j - x] + y);
}
}
cout << d[k] << "\n";
}
| #include <bits/stdc++.h>
#define fi first
#define se second
const int N = 100100;
const long long mod = 1e9 + 9;
using namespace std;
int n;
int k;
long long d[N];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
for (int j = k; j >= x; j--) {
d[j] = max(d[j], d[j - x] + y);
}
}
cout << d[k] << "\n";
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,950 | 968,951 | u941977569 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sp ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr << x << "\n"
#define debug2(x, y) cerr << x << " " << y << "\n"
#define debug3(x, y, z) cerr << x << " " << y << " " << z << "\n"
#define nl cerr << "\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr << "abcd\n";
#define pi pair<int, int>
#define pii pair<int, pi>
#define pb push_back
#define mxn 200005
int main() {
sp;
int limit, n;
cin >> n >> limit;
int w[n + 1], a[n + 1];
for (int i = 1; i <= n; ++i)
cin >> w[i] >> a[i];
int dp[n + 1][limit + 1];
memset(dp, 0, sizeof dp);
for (int i = 1; i < n + 1; ++i) {
for (int j = 1; j < limit + 1; ++j) {
if (w[i] <= j)
dp[i][j] = max(a[i] + dp[i - 1][j - w[i]], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][limit];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sp ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr << x << "\n"
#define debug2(x, y) cerr << x << " " << y << "\n"
#define debug3(x, y, z) cerr << x << " " << y << " " << z << "\n"
#define nl cerr << "\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr << "abcd\n";
#define pi pair<int, int>
#define pii pair<int, pi>
#define pb push_back
#define mxn 200005
int main() {
sp;
int limit, n;
cin >> n >> limit;
ll w[n + 1], a[n + 1];
for (int i = 1; i <= n; ++i)
cin >> w[i] >> a[i];
ll dp[n + 1][limit + 1];
memset(dp, 0, sizeof dp);
for (int i = 1; i < n + 1; ++i) {
for (int j = 1; j < limit + 1; ++j) {
if (w[i] <= j)
dp[i][j] = max(a[i] + dp[i - 1][j - w[i]], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][limit];
return 0;
}
| [
"variable_declaration.type.change"
] | 968,965 | 968,966 | u450036612 | cpp |
p03163 | #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <queue>
#define qmin(x, y) (x = min(x, y))
#define qmax(x, y) (x = max(x, y))
using namespace std;
inline char gc() {
// static char buf[100000],*p1,*p2;
// return
//(p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
return getchar();
}
template <class T> int read(T &ans) {
ans = 0;
char ch = gc();
T f = 1;
while (!isdigit(ch)) {
if (ch == EOF)
return -1;
if (ch == '-')
f = -1;
ch = gc();
}
while (isdigit(ch))
ans = ans * 10 + ch - '0', ch = gc();
ans *= f;
return 1;
}
template <class T1, class T2> int read(T1 &a, T2 &b) {
return read(a) != EOF && read(b) != EOF ? 2 : EOF;
}
template <class T1, class T2, class T3> int read(T1 &a, T2 &b, T3 &c) {
return read(a, b) != EOF && read(c) != EOF ? 3 : EOF;
}
typedef long long ll;
const int Maxn = 210000;
const int inf = 0x3f3f3f3f;
int n, w, tot;
ll f[Maxn], v;
signed main() {
// freopen("test.in","r",stdin);
read(n, tot);
for (int i = 1; i <= n; i++) {
read(w, v);
for (int j = tot; j >= w; j--)
f[j] = max(f[j], f[j - w] + v);
}
printf("%d\n", f[tot]);
return 0;
}
| #include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <queue>
#define qmin(x, y) (x = min(x, y))
#define qmax(x, y) (x = max(x, y))
using namespace std;
inline char gc() {
// static char buf[100000],*p1,*p2;
// return
//(p1==p2)&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
return getchar();
}
template <class T> int read(T &ans) {
ans = 0;
char ch = gc();
T f = 1;
while (!isdigit(ch)) {
if (ch == EOF)
return -1;
if (ch == '-')
f = -1;
ch = gc();
}
while (isdigit(ch))
ans = ans * 10 + ch - '0', ch = gc();
ans *= f;
return 1;
}
template <class T1, class T2> int read(T1 &a, T2 &b) {
return read(a) != EOF && read(b) != EOF ? 2 : EOF;
}
template <class T1, class T2, class T3> int read(T1 &a, T2 &b, T3 &c) {
return read(a, b) != EOF && read(c) != EOF ? 3 : EOF;
}
typedef long long ll;
const int Maxn = 210000;
const int inf = 0x3f3f3f3f;
int n, w, tot;
ll f[Maxn], v;
signed main() {
// freopen("test.in","r",stdin);
read(n, tot);
for (int i = 1; i <= n; i++) {
read(w, v);
for (int j = tot; j >= w; j--)
f[j] = max(f[j], f[j - w] + v);
}
printf("%lld\n", f[tot]);
return 0;
}
| [
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 968,970 | 968,971 | u360800499 | cpp |
p03163 | #include <algorithm>
#include <stdio.h>
using namespace std;
const int MAX_N = 105;
struct item {
int v, m;
};
int F[MAX_N][100005];
int n, M;
item save[MAX_N];
int main() {
scanf("%d %d", &n, &M);
for (int i = 1; i <= n; i++)
scanf("%d %d", &save[i].m, &save[i].v);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= M; j++)
if (save[i].m > j)
F[i][j] = F[i - 1][j];
else
F[i][j] = max(F[i - 1][j], F[i - 1][j - save[i].m] + save[i].v);
printf("%d", F[n][M]);
return 0;
}
| #include <algorithm>
#include <stdio.h>
using namespace std;
const int MAX_N = 105;
struct item {
int v, m;
};
long long F[MAX_N][100005];
int n, M;
item save[MAX_N];
int main() {
scanf("%d %d", &n, &M);
for (int i = 1; i <= n; i++)
scanf("%d %d", &save[i].m, &save[i].v);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= M; j++)
if (save[i].m > j)
F[i][j] = F[i - 1][j];
else
F[i][j] = max(F[i - 1][j], F[i - 1][j - save[i].m] + save[i].v);
printf("%lld", F[n][M]);
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 968,972 | 968,973 | u799820634 | cpp |
p03163 | #include <algorithm>
#include <assert.h>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define vi vector<int>
#define pii pair<int, int>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define pi acos(-1)
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define N 100010
#define _DEBUG
template <class U, class T> void Max(U &x, T y) {
if (x < y)
x = y;
}
template <class U, class T> void Min(U &x, T y) {
if (x > y)
x = y;
}
template <class T> void add(int &a, T b) { a = (a + b) % mod; }
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int pow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = 1LL * ans * a % mod;
a = 1LL * a * a % mod;
b >>= 1;
}
return ans;
}
int pow(int a, int b, int c) {
int ans = 1;
while (b) {
if (b & 1)
ans = 1LL * ans * a % c;
a = 1LL * a * a % c;
b >>= 1;
}
return ans;
}
int dp[N], a[101], b[101];
int main() {
// srand(time(NULL)+clock());
int ca = 0, T, k, i, j, m = 0, K, n;
double start = clock();
scanf("%d%d", &n, &m);
rep(i, 0, n) scanf("%d%d", &a[i], &b[i]);
int s = 0;
rep(i, 0, n) {
per(j, 0, min(s, m) + 1) {
if (a[i] + j <= m)
Max(dp[a[i] + j], dp[j] + b[i]);
}
s += a[i];
}
int ans = 0;
rep(i, 0, m + 1) Max(ans, dp[i]);
printf("%d\n", ans);
cerr << (1. * clock() - start) / CLOCKS_PER_SEC << "\n";
}
| #include <algorithm>
#include <assert.h>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define vi vector<int>
#define pii pair<int, int>
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define pi acos(-1)
#define mod 1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr << (#x) << "=" << x << "\n";
#define N 100010
#define _DEBUG
template <class U, class T> void Max(U &x, T y) {
if (x < y)
x = y;
}
template <class U, class T> void Min(U &x, T y) {
if (x > y)
x = y;
}
template <class T> void add(int &a, T b) { a = (a + b) % mod; }
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int pow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1)
ans = 1LL * ans * a % mod;
a = 1LL * a * a % mod;
b >>= 1;
}
return ans;
}
int pow(int a, int b, int c) {
int ans = 1;
while (b) {
if (b & 1)
ans = 1LL * ans * a % c;
a = 1LL * a * a % c;
b >>= 1;
}
return ans;
}
ll dp[N];
int a[101], b[101];
int main() {
// srand(time(NULL)+clock());
int ca = 0, T, k, i, j, m = 0, K, n;
double start = clock();
scanf("%d%d", &n, &m);
rep(i, 0, n) scanf("%d%d", &a[i], &b[i]);
int s = 0;
rep(i, 0, n) {
per(j, 0, min(s, m) + 1) {
if (a[i] + j <= m)
Max(dp[a[i] + j], dp[j] + b[i]);
}
s += a[i];
}
ll ans = 0;
rep(i, 0, m + 1) Max(ans, dp[i]);
printf("%lld\n", ans);
cerr << (1. * clock() - start) / CLOCKS_PER_SEC << "\n";
}
| [
"variable_declaration.type.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 968,983 | 968,984 | u298360432 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
// using lint = long long;
struct P {
int x, y;
bool operator<(const P &a) const {
if (x != a.x)
return x > a.x;
return y > a.y;
}
};
vector<int> v[111111], v1;
// bitset<4001000> b;
int i, n, d, m, k, a, b, c, h;
int o[111];
long long l[111][111115];
int j[111];
int e[111111];
// int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};
int dx[10] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[10] = {1, 0, -1, 0, 1, -1, 1, -1},
dz[10] = {0, 0, 0, 0, 1, -1};
long long mod = 1000000007, mod2 = 1000000009, mod3 = 2017;
long long x, z, y;
double pi = 3.14159265;
P u[311111];
stack<int> s;
// set<int> s[222][22];
// priority_queue<P> q;
queue<int> q;
// 2147483647
//'1'==49;
//'A'==65;
//'a'==97;
// unordered_
// map<int,int> p;
/*
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x +
FIXED_RANDOM);
}
};
unordered_map<long long, int, custom_hash> safe_map;
*/
// list<int> l;
string r;
// char r[2];
// deque<int> de;
// srand((int)time(NULL));
/*bool as(P a,P b)
{
if(a.x!=b.x)
return a.x<b.x;
return a.y<b.y;
}*/
bool as(P a, P b) {
if (a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
int f(int n, int m) {
if (m > b)
return -987654321;
if (n > a)
return 0;
if (l[n][m] >= 0)
return l[n][m];
return l[n][m] = max(f(n + 1, m), f(n + 1, m + o[n]) + j[n]);
}
int main() {
memset(l, -1, sizeof(l));
scanf("%d %d", &a, &b);
for (int t = 1; t <= a; t++)
scanf("%d %d", &o[t], &j[t]);
printf("%d", f(1, 0));
}
| #include <bits/stdc++.h>
using namespace std;
// using lint = long long;
struct P {
int x, y;
bool operator<(const P &a) const {
if (x != a.x)
return x > a.x;
return y > a.y;
}
};
vector<int> v[111111], v1;
// bitset<4001000> b;
int i, n, d, m, k, a, b, c, h;
int o[111];
long long l[111][111115];
int j[111];
int e[111111];
// int dx[10]={2,2,-2,-2,1,1,-1,-1},dy[10]={1,-1,1,-1,2,-2,2,-2};
int dx[10] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[10] = {1, 0, -1, 0, 1, -1, 1, -1},
dz[10] = {0, 0, 0, 0, 1, -1};
long long mod = 1000000007, mod2 = 1000000009, mod3 = 2017;
long long x, z, y;
double pi = 3.14159265;
P u[311111];
stack<int> s;
// set<int> s[222][22];
// priority_queue<P> q;
queue<int> q;
// 2147483647
//'1'==49;
//'A'==65;
//'a'==97;
// unordered_
// map<int,int> p;
/*
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x +
FIXED_RANDOM);
}
};
unordered_map<long long, int, custom_hash> safe_map;
*/
// list<int> l;
string r;
// char r[2];
// deque<int> de;
// srand((int)time(NULL));
/*bool as(P a,P b)
{
if(a.x!=b.x)
return a.x<b.x;
return a.y<b.y;
}*/
bool as(P a, P b) {
if (a.x != b.x)
return a.x < b.x;
return a.y < b.y;
}
long long f(int n, int m) {
if (m > b)
return -987654321987654321;
if (n > a)
return 0;
if (l[n][m] >= 0)
return l[n][m];
return l[n][m] = max(f(n + 1, m), f(n + 1, m + o[n]) + j[n]);
}
int main() {
memset(l, -1, sizeof(l));
scanf("%d %d", &a, &b);
for (int t = 1; t <= a; t++)
scanf("%d %d", &o[t], &j[t]);
printf("%lld", f(1, 0));
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"function.return_value.change",
"literal.string.change",
"call.arguments.change",
"io.output.change"
] | 968,991 | 968,992 | u428070871 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int n, W;
int w[155], v[155];
int dp[100055];
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
scanf("%d %d", &w[i], &v[i]);
}
for (int i = 0; i < n; i++) {
for (int j = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W];
}
| #include <bits/stdc++.h>
using namespace std;
int n, W;
int w[155], v[155];
long long dp[100055];
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
scanf("%d %d", &w[i], &v[i]);
}
for (int i = 0; i < n; i++) {
for (int j = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W];
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 968,997 | 968,998 | u542172770 | cpp |
p03163 | #include <iostream>
#define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
// const int MOD = 10e9+7;
const int INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int dp[110][100100];
signed main() {
int N, W;
cin >> N >> W;
int v[N], w[N];
REP(i, N) cin >> w[i] >> v[i];
REP(i, N) REP(j, W) dp[i][j] = 0;
REP(i, N) REP(m, W) {
if (m >= w[i])
dp[i + 1][m] = max(dp[i][m - w[i]] + v[i], dp[i][m]);
else
dp[i + 1][m] = dp[i][m];
}
int ans{0};
REP(j, W) chmax(ans, dp[N][j]);
cout << ans << endl;
}
| #include <iostream>
#define int long long
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
// const int MOD = 10e9+7;
const int INF = 1LL << 60;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int dp[110][100100];
signed main() {
int N, W;
cin >> N >> W;
int v[N], w[N];
REP(i, N) cin >> w[i] >> v[i];
REP(i, N) REP(j, W) dp[i][j] = 0;
REP(i, N) REP(m, W + 1) {
if (m >= w[i])
dp[i + 1][m] = max(dp[i][m - w[i]] + v[i], dp[i][m]);
else
dp[i + 1][m] = dp[i][m];
}
int ans{0};
REP(j, W + 1) chmax(ans, dp[N][j]);
cout << ans << endl;
} | [
"expression.operation.binary.add"
] | 968,999 | 969,000 | u904833081 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<vector<int>> dp(N, vector<int>(W + 1, 0));
vector<pair<int, int>> a(N);
for (auto &x : a)
cin >> x.first >> x.second;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (i == 0)
dp[i][j] = j - a[i].first >= 0 ? a[i].second : 0;
else
dp[i][j] =
j - a[i].first < 0
? dp[i - 1][j]
: max(dp[i - 1][j], a[i].second + dp[i - 1][j - a[i].first]);
}
}
cout << dp[N - 1][W] << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<vector<long>> dp(N, vector<long>(W + 1, 0));
vector<pair<int, int>> a(N);
for (auto &x : a)
cin >> x.first >> x.second;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (i == 0)
dp[i][j] = j - a[i].first >= 0 ? a[i].second : 0;
else
dp[i][j] =
j - a[i].first < 0
? dp[i - 1][j]
: max(dp[i - 1][j], a[i].second + dp[i - 1][j - a[i].first]);
}
}
cout << dp[N - 1][W] << endl;
return 0;
}
| [
"variable_declaration.type.primitive.change"
] | 969,005 | 969,006 | u598869726 | cpp |
p03163 | #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define LL long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
int dp[102][100005];
int main() {
int n, w;
cin >> n >> w;
int e[n + 1], v[n + 1];
memset(dp, 0, sizeof dp);
for (int i = 1; i <= n; i++) {
cin >> e[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int k = 1; k <= w; k++) {
if (k >= e[i])
dp[i][k] = max(dp[i][k], dp[i - 1][k - e[i]] + v[i]);
dp[i][k] = max(dp[i][k], dp[i - 1][k]);
}
}
cout << dp[n][w];
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>
#define LL long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
LL dp[102][100005];
int main() {
int n, w;
cin >> n >> w;
int e[n + 1], v[n + 1];
memset(dp, 0, sizeof dp);
for (int i = 1; i <= n; i++) {
cin >> e[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int k = 1; k <= w; k++) {
if (k >= e[i])
dp[i][k] = max(dp[i][k], dp[i - 1][k - e[i]] + v[i]);
dp[i][k] = max(dp[i][k], dp[i - 1][k]);
}
}
cout << dp[n][w];
return 0;
}
| [
"variable_declaration.type.change"
] | 969,013 | 969,014 | u170464980 | cpp |
p03163 | #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
const int MX = 200005;
// 整数スキャン(複数)
/*
int x;
scanf("%d",&x);
int y;
scanf("%d",&y);
int z;
scanf("%d",&z);
// n個の整数のスキャン
/*
ll a[n] = {};
rep(i,n){
scanf("%lld",&a[i]);
}
*/
// 文字列スキャン
/*
string s;
cin >> s;
*/
// n個の文字列スキャン
/*
vector<string> slist;
rep(i,n){
string s;
cin >> s;
slist.push_back(s);
}
*/
int main() {
int n;
scanf("%d", &n);
int w;
scanf("%d", &w);
ll a[n + 1] = {};
ll b[n + 1] = {};
srep(i, 1, n + 1) {
scanf("%lld", &a[i]);
scanf("%lld", &b[i]);
}
ll dp[n + 1][w + 1];
rep(i, n + 1) {
rep(j, w + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else {
if (a[i] > j) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
} else {
dp[i][j] =
max(dp[i - 1][j - a[i]] + b[i], max(dp[i - 1][j], dp[i][j - 1]));
}
}
}
}
int ans = 0;
ans = dp[n][w];
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, sz(v)) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (sz(v))
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
template <typename T> inline ll suma(const v(T) & a) {
ll res(0);
for (auto &&x : a)
res += x;
return res;
}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("Yes"); } \
else { \
puts("No"); \
}
const int MX = 200005;
// 整数スキャン(複数)
/*
int x;
scanf("%d",&x);
int y;
scanf("%d",&y);
int z;
scanf("%d",&z);
// n個の整数のスキャン
/*
ll a[n] = {};
rep(i,n){
scanf("%lld",&a[i]);
}
*/
// 文字列スキャン
/*
string s;
cin >> s;
*/
// n個の文字列スキャン
/*
vector<string> slist;
rep(i,n){
string s;
cin >> s;
slist.push_back(s);
}
*/
int main() {
int n;
scanf("%d", &n);
int w;
scanf("%d", &w);
ll a[n + 1] = {};
ll b[n + 1] = {};
srep(i, 1, n + 1) {
scanf("%lld", &a[i]);
scanf("%lld", &b[i]);
}
ll dp[n + 1][w + 1];
rep(i, n + 1) {
rep(j, w + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else {
if (a[i] > j) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
} else {
dp[i][j] =
max(dp[i - 1][j - a[i]] + b[i], max(dp[i - 1][j], dp[i][j - 1]));
}
}
}
}
ll ans = 0;
ans = dp[n][w];
cout << ans << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 969,023 | 969,024 | u791593901 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll, ll> LLP;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
#define INF 1000000007
#define MOD 1000000007
#define MAX_N 105
#define MAX_W 100005
ll dp[MAX_N][MAX_W]; // 0:海,1:山,2:宿題,dp[i][j] = iをj日目に行う時の幸福度
ll weight[MAX_N];
ll value[MAX_N];
int main() {
ll n, weight_maxi;
cin >> n >> weight_maxi;
REP(i, n) { cin >> weight[i] >> value[i]; }
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= weight_maxi; j++) {
if (j < weight[i]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
}
}
}
cout << dp[n][weight_maxi] << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll, ll> LLP;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
#define INF 1000000007
#define MOD 1000000007
#define MAX_N 105
#define MAX_W 100005
ll dp[MAX_N][MAX_W]; // 0:海,1:山,2:宿題,dp[i][j] = iをj日目に行う時の幸福度
ll weight[MAX_N];
ll value[MAX_N];
int main() {
ll n, weight_maxi;
cin >> n >> weight_maxi;
REP(i, n) { cin >> weight[i] >> value[i]; }
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= weight_maxi; j++) {
if (j < weight[i - 1]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
}
}
}
cout << dp[n][weight_maxi] << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 969,027 | 969,028 | u504142483 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll, ll> LLP;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
#define INF 1000000007
#define MOD 1000000007
#define MAX_N 105
#define MAX_W 100005
ll dp[MAX_N][MAX_W]; // 0:海,1:山,2:宿題,dp[i][j] = iをj日目に行う時の幸福度
ll weight[MAX_N];
ll value[MAX_N];
int main() {
ll n, weight_maxi;
cin >> n >> weight_maxi;
REP(i, n) { cin >> weight[i] >> value[i]; }
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= weight_maxi; j++) {
if (j < weight[i]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
}
}
}
cout << dp[n][weight_maxi] << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll, ll> LLP;
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};
#define INF 1000000007
#define MOD 1000000007
#define MAX_N 105
#define MAX_W 100005
ll dp[MAX_N][MAX_W]; // 0:海,1:山,2:宿題,dp[i][j] = iをj日目に行う時の幸福度
ll weight[MAX_N];
ll value[MAX_N];
int main() {
ll n, weight_maxi;
cin >> n >> weight_maxi;
REP(i, n) { cin >> weight[i] >> value[i]; }
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= weight_maxi; j++) {
if (j < weight[i - 1]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]);
}
}
}
cout << dp[n][weight_maxi] << endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 969,027 | 969,029 | u504142483 | cpp |
p03163 | #include <bits/stdc++.h>
#define int long long int
#define vi vector<int>
#define pii pair<long long, long long>
#define pll pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb push_back
#define ff first
#define ss second
#define rep(n) for (int i = 0; i < n; i++)
#define lb lower_bound
#define up upper_bound
using namespace std;
int dp[100005][105];
int v[100005];
int a[100005];
void solve() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i] >> v[i];
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= n; j++) {
if (i - a[j] >= 0)
dp[i][j] = max(dp[i][j], dp[i - a[j]][j - 1] + v[j]);
else
dp[i][j] = dp[i][j - 1];
}
}
cout << dp[w][n];
}
signed main() {
/* #ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
T = 1;
while (T--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define int long long int
#define vi vector<int>
#define pii pair<long long, long long>
#define pll pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb push_back
#define ff first
#define ss second
#define rep(n) for (int i = 0; i < n; i++)
#define lb lower_bound
#define up upper_bound
using namespace std;
int dp[100005][105];
int v[100005];
int a[100005];
void solve() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i] >> v[i];
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= n; j++) {
if (i - a[j] >= 0)
dp[i][j] = max(dp[i][j - 1], dp[i - a[j]][j - 1] + v[j]);
else
dp[i][j] = dp[i][j - 1];
}
}
cout << dp[w][n];
}
signed main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
T = 1;
while (T--) {
solve();
}
return 0;
}
| [
"assignment.change"
] | 969,030 | 969,031 | u959659903 | cpp |
p03163 | #include <bits/stdc++.h>
#define int long long int
#define vi vector<int>
#define pii pair<long long, long long>
#define pll pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb push_back
#define ff first
#define ss second
#define rep(n) for (int i = 0; i < n; i++)
#define lb lower_bound
#define up upper_bound
using namespace std;
int dp[105][100005];
int v[100005];
int a[100005];
void solve() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i] >> v[i];
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= n; j++) {
if (i - a[j] >= 0)
dp[i][j] = max(dp[i][j], dp[i - a[j]][j - 1] + v[j]);
else
dp[i][j] = dp[i][j - 1];
}
}
cout << dp[w][n];
}
signed main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
T = 1;
while (T--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#define int long long int
#define vi vector<int>
#define pii pair<long long, long long>
#define pll pair<int, int>
#define mod 1000000007
#define all(x) x.begin(), x.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb push_back
#define ff first
#define ss second
#define rep(n) for (int i = 0; i < n; i++)
#define lb lower_bound
#define up upper_bound
using namespace std;
int dp[100005][105];
int v[100005];
int a[100005];
void solve() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i] >> v[i];
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= n; j++) {
if (i - a[j] >= 0)
dp[i][j] = max(dp[i][j - 1], dp[i - a[j]][j - 1] + v[j]);
else
dp[i][j] = dp[i][j - 1];
}
}
cout << dp[w][n];
}
signed main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int T;
T = 1;
while (T--) {
solve();
}
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"assignment.change"
] | 969,032 | 969,031 | u959659903 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
ll dp[101][100001];
int n, w;
ll s[101][3];
int go(int idx, int rem) {
if (idx == n)
return 0;
ll &ret = dp[idx][rem];
if (ret != -1)
return ret;
ret = 0;
if (rem - s[idx][0] >= 0) {
ret = max(ret, s[idx][1] + go(idx + 1, rem - s[idx][0]));
}
ret = max(ret, 0LL + go(idx + 1, rem));
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n >> w;
for (int i = 0; i < n; i++)
scanf("%lld%lld", &s[i][0], &s[i][1]);
go(0, w);
cout << dp[0][w];
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
ll dp[101][100001];
ll n, w;
ll s[101][3];
ll go(int idx, int rem) {
if (idx >= n)
return 0;
ll &ret = dp[idx][rem];
if (ret != -1) {
return ret;
}
ret = 0;
if (rem - s[idx][0] >= 0) {
ret = max(ret, s[idx][1] + go(idx + 1, rem - s[idx][0]));
// cout<<idx<<' '<<rem<<' '<<go(idx+1,rem-s[idx][0])<<endl;
}
ret = max(ret, 0LL + go(idx + 1, rem));
// cout<<idx<<' '<<rem<<' '<<ret<<endl;
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n >> w;
for (int i = 0; i < n; i++)
scanf("%lld%lld", &s[i][0], &s[i][1]);
go(0, w);
cout << dp[0][w];
}
| [
"variable_declaration.type.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 969,033 | 969,034 | u188000196 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
ll dp[101][100001];
int n, w;
ll s[101][3];
int go(int idx, int rem) {
if (idx == n)
return 0;
ll &ret = dp[idx][rem];
if (ret != -1)
return ret;
ret = 0;
if (rem - s[idx][0] >= 0) {
ret = max(ret, s[idx][1] + go(idx + 1, rem - s[idx][0]));
}
ret = max(ret, 0LL + go(idx + 1, rem));
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n >> w;
for (int i = 0; i < n; i++)
scanf("%lld%lldv", &s[i][0], &s[i][1]);
go(0, w);
cout << dp[0][w];
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
ll dp[101][100001];
ll n, w;
ll s[101][3];
ll go(int idx, int rem) {
if (idx >= n)
return 0;
ll &ret = dp[idx][rem];
if (ret != -1) {
return ret;
}
ret = 0;
if (rem - s[idx][0] >= 0) {
ret = max(ret, s[idx][1] + go(idx + 1, rem - s[idx][0]));
// cout<<idx<<' '<<rem<<' '<<go(idx+1,rem-s[idx][0])<<endl;
}
ret = max(ret, 0LL + go(idx + 1, rem));
// cout<<idx<<' '<<rem<<' '<<ret<<endl;
return ret;
}
int main() {
memset(dp, -1, sizeof dp);
cin >> n >> w;
for (int i = 0; i < n; i++)
scanf("%lld%lld", &s[i][0], &s[i][1]);
go(0, w);
cout << dp[0][w];
}
| [
"variable_declaration.type.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"call.arguments.change"
] | 969,035 | 969,034 | u188000196 | cpp |
p03163 | //#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case (t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) \
for (int i = 0; i < (n); i++) \
ni(a[i])
#define nal(a, n) \
for (int i = 0; i < (n); i++) \
nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int, int, hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
ll dp[MAXN];
int main() {
fill(dp, dp + MAXN, 0);
int n, w;
scanf("%d %d", &n, &w);
for (int i = 0; i < n; i++) {
int wi, vi;
scanf("%d %d", &wi, &vi);
for (int j = w - wi; j >= 0; j--)
if (dp[j] != 0 || j == 0)
dp[j + wi] = max(dp[j + wi], dp[j] + vi);
}
prl(*max_element(dp, dp + w + 1));
return 0;
}
| //#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case (t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) \
for (int i = 0; i < (n); i++) \
ni(a[i])
#define nal(a, n) \
for (int i = 0; i < (n); i++) \
nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int, int, hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
ll dp[MAXN];
int main() {
fill(dp, dp + MAXN, 0);
int n, w;
scanf("%d %d", &n, &w);
for (int i = 0; i < n; i++) {
int wi, vi;
scanf("%d %d", &wi, &vi);
for (int j = w - wi; j >= 0; j--)
if (dp[j] != 0 || j == 0)
dp[j + wi] = max(dp[j + wi], dp[j] + vi);
}
prl(*max_element(dp, dp + w + 1));
return 0;
}
| [
"preprocessor.define.value.change"
] | 969,038 | 969,039 | u270920804 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int dp[101][100001];
int n, k;
int we[101], val[101];
long long go(int i, int k) {
if (i >= n || k < 0)
return 0;
else {
if (dp[i][k] == -1) {
if (we[i] > k)
dp[i][k] = go(i + 1, k);
else
dp[i][k] = max(val[i] + go(i + 1, k - we[i]), go(i + 1, k));
}
return dp[i][k];
}
}
int main() {
cin >> n >> k;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> we[i] >> val[i];
}
cout << go(0, k);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long dp[101][100001];
int n, k;
int we[101], val[101];
long long go(int i, int k) {
if (i >= n || k < 0)
return 0;
else {
if (dp[i][k] == -1) {
if (we[i] > k)
dp[i][k] = go(i + 1, k);
else
dp[i][k] = max(val[i] + go(i + 1, k - we[i]), go(i + 1, k));
}
return dp[i][k];
}
}
int main() {
cin >> n >> k;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> we[i] >> val[i];
}
cout << go(0, k);
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 969,053 | 969,054 | u221519228 | cpp |
p03163 | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
// basic knap question
vector<int> lw(N);
vector<int> lv(N);
for (int i = 0; i < N; i++)
cin >> lw[i] >> lv[i];
vector<vector<long long>> f(W + 1, vector<long long>(N + 1));
for (int i = 1; i <= W; i++) {
for (int j = 1; j <= N; j++) {
// f[i][j]=max(f[i][j-1],f[i-wj][j-1]+v[j])
int temp;
if (i - lw[j - 1] < 0)
temp = 0;
else
temp = f[i - lw[j - 1]][j - 1] + lv[j - 1];
f[i][j] = f[i][j - 1] > temp ? f[i][j - 1] : temp;
// cout<<f[i][j]<<" ";
}
// cout<<endl;
}
cout << f[W][N] << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
// basic knap question
vector<int> lw(N);
vector<int> lv(N);
for (int i = 0; i < N; i++)
cin >> lw[i] >> lv[i];
vector<vector<long long>> f(W + 1, vector<long long>(N + 1));
for (int i = 1; i <= W; i++) {
for (int j = 1; j <= N; j++) {
// f[i][j]=max(f[i][j-1],f[i-wj][j-1]+v[j])
long long temp;
if (i - lw[j - 1] < 0)
temp = 0;
else
temp = f[i - lw[j - 1]][j - 1] + lv[j - 1];
f[i][j] = f[i][j - 1] > temp ? f[i][j - 1] : temp;
// cout<<f[i][j]<<" ";
}
// cout<<endl;
}
cout << f[W][N] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 969,067 | 969,068 | u905802918 | cpp |
p03163 | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
// basic knap question
vector<int> lw(N);
vector<int> lv(N);
for (int i = 0; i < N; i++)
cin >> lw[i] >> lv[i];
vector<vector<int>> f(W + 1, vector<int>(N + 1));
for (int i = 1; i <= W; i++) {
for (int j = 1; j <= N; j++) {
// f[i][j]=max(f[i][j-1],f[i-wj][j-1]+v[j])
int temp;
if (i - lw[j - 1] < 0)
temp = 0;
else
temp = f[i - lw[j - 1]][j - 1] + lv[j - 1];
f[i][j] = f[i][j - 1] > temp ? f[i][j - 1] : temp;
// cout<<f[i][j]<<" ";
}
// cout<<endl;
}
cout << f[W][N] << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
// basic knap question
vector<int> lw(N);
vector<int> lv(N);
for (int i = 0; i < N; i++)
cin >> lw[i] >> lv[i];
vector<vector<long long>> f(W + 1, vector<long long>(N + 1));
for (int i = 1; i <= W; i++) {
for (int j = 1; j <= N; j++) {
// f[i][j]=max(f[i][j-1],f[i-wj][j-1]+v[j])
long long temp;
if (i - lw[j - 1] < 0)
temp = 0;
else
temp = f[i - lw[j - 1]][j - 1] + lv[j - 1];
f[i][j] = f[i][j - 1] > temp ? f[i][j - 1] : temp;
// cout<<f[i][j]<<" ";
}
// cout<<endl;
}
cout << f[W][N] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 969,069 | 969,068 | u905802918 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
long n, W;
cin >> n >> W;
long w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
long dp[n][W];
for (int i = 0; i <= W; i++) {
dp[0][i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (j < w[i]) {
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] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long n, W;
cin >> n >> W;
long w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
long dp[n + 1][W + 1];
for (int i = 0; i <= W; i++) {
dp[0][i] = 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (j < w[i]) {
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] << endl;
} | [
"variable_declaration.array_dimensions.change",
"expression.operation.binary.add"
] | 969,074 | 969,075 | u911147723 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#include <vector>
int max(int a, int b) { return (a > b) ? a : b; };
int main() {
int N, W, a, b;
cin >> N >> W;
vector<int> v;
vector<int> wt;
for (int i = 0; i < N; ++i) {
cin >> a;
wt.push_back(a);
cin >> b;
v.push_back(b);
}
int i, w;
int K[N + 1][W + 1];
for (i = 0; i <= N; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = max(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];
}
| #include <bits/stdc++.h>
using namespace std;
#include <vector>
int max(int a, int b) { return (a > b) ? a : b; };
int main() {
long long int N, W, a, b;
cin >> N >> W;
vector<int> v;
vector<int> wt;
for (int i = 0; i < N; ++i) {
cin >> a;
wt.push_back(a);
cin >> b;
v.push_back(b);
}
long long int i, w;
long long int K[N + 1][W + 1];
for (i = 0; i <= N; i++) {
for (w = 0; w <= W; w++) {
if (i == 0 || w == 0)
K[i][w] = 0;
else if (wt[i - 1] <= w)
K[i][w] = max(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];
} | [
"variable_declaration.type.widen.change"
] | 969,080 | 969,081 | u343520219 | cpp |
p03164 | #include <bits/stdc++.h>
// DEEP
using namespace std;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define fwd(i, a, n) for (int i = a; i < n; i++)
#define bak(i, a, n) for (int i = a; i >= n; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll modl = 998244353;
const double pie = 3.1415926535;
// power
ull power(ull x, ull y) {
if (y == 0)
return 1;
else {
if (y % 2 == 0)
return power(x * x, y / 2);
else
return x * power(x * x, (y - 1) / 2);
}
}
// Modular Exponentiation
ll mod_power(ll x, ll y, ll m) {
ll r = 1; // Initialize result
x = x % m; // Update x if it is more than or equal to m
if (x == 0)
return 0; // In case x is divisible by m;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
r = (r * x) % m;
// y must be even now
y = y / 2;
x = (x * x) % m;
}
return r;
}
// GCD
ll gcd(ll x, ll y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
// EXTENDED_EUCLID
vector<ll> extended_Euclid(ll a, ll b) {
vector<ll> v(3);
if (b == 0) {
v[0] = a;
v[1] = 1;
v[2] = 0;
return v;
} else {
vector<ll> v1 = extended_Euclid(b, a % b); // recursive call
v[0] = v1[0];
v[1] = v1[2];
v[2] = v1[1] - (a / b) * v1[2];
return v;
}
}
// DFS ( number of connected components )
// vector<vector<ll> >adj(200001);
// bool visited[200001];
/*ll dfs(int x,int c){ // x - > node c - > number
of edges in the component if(visited[x])return c; else{ visited[x]=true; int
y=c; for(int i=0;i<adj[x].size();i++){ if(!visited[adj[x][i]]){ c+=1; int
d=dfs(adj[x][i],y); c+=d;
}
}
return c;
}
}
*/
// SIEVE
/*
bool isPrime[100001];
void sieve(int N) {
for(int i = 0; i <= N;++i) {
isPrime[i]=true;
}
isPrime[0]=false;
isPrime[1]=false;
for(int i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) {
for(int j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
}
*/
// Binary Search
/*
ll bin_search(ll y){
while(lo<hi){
x=lo+(hi-lo)/2;
if(condition){
.....
}
else{
// increase lo or decrease hi suitably
}
}
}
*/
void max_self(ll &a, ll b) { a = max(a, b); }
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
boost;
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, w;
cin >> n >> w;
ll weight[n];
ll value[n];
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
ll sum_value = 0;
for (int x : value)
sum_value += x;
vector<ll> dp(sum_value + 1, 1e9 + 5);
dp[0] = 0;
for (int i = 0; i <= n; i++) {
for (int value_already = sum_value - value[i]; value_already >= 0;
--value_already) {
min_self(dp[value_already + value[i]], dp[value_already] + weight[i]);
}
}
ll ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
ans = max(ans, ll(i));
}
}
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
// DEEP
using namespace std;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define fwd(i, a, n) for (int i = a; i < n; i++)
#define bak(i, a, n) for (int i = a; i >= n; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll modl = 998244353;
const double pie = 3.1415926535;
// power
ull power(ull x, ull y) {
if (y == 0)
return 1;
else {
if (y % 2 == 0)
return power(x * x, y / 2);
else
return x * power(x * x, (y - 1) / 2);
}
}
// Modular Exponentiation
ll mod_power(ll x, ll y, ll m) {
ll r = 1; // Initialize result
x = x % m; // Update x if it is more than or equal to m
if (x == 0)
return 0; // In case x is divisible by m;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
r = (r * x) % m;
// y must be even now
y = y / 2;
x = (x * x) % m;
}
return r;
}
// GCD
ll gcd(ll x, ll y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
// EXTENDED_EUCLID
vector<ll> extended_Euclid(ll a, ll b) {
vector<ll> v(3);
if (b == 0) {
v[0] = a;
v[1] = 1;
v[2] = 0;
return v;
} else {
vector<ll> v1 = extended_Euclid(b, a % b); // recursive call
v[0] = v1[0];
v[1] = v1[2];
v[2] = v1[1] - (a / b) * v1[2];
return v;
}
}
// DFS ( number of connected components )
// vector<vector<ll> >adj(200001);
// bool visited[200001];
/*ll dfs(int x,int c){ // x - > node c - > number
of edges in the component if(visited[x])return c; else{ visited[x]=true; int
y=c; for(int i=0;i<adj[x].size();i++){ if(!visited[adj[x][i]]){ c+=1; int
d=dfs(adj[x][i],y); c+=d;
}
}
return c;
}
}
*/
// SIEVE
/*
bool isPrime[100001];
void sieve(int N) {
for(int i = 0; i <= N;++i) {
isPrime[i]=true;
}
isPrime[0]=false;
isPrime[1]=false;
for(int i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) {
for(int j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
}
*/
// Binary Search
/*
ll bin_search(ll y){
while(lo<hi){
x=lo+(hi-lo)/2;
if(condition){
.....
}
else{
// increase lo or decrease hi suitably
}
}
}
*/
void max_self(ll &a, ll b) { a = max(a, b); }
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
boost;
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, w;
cin >> n >> w;
ll weight[n];
ll value[n];
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
ll sum_value = 0;
for (int x : value)
sum_value += x;
vector<ll> dp(sum_value + 1, 1e9 + 5);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int value_already = sum_value - value[i]; value_already >= 0;
--value_already) {
min_self(dp[value_already + value[i]], dp[value_already] + weight[i]);
}
}
ll ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
ans = max(ans, ll(i));
}
}
cout << ans << endl;
}
}
| [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 969,094 | 969,095 | u915716225 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll max_val = 1e5;
int main() {
ll n, w, a, b;
cin >> n >> w;
vector<ll> val, wgt;
for (int i = 0; i < n; i++) {
cin >> a >> b;
wgt.pb(a);
val.pb(b);
}
vector<vector<ll>> dp(n + 1, vector<ll>(max_val + 1));
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 0; i <= max_val; i++) {
dp[0][i] = LONG_MAX;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= max_val; j++) {
if (j >= val[i - 1])
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i - 1]] + wgt[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
ll ans = 0;
for (ll i = max_val; i >= 0; i--) {
if (dp[n][i] <= w) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll max_val = 1e5;
int main() {
ll n, w, a, b;
cin >> n >> w;
vector<ll> val, wgt;
for (int i = 0; i < n; i++) {
cin >> a >> b;
wgt.pb(a);
val.pb(b);
}
vector<vector<ll>> dp(n + 1, vector<ll>(max_val + 1));
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 0; i <= max_val; i++) {
dp[0][i] = 2 * 1e9;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= max_val; j++) {
if (j >= val[i - 1])
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i - 1]] + wgt[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
ll ans = 0;
for (ll i = max_val; i >= 0; i--) {
if (dp[n][i] <= w) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add",
"assignment.change"
] | 969,106 | 969,107 | u010088425 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
ll n, w, tv = 0;
ll weights[101];
ll values[101];
// unordered_map<string,int> dpmap;
// ll dp(int pos, ll weight)
// {
// if(weight<0)
// return INT_MIN;
// if(pos<0||weight==0)
// return 0;
// string key = to_string(pos)+"|"+to_string(weight);
// if(dpmap.find(key)==dpmap.end())
// {
// ll takeit = dp(pos-1, weight-weights[pos]) + values[pos];
// ll thankunext = dp(pos-1, weight);
// dpmap[key] = max(takeit, thankunext);
// //cout<<key<<" "<<dpmap[key]<<endl;
// }
// return dpmap[key];
// }
// ll dp(int pos, int value)
// {
// if(pos==n)
// return 0;
// if(memo[pos][value]!=-1)
// return memo[pos][value];
// ll ans = min(dp(pos+1, value + values[pos])-weights[pos], dp(pos+1,
// value)); return memo[pos][value] = ans;
// }
int main() {
cin >> n >> w;
for (ll i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
tv += values[i];
}
vi memo(tv + 5, 1000000000);
memo[0] = 0;
for (int i = 0; i < n; i++)
for (int j = tv; j >= 0; j--) {
if (j >= values[i])
memo[j] = min(memo[j - values[i]] + weights[i], memo[j]);
}
ll ans = 0;
for (ll i = 0; i < tv; i++)
if (memo[i] <= w)
ans = max(ans, i);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
ll n, w, tv = 0;
ll weights[101];
ll values[101];
// unordered_map<string,int> dpmap;
// ll dp(int pos, ll weight)
// {
// if(weight<0)
// return INT_MIN;
// if(pos<0||weight==0)
// return 0;
// string key = to_string(pos)+"|"+to_string(weight);
// if(dpmap.find(key)==dpmap.end())
// {
// ll takeit = dp(pos-1, weight-weights[pos]) + values[pos];
// ll thankunext = dp(pos-1, weight);
// dpmap[key] = max(takeit, thankunext);
// //cout<<key<<" "<<dpmap[key]<<endl;
// }
// return dpmap[key];
// }
// ll dp(int pos, int value)
// {
// if(pos==n)
// return 0;
// if(memo[pos][value]!=-1)
// return memo[pos][value];
// ll ans = min(dp(pos+1, value + values[pos])-weights[pos], dp(pos+1,
// value)); return memo[pos][value] = ans;
// }
int main() {
cin >> n >> w;
for (ll i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
tv += values[i];
}
vi memo(tv + 5, INT_MAX);
memo[0] = 0;
for (int i = 0; i < n; i++)
for (int j = tv; j >= 0; j--) {
if (j >= values[i])
memo[j] = min(memo[j - values[i]] + weights[i], memo[j]);
}
ll ans = 0;
for (ll i = 0; i <= tv; i++)
if (memo[i] <= w)
ans = max(ans, i);
cout << ans << endl;
return 0;
} | [
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 969,110 | 969,109 | u337353034 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
ll n, w, tv = 0;
ll weights[101];
ll values[101];
// unordered_map<string,int> dpmap;
// ll dp(int pos, ll weight)
// {
// if(weight<0)
// return INT_MIN;
// if(pos<0||weight==0)
// return 0;
// string key = to_string(pos)+"|"+to_string(weight);
// if(dpmap.find(key)==dpmap.end())
// {
// ll takeit = dp(pos-1, weight-weights[pos]) + values[pos];
// ll thankunext = dp(pos-1, weight);
// dpmap[key] = max(takeit, thankunext);
// //cout<<key<<" "<<dpmap[key]<<endl;
// }
// return dpmap[key];
// }
// ll dp(int pos, int value)
// {
// if(pos==n)
// return 0;
// if(memo[pos][value]!=-1)
// return memo[pos][value];
// ll ans = min(dp(pos+1, value + values[pos])-weights[pos], dp(pos+1,
// value)); return memo[pos][value] = ans;
// }
int main() {
cin >> n >> w;
for (ll i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
tv += values[i];
}
vi memo(tv + 2, INT_MAX);
memo[0] = 0;
for (int i = 0; i < n; i++)
for (int j = tv; j >= 0; j--) {
if (j >= values[i])
memo[j] = min(memo[j - values[i]] + weights[i], memo[j]);
}
ll ans = 0;
for (int i = 0; i < tv; i++)
if (memo[i] <= w)
ans = max((int)ans, i);
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
ll n, w, tv = 0;
ll weights[101];
ll values[101];
// unordered_map<string,int> dpmap;
// ll dp(int pos, ll weight)
// {
// if(weight<0)
// return INT_MIN;
// if(pos<0||weight==0)
// return 0;
// string key = to_string(pos)+"|"+to_string(weight);
// if(dpmap.find(key)==dpmap.end())
// {
// ll takeit = dp(pos-1, weight-weights[pos]) + values[pos];
// ll thankunext = dp(pos-1, weight);
// dpmap[key] = max(takeit, thankunext);
// //cout<<key<<" "<<dpmap[key]<<endl;
// }
// return dpmap[key];
// }
// ll dp(int pos, int value)
// {
// if(pos==n)
// return 0;
// if(memo[pos][value]!=-1)
// return memo[pos][value];
// ll ans = min(dp(pos+1, value + values[pos])-weights[pos], dp(pos+1,
// value)); return memo[pos][value] = ans;
// }
int main() {
cin >> n >> w;
for (ll i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
tv += values[i];
}
vi memo(tv + 5, INT_MAX);
memo[0] = 0;
for (int i = 0; i < n; i++)
for (int j = tv; j >= 0; j--) {
if (j >= values[i])
memo[j] = min(memo[j - values[i]] + weights[i], memo[j]);
}
ll ans = 0;
for (ll i = 0; i <= tv; i++)
if (memo[i] <= w)
ans = max(ans, i);
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one"
] | 969,111 | 969,109 | u337353034 | cpp |
p03164 | #include <bits/stdc++.h>
#define Mx 1000000000005
#define ll long long
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll, ll>
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define vii vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a, x) memset(a, x, sizeof(a))
using namespace std;
bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.second < b.second;
}
/*vi b=v;
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
ll t; cin>>t; fr(f,0,t){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
int main() {
ll n, W;
cin >> n >> W;
ll wt[n], v[n], ans;
fr(i, 0, n) cin >> wt[i] >> v[i];
vector<vector<ll>> dp(n + 1, vector<ll>(1e5 + 1, 0));
fr(i, 0, n + 1) dp[i][0] = 0;
fr(j, 0, 1e5 + 1) dp[0][j] = Mx;
dp[0][0] = 0;
fr(i, 1, n + 1) {
fr(j, 1, 1e5 + 1) {
dp[i][j] = dp[i - 1][j];
if (j >= v[i - 1])
dp[i][j] = min(dp[i][j], wt[i - 1] + dp[i - 1][j - v[i - 1]]);
}
}
for (ll i = 1e5 + 1; i >= 0; i--)
if (dp[n][i] <= W) {
ans = i;
break;
}
cout << ans;
} | #include <bits/stdc++.h>
#define Mx 1000000000005
#define ll long long
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll, ll>
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define vii vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a, x) memset(a, x, sizeof(a))
using namespace std;
bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.second < b.second;
}
/*vi b=v;
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
ll t; cin>>t; fr(f,0,t){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
int main() {
ll n, W;
cin >> n >> W;
ll wt[n], v[n], ans;
fr(i, 0, n) cin >> wt[i] >> v[i];
vector<vector<ll>> dp(n + 1, vector<ll>(1e5 + 1, 0));
fr(i, 0, n + 1) dp[i][0] = 0;
fr(j, 0, 1e5 + 1) dp[0][j] = Mx;
dp[0][0] = 0;
fr(i, 1, n + 1) {
fr(j, 1, 1e5 + 1) {
dp[i][j] = dp[i - 1][j];
if (j >= v[i - 1])
dp[i][j] = min(dp[i][j], wt[i - 1] + dp[i - 1][j - v[i - 1]]);
}
}
for (ll i = 1e5; i >= 0; i--)
if (dp[n][i] <= W) {
ans = i;
break;
}
cout << ans;
} | [
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 969,112 | 969,113 | u966249394 | cpp |
p03164 | #include <bits/stdc++.h>
#define Mx 1000000000005
#define ll long long
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll, ll>
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define vii vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a, x) memset(a, x, sizeof(a))
using namespace std;
bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.second < b.second;
}
/*vi b=v;
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
ll t; cin>>t; fr(f,0,t){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
int main() {
ll n, W;
cin >> n >> W;
ll wt[n], v[n], ans;
fr(i, 0, n) cin >> wt[i] >> v[i];
vector<vector<ll>> dp(n + 1, vector<ll>(1e5 + 1, 0));
fr(i, 0, n + 1) dp[i][0] = 0;
fr(j, 0, 1e5 + 1) dp[0][j] = Mx;
dp[0][0] = 0;
fr(i, 1, n + 1) {
fr(j, 1, 1e5 + 1) {
dp[i][j] = dp[i - 1][j];
if (j >= v[i - 1])
dp[i][j] = min(dp[i][j], wt[i - 1] + dp[i - 1][j - v[i - 1]]);
}
}
for (ll i = 1e5 + 1; i >= 0; i--)
if (dp[n][i] <= W) {
ans = i;
break;
}
cout << ans;
} | #include <bits/stdc++.h>
#define Mx 1000000000005
#define ll long long
#define pi 3.141592653
#define vi vector<ll>
#define Mo 1000000007
#define mp make_pair
#define M map<ll, ll>
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define vii vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define ld long double
#define fill(a, x) memset(a, x, sizeof(a))
using namespace std;
bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.second < b.second;
}
/*vi b=v;
sort(b.begin(), b.end());
b.resize(unique(b.begin(), b.end()) - b.begin());
ll t; cin>>t; fr(f,0,t){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/
int main() {
ll n, W;
cin >> n >> W;
ll wt[n], v[n], ans;
fr(i, 0, n) cin >> wt[i] >> v[i];
vector<vector<ll>> dp(n + 1, vector<ll>(1e5 + 1, 0));
fr(i, 1, n + 1) dp[i][0] = 0;
fr(j, 1, 1e5 + 1) dp[0][j] = Mx;
dp[0][0] = 0;
fr(i, 1, n + 1) {
fr(j, 1, 1e5 + 1) {
dp[i][j] = dp[i - 1][j];
if (j >= v[i - 1])
dp[i][j] = min(dp[i][j], wt[i - 1] + dp[i - 1][j - v[i - 1]]);
}
}
for (ll i = 1e5; i >= 0; i--)
if (dp[n][i] <= W) {
ans = i;
break;
}
cout << ans;
} | [
"literal.number.change",
"assignment.variable.change",
"call.arguments.change",
"control_flow.loop.for.initializer.change",
"expression.operation.binary.remove"
] | 969,112 | 969,114 | u966249394 | cpp |
p03164 | #include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
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 main() {
int64_t N, W;
cin >> N >> W;
vector<int64_t> waits(N);
vector<int64_t> values(N);
int64_t max_v = 100100;
int64_t max_n = 110;
for (int64_t i = 0; i < N; i++) {
int64_t w, v;
cin >> w >> v;
waits[i] = w;
values[i] = v;
}
vector<vector<int64_t>> dp(max_n, vector<int64_t>(max_v, 100101));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int sum_v = 0; sum_v < max_v; sum_v++) {
if (sum_v - values[i] >= 0) {
chmin(dp[i + 1][sum_v], dp[i][sum_v - values[i]] + waits[i]);
}
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
int64_t ans = 0;
for (int sum_v = 0; sum_v < max_v; sum_v++) {
if (dp[N][sum_v] <= W) {
ans = sum_v;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
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 main() {
int64_t N, W;
cin >> N >> W;
vector<int64_t> waits(110);
vector<int64_t> values(110);
int64_t max_v = 100100;
int64_t max_n = 110;
for (int64_t i = 0; i < N; i++) {
int64_t w, v;
cin >> w >> v;
waits[i] = w;
values[i] = v;
}
vector<vector<int64_t>> dp(max_n, vector<int64_t>(max_v, 1000000001));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int sum_v = 0; sum_v < max_v; sum_v++) {
if (sum_v - values[i] >= 0) {
chmin(dp[i + 1][sum_v], dp[i][sum_v - values[i]] + waits[i]);
}
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
int64_t ans = 0;
for (int sum_v = 0; sum_v < max_v; sum_v++) {
if (dp[N][sum_v] <= W) {
ans = sum_v;
}
}
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"call.arguments.change"
] | 969,115 | 969,116 | u651314218 | cpp |
p03164 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<vector<int>> items(n, vector<int>(2)); // 0 = weight 1 = value
for (int i = 0; i < n; i++) {
cin >> items[i][0];
cin >> items[i][1];
}
vector<vector<int>> dp(n, vector<int>(100005, 999999999));
dp[0][items[0][1]] = items[0][0];
dp[0][0] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 100005; j++) {
if ((j - items[i][1]) >= 0) {
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - items[i][1]] + items[i][0]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
int ans = 0;
for (int i = 0; i < 100005; i++) {
if (dp[n - 1][i] <= w) {
ans = max(ans, i);
}
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<vector<int>> items(n, vector<int>(2)); // 0 = weight 1 = value
for (int i = 0; i < n; i++) {
cin >> items[i][0];
cin >> items[i][1];
}
vector<vector<long long int>> dp(n,
vector<long long int>(100005, 99999999999));
dp[0][items[0][1]] = items[0][0];
dp[0][0] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 100005; j++) {
if ((j - items[i][1]) >= 0) {
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - items[i][1]] + items[i][0]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
int ans = 0;
for (int i = 0; i < 100005; i++) {
if (dp[n - 1][i] <= w) {
ans = max(ans, i);
}
}
cout << ans << endl;
} | [
"literal.number.change",
"call.arguments.change"
] | 969,155 | 969,156 | u884496139 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxi = 100005;
ll cost[105][maxi];
ll val[105], w[105];
int main() {
ll n, W;
cin >> n >> W;
for (int i = 0; i <= n; i++)
for (int j = 0; j < 100001; j++)
cost[i][j] = 100000000000L;
cost[0][0] = 0;
for (int i = 1; i <= n; i++)
cin >> w[i] >> val[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < 100001; j++) {
cost[i + 1][j] = min(cost[i + 1][j], cost[i][j]);
if (cost[i][j] + w[i + 1] <= W)
cost[i + 1][j + val[i + 1]] =
min(cost[i + 1][j + val[i + 1]], cost[i][j] + w[i + 1]);
}
ll ans = 0;
for (int i = 0; i <= 100001; i++)
if (cost[n][i] <= W)
ans = i;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxi = 100005;
ll cost[105][maxi];
ll val[105], w[105];
int main() {
ll n, W;
cin >> n >> W;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 100001; j++)
cost[i][j] = 100000000000L;
cost[0][0] = 0;
for (int i = 1; i <= n; i++)
cin >> w[i] >> val[i];
for (int i = 0; i < n; i++)
for (int j = 0; j <= 100001; j++) {
cost[i + 1][j] = min(cost[i + 1][j], cost[i][j]);
if (cost[i][j] + w[i + 1] <= W)
cost[i + 1][j + val[i + 1]] =
min(cost[i + 1][j + val[i + 1]], cost[i][j] + w[i + 1]);
}
ll ans = 0;
for (int i = 0; i <= 100001; i++)
if (cost[n][i] <= W)
ans = i;
cout << ans << endl;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 969,159 | 969,160 | u051846813 | cpp |
p03164 | #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <unordered_map>
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define PI 3.14159265358979323
using namespace std;
int main() {
ll n, w, wt[100010], value[100010], ans = 0, mv = 0;
vector<ll> min_wt_for_val(100010, 99999999);
min_wt_for_val[0] = 0;
cin >> n >> w;
for (ll i = 1; i <= n; i++) {
cin >> wt[i] >> value[i];
mv += value[i];
}
for (ll item = 1; item <= n; item++) {
for (ll val = 100002; val >= value[item]; val--) {
min_wt_for_val[val] = min(min_wt_for_val[val],
min_wt_for_val[val - value[item]] + wt[item]);
}
}
for (ll i = 0; i < 100010; i++)
if (min_wt_for_val[i] <= w)
ans = max(ans, i);
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <unordered_map>
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define mod 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
#define gcd __gcd
#define F first
#define S second
#define PI 3.14159265358979323
using namespace std;
int main() {
ll n, w, wt[100010], value[100010], ans = 0, mv = 0;
vector<ll> min_wt_for_val(100010, 9999999999999);
min_wt_for_val[0] = 0;
cin >> n >> w;
for (ll i = 1; i <= n; i++) {
cin >> wt[i] >> value[i];
mv += value[i];
}
for (ll item = 1; item <= n; item++) {
for (ll val = 100002; val >= value[item]; val--) {
min_wt_for_val[val] = min(min_wt_for_val[val],
min_wt_for_val[val - value[item]] + wt[item]);
}
}
for (ll i = 0; i <= mv; i++)
if (min_wt_for_val[i] <= w)
ans = max(ans, i);
cout << ans << "\n";
return 0;
} | [
"literal.number.change",
"call.arguments.change",
"control_flow.loop.for.condition.change"
] | 969,165 | 969,166 | u203251523 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18L + 5;
int main() {
int n, w;
cin >> n >> w;
vector<int> wt(n), val(n);
int sum_val = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
sum_val += val[i];
}
vector<long long> dp(sum_val + 1, INF);
dp[0] = 0;
// dp[i] have min weight for value i
for (int i = 0; i < n; i++) {
for (int j = sum_val; j >= val[i]; j--) {
dp[j] = min(dp[j - val[i]] + wt[i], dp[j]);
}
}
long long ans = 0;
for (int i = 0; i < sum_val; i++) {
if (dp[i] <= w) {
ans = max(ans, (long long)i);
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18L + 5;
int main() {
int n, w;
cin >> n >> w;
vector<int> wt(n), val(n);
int sum_val = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
sum_val += val[i];
}
vector<long long> dp(sum_val + 1, INF);
dp[0] = 0;
// dp[i] have min weight for value i
for (int i = 0; i < n; i++) {
for (int j = sum_val; j >= val[i]; j--) {
dp[j] = min(dp[j - val[i]] + wt[i], dp[j]);
}
}
long long ans = 0;
for (int i = 0; i <= sum_val; i++) {
if (dp[i] <= w) {
ans = max(ans, (long long)i);
}
}
cout << ans;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 969,170 | 969,171 | u061594873 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
ll n, w;
cin >> n >> w;
vector<ll> W(110), V(110); //余裕をもって
vector<vector<ll>> dp(110, vector<ll>(100100)); //価値の最大値はn*10^3=10^5
rep(i, n) cin >> W[i] >> V[i];
// INFで初期化
rep(i, 110) rep(j, 100100) dp[i][j] = INF;
dp[0][0] = 0;
rep(i, n) {
for (int v = 0; v <= 100100; v++) {
dp[i + 1][v] = min(dp[i + 1][v], dp[i][v]); //選ばない
if (v - V[i] >= 0)
dp[i + 1][v] = min(dp[i + 1][v], dp[i][v - V[i]] + W[i]); //選ぶ
}
}
ll ans = 0;
rep(i, n) {
rep(v, 1001001) {
if (dp[i][v] <= w)
ans = v;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
ll n, w;
cin >> n >> w;
vector<ll> W(110), V(110); //余裕をもって
vector<vector<ll>> dp(110, vector<ll>(100100)); //価値の最大値はn*10^3=10^5
rep(i, n) cin >> W[i] >> V[i];
// INFで初期化
rep(i, 110) rep(j, 100100) dp[i][j] = INF;
dp[0][0] = 0;
rep(i, n) {
for (int v = 0; v < 100100; v++) {
dp[i + 1][v] = min(dp[i + 1][v], dp[i][v]); //選ばない
if (v - V[i] >= 0)
dp[i + 1][v] = min(dp[i + 1][v], dp[i][v - V[i]] + W[i]); //選ぶ
}
}
ll ans = 0;
rep(i, n + 1) {
rep(v, 100100) {
if (dp[i][v] <= w)
ans = v;
}
}
cout << ans << endl;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change",
"literal.number.change",
"call.arguments.change"
] | 969,176 | 969,177 | u650236619 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, w;
ll dp[105][100005];
const ll INF = 1LL << 60;
int main() {
cin >> n >> w;
ll weight[n];
ll value[n];
for (ll i = 0; i < n; i++)
cin >> weight[i] >> value[i];
for (ll i = 0; i < n; i++) {
for (ll j = 0; j <= 100000; j++)
dp[i][j] = INF;
}
dp[0][0] = 0;
for (ll i = 0; i < n; i++) {
for (ll sum_v = 0; sum_v <= 100000; sum_v++) {
if (sum_v - value[i] >= 0)
dp[i + 1][sum_v] =
min(dp[i][sum_v - value[i]] + weight[i], dp[i][sum_v]);
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ll res = 0;
for (ll sum_v = 0; sum_v <= 10000; sum_v++) {
if (dp[n][sum_v] <= w)
res = sum_v;
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, w;
ll dp[105][100005];
const ll INF = 1LL << 60;
int main() {
cin >> n >> w;
ll weight[n];
ll value[n];
for (ll i = 0; i < n; i++)
cin >> weight[i] >> value[i];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= 100000; j++)
dp[i][j] = INF;
}
dp[0][0] = 0;
for (ll i = 0; i < n; i++) {
for (ll sum_v = 0; sum_v <= 100000; sum_v++) {
if (sum_v - value[i] >= 0)
dp[i + 1][sum_v] =
min(dp[i][sum_v - value[i]] + weight[i], dp[i + 1][sum_v]);
dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ll res = 0;
for (ll sum_v = 0; sum_v <= 100000; sum_v++) {
if (dp[n][sum_v] <= w)
res = sum_v;
}
cout << res << endl;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change",
"assignment.change",
"literal.number.change"
] | 969,182 | 969,179 | u955282280 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, W;
cin >> n >> W;
ll w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
sum += v[i];
}
ll dp[sum][n + 1];
dp[0][0] = 0;
for (int i = 0; i <= sum; i++) {
for (int j = 0; j <= n; j++) {
if (i != 0 && j == 0) {
dp[i][j] = INT_MAX;
continue;
}
if (i == 0) {
dp[i][j] = 0;
continue;
}
ll take = INT_MAX, not_take = INT_MAX;
if (v[j - 1] <= i) {
take = w[j - 1] + dp[i - v[j - 1]][j - 1];
}
not_take = dp[i][j - 1];
// cout<<take<<" "<<not_take<<endl;
dp[i][j] = min(take, not_take);
}
}
int ans = 0;
for (int i = 0; i <= sum; i++) {
for (int j = 0; j <= n; j++) {
if (dp[i][j] <= W)
ans = max(ans, i);
}
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, W;
cin >> n >> W;
ll w[n], v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
int sum = 1;
for (int i = 0; i < n; i++) {
sum += v[i];
}
ll dp[sum][n + 1];
dp[0][0] = 0;
for (int i = 0; i <= sum; i++) {
for (int j = 0; j <= n; j++) {
if (i != 0 && j == 0) {
dp[i][j] = INT_MAX;
continue;
}
if (i == 0) {
dp[i][j] = 0;
continue;
}
ll take = INT_MAX, not_take = INT_MAX;
if (v[j - 1] <= i) {
take = w[j - 1] + dp[i - v[j - 1]][j - 1];
}
not_take = dp[i][j - 1];
// cout<<take<<" "<<not_take<<endl;
dp[i][j] = min(take, not_take);
}
}
int ans = 0;
for (int i = 0; i <= sum; i++) {
for (int j = 0; j <= n; j++) {
if (dp[i][j] <= W)
ans = max(ans, i);
}
}
cout << ans;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 969,191 | 969,192 | u180171323 | cpp |
p03164 | #include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define ins insert
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define pib pair<int, bool>
#define SET(a, c) memset(a, c, sizeof(a))
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define found(u, val) u.find(val) != u.end()
#include <string>
#include <vector>
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
//#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, W;
cin >> n >> W;
vl values, weights;
values.resize(n);
weights.resize(n);
ll sumValue = 0;
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
sumValue += values[i];
}
ll dp[sumValue + 1];
for (int i = 0; i <= sumValue; i++) {
dp[i] = 10000000;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
int value = values[i], weight = weights[i];
for (int value_already = sumValue - value; value_already >= 0;
value_already--) {
dp[value_already + value] =
min(dp[value_already] + weight, dp[value_already + value]);
// if (dp[value_already + value] != 10000000) cout << dp[value_already +
// value] << endl;
}
}
ll answer = 0;
for (int i = 0; i < sumValue; i++) {
if (dp[i] <= W)
answer = i;
}
cout << answer;
} | #include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define ins insert
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define pib pair<int, bool>
#define SET(a, c) memset(a, c, sizeof(a))
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define found(u, val) u.find(val) != u.end()
#include <string>
#include <vector>
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
//#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, W;
cin >> n >> W;
vl values, weights;
values.resize(n);
weights.resize(n);
ll sumValue = 0;
for (int i = 0; i < n; i++) {
cin >> weights[i] >> values[i];
sumValue += values[i];
}
ll dp[sumValue + 1];
for (int i = 0; i <= sumValue; i++) {
dp[i] = 1e11;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
int value = values[i], weight = weights[i];
for (int value_already = sumValue - value; value_already >= 0;
value_already--) {
dp[value_already + value] =
min(dp[value_already] + weight, dp[value_already + value]);
// if (dp[value_already + value] != 10000000) cout << dp[value_already +
// value] << endl;
}
}
ll answer = 0;
for (int i = 0; i <= sumValue; i++) {
if (dp[i] <= W)
answer = i;
}
cout << answer;
} | [
"literal.number.change",
"assignment.value.change",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 969,195 | 969,194 | u599578478 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq(int x) { return x * x; }
////////////////////////////////////////////////////////////////////Header
const int maxn = 1e5 + 5;
ll n, m;
ll w[maxn], v[maxn];
ll dp[105][maxn];
int main() {
scanl2(n, m);
FORN(i, 1, n) scanl2(w[i], v[i]);
FORN(i, 0, n) FORN(j, 0, maxn - 1) dp[i][j] = 987654321;
dp[0][0] = 0;
ll ans = 0;
FORN(i, 1, n) {
FORN(j, 0, maxn - 1) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j >= v[i])
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
if (dp[i][j] <= m)
ans = max(ans, (ll)j);
}
}
printl1(ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define FORN(i, x, y) for (int i = x; i <= y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define scan1(X) scanf("%d", &X)
#define scan2(X, Y) scanf("%d%d", &X, &Y)
#define scan3(X, Y, Z) scanf("%d%d%d", &X, &Y, &Z)
#define scan4(X, Y, Z, W) scanf("%d%d%d%d", &X, &Y, &Z, &W)
#define scanl1(X) scanf("%lld", &X);
#define scanl2(X, Y) scanf("%lld%lld", &X, &Y)
#define scanl3(X, Y, Z) scanf("%lld%lld%lld", &X, &Y, &Z)
#define scanl4(X, Y, Z, W) scanf("%lld%lld%lld%lld", &X, &Y, &Z, &W)
#define print1(X) printf("%d\n", X);
#define print2(X, Y) printf("%d %d\n", X, Y);
#define print3(X, Y, Z) printf("%d %d %d\n", X, Y, Z);
#define print4(X, Y, Z, W) printf("%d %d %d %d\n", X, Y, Z, W);
#define printl1(X) printf("%lld\n", X);
#define printl2(X, Y) printf("%lld %lld\n", X, Y);
#define printl3(X, Y, Z) printf("%lld %lld %lld\n", X, Y, Z);
#define printl4(X, Y, Z, W) printf("%lld %lld %lld %lld\n", X, Y, Z, W);
#define max3(X, Y, Z) max(X, max(Y, Z))
#define max4(X, Y, Z, W) max(max(X, Y), max(Z, W))
#define min3(X, Y, Z) min(X, min(Y, Z))
#define min4(X, Y, Z, W) min(min(X, Y), min(Z, W))
#define popcount(X) __builtin_popcount(X)
#define all(x) x.begin(), x.end()
#define size(X) (int)X.size()
#define mp make_pair
#define pb push_back
#define fr first
#define sc second
#define lc(x) 2 * x
#define rc(x) 2 * x + 1
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pldld;
const long long l_inf = numeric_limits<long long>::max();
const long long l_ninf = numeric_limits<long long>::min();
const int inf = numeric_limits<int>::max();
const int ninf = numeric_limits<int>::min();
const double pi = 1.00 * acos(-1.00);
const double eps = 1e-8;
void cio() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }
int sq(int x) { return x * x; }
////////////////////////////////////////////////////////////////////Header
const int maxn = 1e5 + 5;
ll n, m;
ll w[maxn], v[maxn];
ll dp[105][maxn];
int main() {
scanl2(n, m);
FORN(i, 1, n) scanl2(w[i], v[i]);
FORN(i, 0, n) FORN(j, 0, maxn - 1) dp[i][j] = 1e15;
dp[0][0] = 0;
ll ans = 0;
FORN(i, 1, n) {
FORN(j, 0, maxn - 1) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j >= v[i])
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
if (dp[i][j] <= m)
ans = max(ans, (ll)j);
}
}
printl1(ans);
}
| [
"literal.number.change",
"assignment.value.change"
] | 969,217 | 969,218 | u732471139 | cpp |
p03164 | #pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi = acos(-1);
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int>> matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define reset(x, v) memset(x, v, sizeof(x))
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p % m * p % m) % m;
if (n % 2)
return (p % m * a % m) % m;
else
return p;
}
const double EPS = 1e-9;
const ll MOD = 998244353;
const ll hell = 1000000007;
const int INF = 1e8;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
double startTime;
double getCurrentTime() {
return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int N = 100005;
int dp[N + 1][101];
int w[N + 1], profit[N + 1];
void solve() {
int n, W;
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> profit[i];
}
// for(int i=1;i<=n;i++)
// dp[0][i]= INF;
for (int i = 1; i <= N; i++) {
dp[i][0] = INF;
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i][j - 1];
if (profit[j] <= i) {
dp[i][j] = min(dp[i][j], w[j] + dp[i - profit[j]][j - 1]);
}
}
}
// cout<<dp[17][n]<<endl;
for (int i = N; i >= 0; i--)
if (dp[i][n] <= W) {
cout << i << endl;
return;
}
}
int32_t main() {
IOS;
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| #pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi = acos(-1);
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int>> matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS \
std::ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define reset(x, v) memset(x, v, sizeof(x))
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
inline ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m) {
if (n == 0)
return 1;
ll p = power(a, n / 2, m);
p = (p % m * p % m) % m;
if (n % 2)
return (p % m * a % m) % m;
else
return p;
}
const double EPS = 1e-9;
const ll MOD = 998244353;
const ll hell = 1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
double startTime;
double getCurrentTime() {
return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const int N = 100005;
int dp[N + 1][101];
int w[N + 1], profit[N + 1];
void solve() {
int n, W;
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> profit[i];
}
// for(int i=1;i<=n;i++)
// dp[0][i]= INF;
for (int i = 1; i <= N; i++) {
dp[i][0] = INF;
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i][j - 1];
if (profit[j] <= i) {
dp[i][j] = min(dp[i][j], w[j] + dp[i - profit[j]][j - 1]);
}
}
}
// cout<<dp[17][n]<<endl;
for (int i = N; i >= 0; i--)
if (dp[i][n] <= W) {
cout << i << endl;
return;
}
}
int32_t main() {
IOS;
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 969,221 | 969,222 | u314476982 | cpp |
p03164 | #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e18L + 5;
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n), value(n);
for (ll i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++) {
sum_value = sum_value + value[i];
}
vector<ll> dp(sum_value + 1, INF);
dp[0] = 0;
for (ll item = 0; item < n; item++) {
for (ll value_already = sum_value - value[item]; value_already >= 0;
value_already--) {
min_self(dp[value_already + value[item]],
dp[value_already] + weight[item]);
}
}
ll answer = INF;
for (ll i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
answer = max(answer, i);
}
}
cout << answer;
return 0;
}
| #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e18L + 5;
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n), value(n);
for (ll i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++) {
sum_value = sum_value + value[i];
}
vector<ll> dp(sum_value + 1, INF);
dp[0] = 0;
for (ll item = 0; item < n; item++) {
for (ll value_already = sum_value - value[item]; value_already >= 0;
value_already--) {
min_self(dp[value_already + value[item]],
dp[value_already] + weight[item]);
}
}
ll answer = 0;
for (ll i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
answer = max(answer, i);
}
}
cout << answer;
return 0;
}
| [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 969,257 | 969,258 | u772397797 | cpp |
p03164 | #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e18L + 5;
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n), value(n);
for (ll i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++) {
sum_value = sum_value + value[i];
}
vector<ll> dp(sum_value + 1, INF);
dp[0] = 0;
for (ll item = 0; item < n; item++) {
for (ll value_already = value_already - value[item]; value_already >= 0;
value_already--) {
min_self(dp[value_already + value[item]],
dp[value_already] + weight[item]);
}
}
ll answer = INF;
for (ll i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
answer = max(answer, i);
}
}
cout << answer;
return 0;
}
| #include <bits/stdc++.h>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1e18L + 5;
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n), value(n);
for (ll i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++) {
sum_value = sum_value + value[i];
}
vector<ll> dp(sum_value + 1, INF);
dp[0] = 0;
for (ll item = 0; item < n; item++) {
for (ll value_already = sum_value - value[item]; value_already >= 0;
value_already--) {
min_self(dp[value_already + value[item]],
dp[value_already] + weight[item]);
}
}
ll answer = 0;
for (ll i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
answer = max(answer, i);
}
}
cout << answer;
return 0;
}
| [
"identifier.change",
"control_flow.loop.for.initializer.change",
"expression.operation.binary.change",
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 969,259 | 969,258 | u772397797 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int main() {
int N;
int W;
cin >> N >> W;
vector<vector<int>> dp(N + 1, vector<int>(1e5 + 1, 1e9 + 1));
dp[0][0] = 0;
vector<int> weight(N + 1, 0);
vector<int> value(N + 1, 0);
int temp_w, temp_v;
for (int i = 1; i < N + 1; i++) {
cin >> temp_w >> temp_v;
weight[i] = temp_w;
value[i] = temp_v;
}
for (int i = 1; i < N + 1; i++) {
for (int j = 1; j < 1e5 + 1; j++) {
if (j - value[i] >= 0)
// min(品物を選ばない場合の重量, 品物を選ぶ場合の重量 +
// 余った価値で最小の重量)
dp[i][j] = min(dp[i - 1][j], weight[i] + dp[i - 1][j - value[i]]);
else
dp[i][j] = dp[i - 1][j];
}
}
int ans = 100000;
while (dp[N][ans] > W) {
ans -= 1;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int main() {
int N;
int W;
cin >> N >> W;
vector<vector<int>> dp(N + 1, vector<int>(1e5 + 1, 1e9 + 1));
dp[0][0] = 0;
vector<int> weight(N + 1, 0);
vector<int> value(N + 1, 0);
int temp_w, temp_v;
for (int i = 1; i < N + 1; i++) {
cin >> temp_w >> temp_v;
weight[i] = temp_w;
value[i] = temp_v;
}
for (int i = 1; i < N + 1; i++) {
for (int j = 0; j < 1e5 + 1; j++) {
if (j - value[i] >= 0)
// min(品物を選ばない場合の重量, 品物を選ぶ場合の重量 +
// 余った価値で最小の重量)
dp[i][j] = min(dp[i - 1][j], weight[i] + dp[i - 1][j - value[i]]);
else
dp[i][j] = dp[i - 1][j];
}
}
int ans = 100000;
while (dp[N][ans] > W) {
ans -= 1;
}
cout << ans << endl;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 969,266 | 969,267 | u840310460 | cpp |
p03164 | #include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
vector<vector<int>> graph;
bool sort_sec(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second < b.second) {
return true;
}
return false;
}
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main(void) {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long>> dp(N + 1, vector<long long>(100007));
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 100007; j++) {
dp[i][j] = 1000000007;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 100007; j++) {
if (v[i] <= j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
}
int ans = -1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= 100000; j++) {
if (dp[i][j] <= W) {
ans = j;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
vector<vector<int>> graph;
bool sort_sec(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second < b.second) {
return true;
}
return false;
}
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main(void) {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long>> dp(N + 1, vector<long long>(100007));
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 100007; j++) {
dp[i][j] = 1000000007;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 100007; j++) {
if (v[i] <= j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
int ans = -1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= 100000; j++) {
if (dp[i][j] <= W) {
ans = j;
}
}
}
cout << ans << endl;
return 0;
}
| [] | 969,275 | 969,276 | u150155436 | cpp |
p03164 | #include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
vector<vector<int>> graph;
bool sort_sec(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second < b.second) {
return true;
}
return false;
}
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main(void) {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long>> dp(N + 1, vector<long long>(100007));
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 100007; j++) {
dp[i][j] = 1000000007;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 100007; j++) {
if (w[i] <= j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
}
int ans = -1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= 100000; j++) {
if (dp[i][j] <= W) {
ans = j;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
vector<vector<int>> graph;
bool sort_sec(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second < b.second) {
return true;
}
return false;
}
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main(void) {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long>> dp(N + 1, vector<long long>(100007));
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 100007; j++) {
dp[i][j] = 1000000007;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 100007; j++) {
if (v[i] <= j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
int ans = -1;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= 100000; j++) {
if (dp[i][j] <= W) {
ans = j;
}
}
}
cout << ans << endl;
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 969,277 | 969,276 | u150155436 | cpp |
p03164 | /*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr
andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.
___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !
___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard
*/
#include <bits/stdc++.h>
#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2) + 1)
#define fuck(x) cout << #x << " : " << x << endl;
#define findLowVec(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a, n, x) (lower_bound(a, a + n, x) - a)
#define findUpArr(a, n, x) (upper_bound(a, a + n, x) - a)
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &v) {
out << "[";
for (int i = 0; i < v.size(); i++) {
if (i)
out << ", ";
out << v[i];
}
return out << "]";
}
template <class A, class B>
ostream &operator<<(ostream &out, const set<A, B> &s) {
out << "[";
for (auto i = s.begin(); i != s.end(); i++) {
out << ", ";
out << *i;
}
return out << "]";
}
template <class A> ostream &operator<<(ostream &out, const set<A> &s) {
out << "[";
for (auto i = s.begin(); i != s.end(); i++) {
out << ", ";
out << *i;
}
return out << "]";
}
const int N = 1e5 + 10;
int dp[N];
const int inf = 1e18L + 10;
int32_t SALI() {
cout << inf;
int n, W;
cin >> n >> W;
int w[n];
int v[n];
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
sum += v[i];
}
for (int i = 1; i < N; i++) {
dp[i] = inf;
}
for (int i = 0; i < n; i++) {
for (int j = sum; j >= v[i]; j--) {
dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (dp[i] <= W) {
ans = i;
}
}
cout << ans << endl;
}
/**< WRITEN BY ALI ADELKHAH */
| /*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr
andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.
___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !
___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard
*/
#include <bits/stdc++.h>
#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2) + 1)
#define fuck(x) cout << #x << " : " << x << endl;
#define findLowVec(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a, n, x) (lower_bound(a, a + n, x) - a)
#define findUpArr(a, n, x) (upper_bound(a, a + n, x) - a)
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template <class A> ostream &operator<<(ostream &out, const vector<A> &v) {
out << "[";
for (int i = 0; i < v.size(); i++) {
if (i)
out << ", ";
out << v[i];
}
return out << "]";
}
template <class A, class B>
ostream &operator<<(ostream &out, const set<A, B> &s) {
out << "[";
for (auto i = s.begin(); i != s.end(); i++) {
out << ", ";
out << *i;
}
return out << "]";
}
template <class A> ostream &operator<<(ostream &out, const set<A> &s) {
out << "[";
for (auto i = s.begin(); i != s.end(); i++) {
out << ", ";
out << *i;
}
return out << "]";
}
const int N = 1e5 + 10;
int dp[N];
const int inf = 1e18L + 10;
int32_t SALI() {
int n, W;
cin >> n >> W;
int w[n];
int v[n];
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
sum += v[i];
}
for (int i = 1; i < N; i++) {
dp[i] = inf;
}
for (int i = 0; i < n; i++) {
for (int j = sum; j >= v[i]; j--) {
dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
}
}
int ans = 0;
for (int i = 0; i < N; i++) {
if (dp[i] <= W) {
ans = i;
}
}
cout << ans << endl;
}
/**< WRITEN BY ALI ADELKHAH */
| [] | 969,283 | 969,284 | u232873057 | cpp |
p03164 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int w;
cin >> w;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
}
vector<int> dp(100001, 1e10);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 100000; j >= b[i]; j--)
dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
}
int soln = 0;
for (int i = 0; i <= 100000; i++) {
if (dp[i] <= w)
soln = i;
}
cout << soln;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int w;
cin >> w;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
}
vector<long int> dp(100001, 1e10);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 100000; j >= b[i]; j--)
dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
}
int soln = 0;
for (int i = 1; i <= 100000; i++) {
if (dp[i] <= w * 1l)
soln = i;
}
cout << soln;
return 0;
}
| [
"variable_declaration.type.widen.change",
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 969,285 | 969,286 | u430302520 | cpp |
p03164 | /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, W, tot = 0;
cin >> n >> W;
long long int dp[100005];
for (int i = 1; i < 100005; i++)
dp[i] = 20;
// memset(dp,20,sizeof(dp));
dp[0] = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
sum += v;
for (int j = sum - v; j >= 0; j--)
dp[j + v] = min(dp[j + v], dp[j] + w);
}
for (int i = sum; i >= 0; i--) {
if (dp[i] <= W) {
cout << i;
return 0;
}
}
}
| /******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, W, tot = 0;
cin >> n >> W;
long long int dp[100005];
for (int i = 1; i < 100005; i++)
dp[i] = 1e9;
// memset(dp,20,sizeof(dp));
dp[0] = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
sum += v;
for (int j = sum - v; j >= 0; j--)
dp[j + v] = min(dp[j + v], dp[j] + w);
}
for (int i = sum; i >= 0; i--) {
if (dp[i] <= W) {
cout << i;
return 0;
}
}
}
| [
"literal.number.change",
"assignment.value.change"
] | 969,302 | 969,303 | u266399570 | cpp |
p03164 | #include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i, a, n) for (int i = a; i < n; i++)
#define ll long long int
#define li long int
using namespace std;
int n;
li weight;
vector<int> w(101);
vector<int> v(101);
vector<vector<ll>> dp(101, vector<ll>(100005, -1));
int sum = 0;
ll cost(int ind, int sum1) {
if (ind > n || sum1 <= 0) {
if (sum1 == 0)
return 0;
else
return LONG_MAX;
}
if (dp[ind][sum1] == -1) {
if (v[ind] <= sum1) {
ll left = cost(ind + 1, sum1 - v[ind]) + w[ind];
ll right = cost(ind + 1, sum1);
dp[ind][sum1] = min(left, right);
} else
dp[ind][sum1] = cost(ind + 1, sum1);
}
return dp[ind][sum1];
}
int check() {
for (int i = sum; i > 0; i--) {
ll ans = cost(1, i);
// cout<<ans<<" "<<weight;
if (ans <= weight) {
return i;
}
}
return 0;
}
int main() {
cin >> n >> weight;
// cout<<"hello"<<weight;
fo(i, 1, n + 1) cin >> w[i] >> v[i];
fo(i, 1, n + 1) sum += v[i];
cout << check();
// ll ans=cost(1,sum,weight);
// cout<<ans;
}
| #include <bits/stdc++.h>
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i, a, n) for (int i = a; i < n; i++)
#define ll long long int
#define li long int
using namespace std;
int n;
li weight;
vector<int> w(101);
vector<int> v(101);
vector<vector<ll>> dp(101, vector<ll>(100005, -1));
int sum = 0;
ll cost(int ind, int sum1) {
if (ind > n || sum1 <= 0) {
if (sum1 == 0)
return 0;
else
return INT_MAX;
}
if (dp[ind][sum1] == -1) {
if (v[ind] <= sum1) {
ll left = cost(ind + 1, sum1 - v[ind]) + w[ind];
ll right = cost(ind + 1, sum1);
dp[ind][sum1] = min(left, right);
} else
dp[ind][sum1] = cost(ind + 1, sum1);
}
return dp[ind][sum1];
}
int check() {
for (int i = sum; i > 0; i--) {
ll ans = cost(1, i);
// cout<<ans<<" "<<weight;
if (ans <= weight) {
return i;
}
}
return 0;
}
int main() {
cin >> n >> weight;
// cout<<"hello"<<weight;
fo(i, 1, n + 1) cin >> w[i] >> v[i];
fo(i, 1, n + 1) sum += v[i];
cout << check();
// ll ans=cost(1,sum,weight);
// cout<<ans;
}
| [
"identifier.change",
"function.return_value.change"
] | 969,310 | 969,311 | u765828490 | cpp |
p03164 | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define pb push_back
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using vst = vector<string>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll dp[110][110000]; // iまで 価値vになる最小値w
ll w[110], v[110];
int main() {
cout << fixed << setprecision(10);
int n, W;
cin >> n >> W;
rep(i, 1, n + 1) { cin >> w[i] >> v[i]; }
rep(i, 1, 110000) dp[0][i] = INF;
rep(i, 1, n + 1) {
rep(j, 0, 110000) {
dp[i][j] = dp[i - 1][j];
if (j - w[i] >= 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
}
}
int ans = 0;
rep(i, 0, 110000) {
if (dp[n][i] <= W)
chmax(ans, i);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
#define pb push_back
using ll = long long;
using vin = vector<int>;
using vll = vector<ll>;
using vst = vector<string>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <class T> inline void Yes(T condition) {
if (condition)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
template <class T> inline void YES(T condition) {
if (condition)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll dp[110][110000]; // iまで 価値vになる最小値w
ll w[110], v[110];
int main() {
cout << fixed << setprecision(10);
int n, W;
cin >> n >> W;
rep(i, 1, n + 1) { cin >> w[i] >> v[i]; }
rep(i, 1, 110000) dp[0][i] = INF;
rep(i, 1, n + 1) {
rep(j, 0, 110000) {
dp[i][j] = dp[i - 1][j];
if (j - v[i] >= 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
}
}
int ans = 0;
rep(i, 0, 110000) {
if (dp[n][i] <= W)
chmax(ans, i);
}
cout << ans << endl;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 969,312 | 969,313 | u531461815 | cpp |
p03164 | #include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
/* range: ± 3.27 * 10^4 */
using i16 = short int;
/* range: 0 to 65535 */
using u16 = short unsigned int;
/* range: ± 2.14 * 10^9 */
using i32 = int;
/* range: 0 to 4.29 * 10^9 */
using u32 = unsigned int;
/* range: ± 9.22 * 10^18 */
using i64 = long long int;
/* range: 0 to 1.84 * 10^19 */
using u64 = long long unsigned int;
static constexpr i32 MAX = 1e9 + 7;
// array<array<i32, 101>, 100007> memo;
// i32 knapsackRecur(const vector<i32>& w, const vector<i32>& v, i32 val,
// i32 idx = 0) {
// if (val <= 0) {
// return 0;
// }
// if (idx == w.size()) {
// return MAX;
// }
// if (memo[val][idx] != -1) {
// return memo[val][idx];
// }
// memo[val][idx] = min(knapsackRecur(w, v, val, idx + 1),
// w[idx] + knapsackRecur(w, v, val - v[idx], idx +
// 1));
// return memo[val][idx];
// }
i32 knapsack2(const vector<i32> &w, const vector<i32> &v, i32 capacity,
i32 max_val) {
vector<i32> dp(max_val + 1, MAX);
dp[0] = 0;
for (i32 i = 0; i < w.size(); i++) {
for (auto val = max_val; val >= v[i]; val--) {
dp[val] = min(dp[val], dp[val - v[i]] + w[i]);
}
}
// for (; max_val > 0; max_val--) {
// if (knapsackRecur(w, v, max_val) <= capacity) {
// return max_val;
// }
// }
for (auto val = max_val; val > 0; val--) {
if (val <= capacity) {
return val;
}
}
return 0;
}
i32 main() {
i32 items = 0, capacity = 0;
cin >> items >> capacity;
i32 max_val = 0;
vector<i32> w(items), v(items);
for (i32 i = 0; i < items; i++) {
cin >> w[i] >> v[i];
max_val += v[i];
}
// memo[0].fill(-1);
// memo.fill(memo[0]);
cout << knapsack2(w, v, capacity, max_val) << '\n';
} | #include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
/* range: ± 3.27 * 10^4 */
using i16 = short int;
/* range: 0 to 65535 */
using u16 = short unsigned int;
/* range: ± 2.14 * 10^9 */
using i32 = int;
/* range: 0 to 4.29 * 10^9 */
using u32 = unsigned int;
/* range: ± 9.22 * 10^18 */
using i64 = long long int;
/* range: 0 to 1.84 * 10^19 */
using u64 = long long unsigned int;
static constexpr i32 MAX = 1e9 + 7;
// array<array<i32, 101>, 100007> memo;
// i32 knapsackRecur(const vector<i32>& w, const vector<i32>& v, i32 val,
// i32 idx = 0) {
// if (val <= 0) {
// return 0;
// }
// if (idx == w.size()) {
// return MAX;
// }
// if (memo[val][idx] != -1) {
// return memo[val][idx];
// }
// memo[val][idx] = min(knapsackRecur(w, v, val, idx + 1),
// w[idx] + knapsackRecur(w, v, val - v[idx], idx +
// 1));
// return memo[val][idx];
// }
i32 knapsack2(const vector<i32> &w, const vector<i32> &v, i32 capacity,
i32 max_val) {
vector<i32> dp(max_val + 1, MAX);
dp[0] = 0;
for (i32 i = 0; i < w.size(); i++) {
for (auto val = max_val; val >= v[i]; val--) {
dp[val] = min(dp[val], dp[val - v[i]] + w[i]);
}
}
// for (; max_val > 0; max_val--) {
// if (knapsackRecur(w, v, max_val) <= capacity) {
// return max_val;
// }
// }
for (auto val = max_val; val > 0; val--) {
if (dp[val] <= capacity) {
return val;
}
}
return 0;
}
i32 main() {
i32 items = 0, capacity = 0;
cin >> items >> capacity;
i32 max_val = 0;
vector<i32> w(items), v(items);
for (i32 i = 0; i < items; i++) {
cin >> w[i] >> v[i];
max_val += v[i];
}
// memo[0].fill(-1);
// memo.fill(memo[0]);
cout << knapsack2(w, v, capacity, max_val) << '\n';
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 969,316 | 969,317 | u865044045 | cpp |
p03164 | #include <bits/stdc++.h>
#define ll long long int
#define lld long double
#define pb push_back
#define pii pair<ll, ll>
#define mi map<ll, ll>
#define vec vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repi(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define mit map<ll, ll>::iterator
#define sit set<ll>::iterator
#define pit pair<ll, ll>::iterator
#define tr(container, it) \
for (__typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) { return (x | y) & (~x | ~y); }
ll bin_Expo(ll x, ll n) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return bin_Expo(x * x, n / 2);
else // n is odd
return x * bin_Expo(x * x, (n - 1) / 2);
}
ll mod_Expo(ll x, ll n, ll M) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return mod_Expo((x * x) % M, n / 2, M);
else // n is odd
return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;
}
ll NcR(int n, int r) {
ll p = 1, k = 1;
if (n - r < r)
r = n - r;
if (r != 0) {
while (r) {
p *= n;
k *= r;
ll m = __gcd(p, k);
p /= m;
k /= m;
n--;
r--;
}
} else
p = 1;
return p;
}
bool prime_check(ll x) {
bool prime = (x >= 2);
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) {
prime = false;
break;
}
}
return prime;
}
ll logg(ll base, ll x) { return (ll)(log(x) / log(base)); }
ll po(ll n) {
ll k = 0;
while (n % 2 == 0) {
k++;
n = n / 2;
}
return k;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
ll i, j, l, m, k, n, w;
cin >> n >> w;
ll dp[100001];
pii a[n];
rep(i, 0, n) cin >> a[i].F >> a[i].S;
k = 0;
rep(i, 0, 100001) { dp[i] = mod; }
dp[0] = 0;
rep(i, 0, n) {
per(j, 100001, 0) {
dp[j] = min(dp[j], (j >= a[i].S) ? dp[j - a[i].S] + a[i].F : mod);
}
}
repi(i, 0, 100000) {
if (w >= dp[i])
k = i;
}
cout << k;
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define lld long double
#define pb push_back
#define pii pair<ll, ll>
#define mi map<ll, ll>
#define vec vector<ll>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define mod 1000000007
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define repi(i, a, b) for (ll i = a; i <= b; i++)
#define per(i, a, b) for (ll i = a; i >= b; i--)
#define mp make_pair
#define mit map<ll, ll>::iterator
#define sit set<ll>::iterator
#define pit pair<ll, ll>::iterator
#define tr(container, it) \
for (__typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) { return (x | y) & (~x | ~y); }
ll bin_Expo(ll x, ll n) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return bin_Expo(x * x, n / 2);
else // n is odd
return x * bin_Expo(x * x, (n - 1) / 2);
}
ll mod_Expo(ll x, ll n, ll M) {
if (x == 0)
return 0;
if (n == 0)
return 1;
else if (n % 2 == 0) // n is even
return mod_Expo((x * x) % M, n / 2, M);
else // n is odd
return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;
}
ll NcR(int n, int r) {
ll p = 1, k = 1;
if (n - r < r)
r = n - r;
if (r != 0) {
while (r) {
p *= n;
k *= r;
ll m = __gcd(p, k);
p /= m;
k /= m;
n--;
r--;
}
} else
p = 1;
return p;
}
bool prime_check(ll x) {
bool prime = (x >= 2);
for (ll i = 2; i * i <= x; i++) {
if (x % i == 0) {
prime = false;
break;
}
}
return prime;
}
ll logg(ll base, ll x) { return (ll)(log(x) / log(base)); }
ll po(ll n) {
ll k = 0;
while (n % 2 == 0) {
k++;
n = n / 2;
}
return k;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
ll i, j, l, m, k, n, w;
cin >> n >> w;
ll dp[100005];
pii a[n];
rep(i, 0, n) cin >> a[i].F >> a[i].S;
k = 0;
rep(i, 0, 100005) { dp[i] = mod; }
dp[0] = 0;
rep(i, 0, n) {
per(j, 100004, 0) {
dp[j] = min(dp[j], (j >= a[i].S) ? dp[j - a[i].S] + a[i].F : mod);
}
}
repi(i, 0, 100004) {
if (w >= dp[i])
k = i;
}
cout << k;
}
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"call.arguments.change"
] | 969,331 | 969,332 | u334773822 | cpp |
p03164 | #include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
#define ll long long
#define ld long double
#define vll vector<ll>
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) \
cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \
<< z << endl;
#define deb4(w, x, y, z) \
cout << #w << " : " << w << "\t" << #x << " : " << x << "\t" << #y << " : " \
<< y << "\t" << #z << " : " << z << endl;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define printv(a) \
for (ll i = 0; i < a.size(); i++) \
cout << a[i] << " ";
const int mod = 998244353.;
const int N = 1e6 + 5;
bool sortbysec(const pair<pair<ll, ll>, ll> &a,
const pair<pair<ll, ll>, ll> &b) {
return (a.second > b.second);
}
ll powermod(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
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;
}
int main() {
FAST;
ll n, W;
cin >> n >> W;
vll wt(n), val(n);
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++)
sum_value += val[i];
ll inf = 1e18 + 5;
vll dp(sum_value, inf);
dp[0] = 0;
for (ll i = 0; i < n; i++) {
for (ll value_already = sum_value - val[i]; value_already >= 0;
value_already--) {
dp[value_already + val[i]] =
min(dp[value_already + val[i]], dp[value_already] + wt[i]);
}
}
ll ans = 0;
for (ll i = 0; i <= sum_value; i++) {
if (dp[i] <= W)
ans = max(ans, i);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
#define ll long long
#define ld long double
#define vll vector<ll>
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) \
cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \
<< z << endl;
#define deb4(w, x, y, z) \
cout << #w << " : " << w << "\t" << #x << " : " << x << "\t" << #y << " : " \
<< y << "\t" << #z << " : " << z << endl;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define printv(a) \
for (ll i = 0; i < a.size(); i++) \
cout << a[i] << " ";
const int mod = 998244353.;
const int N = 1e6 + 5;
bool sortbysec(const pair<pair<ll, ll>, ll> &a,
const pair<pair<ll, ll>, ll> &b) {
return (a.second > b.second);
}
ll powermod(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
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;
}
int main() {
FAST;
ll n, W;
cin >> n >> W;
vll wt(n), val(n);
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++)
sum_value += val[i];
ll inf = 1e18 + 5;
vll dp(sum_value + 1, inf);
dp[0] = 0;
for (ll i = 0; i < n; i++) {
for (ll value_already = sum_value - val[i]; value_already >= 0;
value_already--) {
dp[value_already + val[i]] =
min(dp[value_already + val[i]], dp[value_already] + wt[i]);
}
}
ll ans = 0;
for (ll i = 0; i <= sum_value; i++) { // deb(dp[i]);
if (dp[i] <= W)
ans = max(ans, i);
}
cout << ans;
return 0;
} | [
"assignment.change"
] | 969,339 | 969,340 | u731601480 | cpp |
p03164 | #include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
#define ll long long
#define ld long double
#define vll vector<ll>
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) \
cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \
<< z << endl;
#define deb4(w, x, y, z) \
cout << #w << " : " << w << "\t" << #x << " : " << x << "\t" << #y << " : " \
<< y << "\t" << #z << " : " << z << endl;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define printv(a) \
for (ll i = 0; i < a.size(); i++) \
cout << a[i] << " ";
const int mod = 998244353.;
const int N = 1e6 + 5;
bool sortbysec(const pair<pair<ll, ll>, ll> &a,
const pair<pair<ll, ll>, ll> &b) {
return (a.second > b.second);
}
ll powermod(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
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;
}
int main() {
FAST;
ll n, W;
cin >> n >> W;
vll wt(n), val(n);
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++)
sum_value += val[i];
ll inf = 1e18 + 5;
vll dp(sum_value, inf);
dp[0] = 0;
for (ll i = 0; i < n; i++) {
for (ll value_already = sum_value - val[i]; value_already >= 0;
value_already--) {
dp[value_already + val[i]] =
min(dp[value_already + val[i]], dp[value_already] + wt[i]);
}
}
ll ans = 0;
for (ll i = 0; i < sum_value; i++) {
if (dp[i] <= W)
ans = max(ans, i);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
#define ll long long
#define ld long double
#define vll vector<ll>
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define deb(x) cout << #x << " : " << x << endl;
#define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define deb3(x, y, z) \
cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \
<< z << endl;
#define deb4(w, x, y, z) \
cout << #w << " : " << w << "\t" << #x << " : " << x << "\t" << #y << " : " \
<< y << "\t" << #z << " : " << z << endl;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define printv(a) \
for (ll i = 0; i < a.size(); i++) \
cout << a[i] << " ";
const int mod = 998244353.;
const int N = 1e6 + 5;
bool sortbysec(const pair<pair<ll, ll>, ll> &a,
const pair<pair<ll, ll>, ll> &b) {
return (a.second > b.second);
}
ll powermod(ll x, ll y, ll p) {
ll res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
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;
}
int main() {
FAST;
ll n, W;
cin >> n >> W;
vll wt(n), val(n);
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
ll sum_value = 0;
for (ll i = 0; i < n; i++)
sum_value += val[i];
ll inf = 1e18 + 5;
vll dp(sum_value + 1, inf);
dp[0] = 0;
for (ll i = 0; i < n; i++) {
for (ll value_already = sum_value - val[i]; value_already >= 0;
value_already--) {
dp[value_already + val[i]] =
min(dp[value_already + val[i]], dp[value_already] + wt[i]);
}
}
ll ans = 0;
for (ll i = 0; i <= sum_value; i++) { // deb(dp[i]);
if (dp[i] <= W)
ans = max(ans, i);
}
cout << ans;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 969,341 | 969,340 | u731601480 | cpp |
p03164 | #include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
// wierd debugging stuff
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n"; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) \
for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i, x) for (auto &i : x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second
template <class T> bool umin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool umax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template <class A> void read(vt<A> &v);
template <class A, size_t S> void read(ar<A, S> &a);
template <class T> void read(T &x) { cin >> x; }
void read(double &d) {
string t;
read(t);
d = stod(t);
}
void read(long double &d) {
string t;
read(t);
d = stold(t);
}
template <class H, class... T> void read(H &h, T &...t) {
read(h);
read(t...);
}
template <class A> void read(vt<A> &x) { foe(a, x) read(a); }
int nxt() {
int a;
cin >> a;
return a;
}
// no change
const ll MOD = 1e9 + 7;
int n;
const int mx = 2e5 + 1;
void Titan() {
int w;
read(n, w);
vll W(n), V(n);
fo(n) { cin >> W[i] >> V[i]; }
ll sum_values = 0;
fo(n) { sum_values += V[i]; }
const ll inf = 1e18l + 1;
vll dp(sum_values + 1, inf);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = sum_values - V[i]; j >= 0; --j) {
// for(int j = 98values - V[i];j++){
umin(dp[j + V[i]], dp[j] + W[i]);
}
}
ll ans = 0;
fo(sum_values) {
if (dp[i] <= w)
umax(ans, (ll)i);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T; //cmt if one test case
fo(T) {
// cout << "Case #" << i+1 << ": " ;
Titan();
}
}
/*///////////////////////////////////////////////////////////
Important Notes :
* check long long
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/
| #include "bits/stdc++.h"
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
// wierd debugging stuff
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n"; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// end of weird debugging stuff
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define F_OR(i, a, b, s) \
for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define foe(i, x) for (auto &i : x)
#define ar array
#define pb push_back
#define vt vector
#define F first
#define S second
template <class T> bool umin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T> bool umax(T &a, const T &b) { return b > a ? a = b, 1 : 0; }
template <class A> void read(vt<A> &v);
template <class A, size_t S> void read(ar<A, S> &a);
template <class T> void read(T &x) { cin >> x; }
void read(double &d) {
string t;
read(t);
d = stod(t);
}
void read(long double &d) {
string t;
read(t);
d = stold(t);
}
template <class H, class... T> void read(H &h, T &...t) {
read(h);
read(t...);
}
template <class A> void read(vt<A> &x) { foe(a, x) read(a); }
int nxt() {
int a;
cin >> a;
return a;
}
// no change
const ll MOD = 1e9 + 7;
int n;
const int mx = 2e5 + 1;
void Titan() {
ll w;
read(n, w);
vll W(n), V(n);
fo(n) { cin >> W[i] >> V[i]; }
ll sum_values = 0;
fo(n) { sum_values += V[i]; }
const ll inf = 1e18l + 1;
vll dp(sum_values + 1, inf);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = sum_values - V[i]; j >= 0; --j) {
// for(int j = 98values - V[i];j++){
umin(dp[j + V[i]], dp[j] + W[i]);
}
}
ll ans = 0;
fo(sum_values + 1) {
if (dp[i] <= w)
umax(ans, (ll)i);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
// cin >> T; //cmt if one test case
fo(T) {
// cout << "Case #" << i+1 << ": " ;
Titan();
}
}
/*///////////////////////////////////////////////////////////
Important Notes :
* check long long
* check base cases
* do not loose Hope
* if case fails on 2nd test case maybe some cases are missing check them
* do not sit idle
* try to do it using pen/paper.
*/
| [
"variable_declaration.type.change"
] | 969,370 | 969,371 | u161309389 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.