Datasets:

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 <algorithm> #include <array> #include <bitset> #include <cctype> #include <cinttypes> #include <climits> #include <cmath> #include <complex> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <new> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; static int F[100001]; while (N--) { int a, b; cin >> a >> b; for (auto i = M; i >= a; --i) F[i] = max(F[i], F[i - a] + b); } cout << F[M] << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cctype> #include <cinttypes> #include <climits> #include <cmath> #include <complex> #include <cstddef> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <new> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; static long long F[100001]; while (N--) { int a, b; cin >> a >> b; for (auto i = M; i >= a; --i) F[i] = max(F[i], F[i - a] + b); } cout << F[M] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,787
966,788
u169524054
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n, W, i, j; cin >> n >> W; int w[n + 1], v[n + 1]; for (i = 0; i < n; i++) { cin >> w[i] >> v[i]; } int k[n + 1][W + 1]; for (i = 0; i <= n; i++) { k[i][0] = 0; } for (i = 0; i <= W; i++) { k[0][i] = 0; } for (i = 1; i <= n; i++) { for (j = 1; j <= W; j++) { if (j >= w[i - 1]) { k[i][j] = max(v[i - 1] + k[i - 1][j - w[i - 1]], k[i - 1][j]); } else k[i][j] = k[i - 1][j]; } } cout << k[n][W]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, W, i, j; cin >> n >> W; long long w[n + 1], v[n + 1]; for (i = 0; i < n; i++) { cin >> w[i] >> v[i]; } long long k[n + 1][W + 1]; for (i = 0; i <= n; i++) { k[i][0] = 0; } for (i = 0; i <= W; i++) { k[0][i] = 0; } for (i = 1; i <= n; i++) { for (j = 1; j <= W; j++) { if (j >= w[i - 1]) { k[i][j] = max(v[i - 1] + k[i - 1][j - w[i - 1]], k[i - 1][j]); } else k[i][j] = k[i - 1][j]; } } cout << k[n][W]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,793
966,794
u580216411
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long #define loop(i, a, b) for (int i = a; i < b; ++i) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N, W; cin >> N >> W; vector<ll> weights(N + 1), values(N + 1); loop(i, 1, N) cin >> weights[i] >> values[i]; vector<vector<ll>> dp(N + 1, vector<ll>(W)); loop(i, 0, W + 1) dp[0][i] = 0; loop(i, 1, N + 1) { loop(j, 1, W + 1) { if (weights[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i] + values[i]]); } } cout << dp[N][W] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define loop(i, a, b) for (int i = a; i < b; ++i) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N, W; cin >> N >> W; vector<ll> weights(N + 1), values(N + 1); loop(i, 1, N + 1) cin >> weights[i] >> values[i]; vector<vector<ll>> dp(N + 1, vector<ll>(W + 1)); loop(i, 0, W + 1) dp[0][i] = 0; loop(i, 1, N + 1) { loop(j, 1, W + 1) { if (weights[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + values[i]); } } cout << dp[N][W] << "\n"; return 0; }
[ "call.arguments.change" ]
966,797
966,798
u158826456
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mem(x, val) memset(x, val, sizeof(x)); int v[105], w[105]; int n; int weight; int dp[105][100005]; ll cal(int pos, int cap) { if (pos >= n) { return 0; } if (dp[pos][cap] != -1) return dp[pos][cap]; ll x = 0, y = 0; if (cap + w[pos] <= weight) { x = cal(pos + 1, cap + w[pos]) + v[pos]; } y = cal(pos + 1, cap); return dp[pos][cap] = max(x, y); } int main() { mem(dp, -1); cin >> n; cin >> weight; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } cout << cal(0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mem(x, val) memset(x, val, sizeof(x)); int v[105], w[105]; int n; int weight; ll dp[105][100005]; ll cal(int pos, int cap) { if (pos >= n) { return 0; } if (dp[pos][cap] != -1) return dp[pos][cap]; ll x = 0, y = 0; if (cap + w[pos] <= weight) { x = cal(pos + 1, cap + w[pos]) + v[pos]; } else x = 0; y = cal(pos + 1, cap); return dp[pos][cap] = max(x, y); } int main() { mem(dp, -1); cin >> n; cin >> weight; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } cout << cal(0, 0) << endl; return 0; }
[ "variable_declaration.type.change", "control_flow.branch.else_if.replace.remove", "control_flow.branch.if.replace.add", "assignment.add" ]
966,799
966,800
u562027277
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 #define rep(i, a, b) for (ll i = a; i < b; i++) #define repc(i, a, b, c) \ for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c) #define mp make_pair #define pb push_back #define all(name) (name.begin(), name.end()) #define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod); #define mod_in(a) power(a, mod - 2) #define ncr(n, r) ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) #define deb(x) cout << #x << " " << x << endl; ll dp[105][100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { ll n, wt; cin >> n >> wt; ll val[n + 5], w[n + 5]; rep(i, 1, n + 1) cin >> w[i] >> val[i]; rep(i, 1, n + 1) { rep(j, 1, wt + 1) { if (j >= w[i]) dp[i][j] = max(dp[i - 1][wt - w[i]] + val[i], dp[i - 1][wt]); else dp[i][j] = dp[i - 1][wt]; } } cout << dp[n][wt]; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 #define rep(i, a, b) for (ll i = a; i < b; i++) #define repc(i, a, b, c) \ for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c) #define mp make_pair #define pb push_back #define all(name) (name.begin(), name.end()) #define fact(n) rep(i, 1, n + 1) ft.pb((ft[i - 1] * i) % mod); #define mod_in(a) power(a, mod - 2) #define ncr(n, r) ((ft[n] * mod_in((ft[r] * ft[(n) - (r)]) % mod)) % mod) #define deb(x) cout << #x << " " << x << endl; ll dp[105][100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { ll n, wt; cin >> n >> wt; ll val[n + 5], w[n + 5]; rep(i, 1, n + 1) cin >> w[i] >> val[i]; rep(i, 1, n + 1) { rep(j, 1, wt + 1) { if (j >= w[i]) dp[i][j] = max(dp[i - 1][j - w[i]] + val[i], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][wt]; } }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
966,801
966,802
u202796595
cpp
p03163
#include <bits/stdc++.h> using namespace std; int n; long long valor[105]; long long peso[105]; long long dp[105000][1060]; int p; long long pd(long long id, long long aguenta) { if (dp[id][aguenta] != -1) { return dp[id][aguenta]; } if (id == n or !aguenta) { return dp[id][aguenta] = 0; } long long nao_pega = pd(id + 1, aguenta); if (peso[id] <= aguenta) { long long pega = valor[id] + pd(id + 1, aguenta - peso[id]); return dp[id][aguenta] = max(pega, nao_pega); } return dp[id][aguenta] = nao_pega; } int main() { cin >> n; cin >> p; for (int i = 0; i < n; i++) { cin >> peso[i]; cin >> valor[i]; } memset(dp, -1, sizeof(dp)); cout << pd(0, p); return 0; }
#include <bits/stdc++.h> using namespace std; int n; long long valor[105]; long long peso[105]; long long dp[105][106000]; int p; long long pd(long long id, long long aguenta) { if (dp[id][aguenta] != -1) { return dp[id][aguenta]; } if (id == n or !aguenta) { return dp[id][aguenta] = 0; } long long nao_pega = pd(id + 1, aguenta); if (peso[id] <= aguenta) { long long pega = valor[id] + pd(id + 1, aguenta - peso[id]); return dp[id][aguenta] = max(pega, nao_pega); } return dp[id][aguenta] = nao_pega; } int main() { cin >> n; cin >> p; for (int i = 0; i < n; i++) { cin >> peso[i]; cin >> valor[i]; } memset(dp, -1, sizeof(dp)); cout << pd(0, p); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
966,803
966,804
u557463467
cpp
p03163
/* */ // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define LSOne(S) (S & (-S)) #define EPS 1e-9 typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pd; typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; int main() { std::ios::sync_with_stdio(false); cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS int n, limit; cin >> n >> limit; vector<int> w(n + 5), val(n + 5); for (int i = 0; i < n; ++i) { cin >> w[i] >> val[i]; } vector<int> dp(limit + 5); for (int i = 0; i < n; ++i) { for (int j = limit; j >= w[i]; --j) { dp[j] = max(dp[j], dp[j - w[i]] + val[i]); } } cout << dp[limit] << "\n"; return 0; }
/* */ // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define LSOne(S) (S & (-S)) #define EPS 1e-9 typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pd; typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset; int main() { std::ios::sync_with_stdio(false); cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS int n, limit; cin >> n >> limit; vector<int> w(n + 5), val(n + 5); for (int i = 0; i < n; ++i) { cin >> w[i] >> val[i]; } vector<ll> dp(limit + 5); for (int i = 0; i < n; ++i) { for (int j = limit; j >= w[i]; --j) { dp[j] = max(dp[j], dp[j - w[i]] + val[i]); } } cout << dp[limit] << "\n"; return 0; }
[]
966,809
966,810
u378221363
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define fore(i, a, b) for (int i = a; i < b; i++) #define maxe(a, b, c) max(a, max(b, c)) #define pb push_back #define eb emplace_back #define em emplace #define print(x) cout << x << endl; typedef long long ll; const int mod = 1e9 + 7; int main() { fastio; int n, w; cin >> n >> w; int table[n + 1][w + 1]; int wt[n], v[n]; fore(i, 0, n) cin >> wt[i] >> v[i]; fore(i, 0, n + 1) { fore(j, 0, w + 1) { if (i == 0 || j == 0) table[i][j] = 0; else if (j >= wt[i - 1]) table[i][j] = max(table[i - 1][j], v[i - 1] + table[i - 1][j - wt[i - 1]]); else table[i][j] = table[i - 1][j]; } } cout << table[n][w]; return 0; }
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define fore(i, a, b) for (int i = a; i < b; i++) #define maxe(a, b, c) max(a, max(b, c)) #define pb push_back #define eb emplace_back #define em emplace #define print(x) cout << x << endl; typedef long long ll; const int mod = 1e9 + 7; int main() { fastio; int n, w; cin >> n >> w; ll table[n + 1][w + 1]; int wt[n], v[n]; fore(i, 0, n) cin >> wt[i] >> v[i]; fore(i, 0, n + 1) { fore(j, 0, w + 1) { if (i == 0 || j == 0) table[i][j] = 0; else if (j >= wt[i - 1]) table[i][j] = max(table[i - 1][j], v[i - 1] + table[i - 1][j - wt[i - 1]]); else table[i][j] = table[i - 1][j]; } } cout << table[n][w]; return 0; }
[ "variable_declaration.type.change" ]
966,817
966,818
u719855312
cpp
p03163
#include <bits/stdc++.h> using namespace std; class Knapsack { public: vector<vector<long long>> dp; int solve(vector<long long> &val, vector<long long> &wt, int item, int capacity) { if (item <= 0 || capacity <= 0) return 0; if (dp[item][capacity] != -1) return dp[item][capacity]; int itemCurr = item - 1; int lastMax = solve(val, wt, item - 1, capacity); int currMax = 0; if (wt[itemCurr] <= capacity) { currMax = val[itemCurr] + solve(val, wt, item - 1, capacity - wt[itemCurr]); } dp[item][capacity] = max(lastMax, currMax); return dp[item][capacity]; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; int w_i, n_i; if (n == 1) { cin >> w_i >> n_i; if (w_i <= w) { cout << n_i << endl; } else { cout << 0 << endl; } return 0; } vector<long long> val; vector<long long> wt; val.reserve(n); wt.reserve(n); for (int i = 0; i < n; ++i) { cin >> w_i >> n_i; wt.push_back(w_i); val.push_back(n_i); } Knapsack ks; ks.dp.resize(n + 1, vector<long long>(w + 1, -1)); cout << ks.solve(val, wt, n, w) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; class Knapsack { public: vector<vector<long long>> dp; long long solve(vector<long long> &val, vector<long long> &wt, int item, int capacity) { if (item <= 0 || capacity <= 0) return 0; if (dp[item][capacity] != -1) return dp[item][capacity]; int itemCurr = item - 1; long long lastMax = solve(val, wt, item - 1, capacity); long long currMax = 0; if (wt[itemCurr] <= capacity) { currMax = val[itemCurr] + solve(val, wt, item - 1, capacity - wt[itemCurr]); } dp[item][capacity] = max(lastMax, currMax); return dp[item][capacity]; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; int w_i, n_i; if (n == 1) { cin >> w_i >> n_i; if (w_i <= w) { cout << n_i << endl; } else { cout << 0 << endl; } return 0; } vector<long long> val; vector<long long> wt; val.reserve(n); wt.reserve(n); for (int i = 0; i < n; ++i) { cin >> w_i >> n_i; wt.push_back(w_i); val.push_back(n_i); } Knapsack ks; ks.dp.resize(n + 1, vector<long long>(w + 1, -1)); cout << ks.solve(val, wt, n, w) << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,819
966,820
u192061265
cpp
p03163
#include <bits/stdc++.h> #define int ll #define D(x) cout << "D: " << #x << '=' << x << endl; #define R(x, l) \ cout << "R: Array " << #x << endl; \ for (int i = 0; i < l; i++) \ cout << ' ' << i << ':' << *(x + i) << endl; #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; template <typename tn> inline tn next(void); template <typename tn> inline ostream &operator<<(ostream &os, const vector<tn> &v); int w[105], p[105], dp[105]; signed main(void) { ios::sync_with_stdio(false); cin.tie(0); int a, b; cin >> a >> b; for (int i = 0; i < a; i++) cin >> w[i] >> p[i]; for (int i = 0; i < a; i++) for (int j = b; j >= p[i]; j--) dp[j] = max(dp[j], dp[j - w[i]] + p[i]); cout << dp[b] << endl; return ~~(0 - 0); } template <typename tn> inline tn next(void) { tn k; cin >> k; return k; } template <typename tn> inline ostream &operator<<(ostream &os, const vector<tn> &v) { for (unsigned i = 0; i < v.size(); i++) os << v[i] << ' '; return os; }
#include <bits/stdc++.h> #define int ll #define D(x) cout << "D: " << #x << '=' << x << endl; #define R(x, l) \ cout << "R: Array " << #x << endl; \ for (int i = 0; i < l; i++) \ cout << ' ' << i << ':' << *(x + i) << endl; #define pb push_back using namespace std; typedef long long ll; typedef pair<int, int> pii; template <typename tn> inline tn next(void); template <typename tn> inline ostream &operator<<(ostream &os, const vector<tn> &v); int w[105], p[105], dp[100500]; signed main(void) { ios::sync_with_stdio(false); cin.tie(0); int a, b; cin >> a >> b; for (int i = 0; i < a; i++) cin >> w[i] >> p[i]; for (int i = 0; i < a; i++) for (int j = b; j >= w[i]; j--) dp[j] = max(dp[j], dp[j - w[i]] + p[i]); cout << dp[b] << endl; return ~~(0 - 0); } template <typename tn> inline tn next(void) { tn k; cin >> k; return k; } template <typename tn> inline ostream &operator<<(ostream &os, const vector<tn> &v) { for (unsigned i = 0; i < v.size(); i++) os << v[i] << ' '; return os; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
966,826
966,825
u313129279
cpp
p03163
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #define pii pair<int, int> #define pll pair<long long, long long> #define vi vector<int> #define ll long long #define pb push_back #define ff first #define ss second #define rep(n) for (int i = 0; i < n; i++) #define input(n) \ for (int i = 0; i < n; i++) { \ cin >> arr[i]; \ } #define output(n) \ for (int i = 0; i < n; i++) { \ cout << arr[i] << " "; \ } #define tc \ int t; \ cin >> t; \ while (t--) using namespace std; int32_t main() { int n; cin >> n; int w; cin >> w; int weight[n]; int value[n]; rep(n) { cin >> weight[i]; cin >> value[i]; } int dp[n + 1][w + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (j >= weight[i - 1]) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #define pii pair<int, int> #define pll pair<long long, long long> #define vi vector<int> #define ll long long #define pb push_back #define ff first #define ss second #define rep(n) for (int i = 0; i < n; i++) #define input(n) \ for (int i = 0; i < n; i++) { \ cin >> arr[i]; \ } #define output(n) \ for (int i = 0; i < n; i++) { \ cout << arr[i] << " "; \ } #define tc \ int t; \ cin >> t; \ while (t--) using namespace std; int32_t main() { int n; cin >> n; int w; cin >> w; long long int weight[n]; long long int value[n]; rep(n) { cin >> weight[i]; cin >> value[i]; } long long int dp[n + 1][w + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (j >= weight[i - 1]) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
966,831
966,832
u809582239
cpp
p03163
#include <bits/stdc++.h> using namespace std; int n, w, dp[100001], maxi; int main() { cin >> n >> w; for (int i = 0; i < n; i += 1) { int a, b; cin >> a >> b; for (int j = w; j >= a; j -= 1) { dp[j] = max(dp[j], dp[j - a] + b); maxi = max(maxi, dp[j]); } } cout << maxi << endl; }
#include <bits/stdc++.h> using namespace std; long long n, w, dp[100001], maxi; int main() { cin >> n >> w; for (int i = 0; i < n; i += 1) { int a, b; cin >> a >> b; for (int j = w; j >= a; j -= 1) { dp[j] = max(dp[j], dp[j - a] + b); maxi = max(maxi, dp[j]); } } cout << maxi << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,835
966,836
u689442090
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n, c, i, j; cin >> n; cin >> c; vector<int> w(n + 1); vector<int> v(n + 1); vector<vector<int>> kp(n + 1, vector<int>(c + 1)); kp[0] = vector<int>(c + 1, 0); for (i = 1; i < n + 1; i++) kp[i][0] = 0; w[0] = 0; v[0] = 0; for (i = 1; i < n + 1; i++) { cin >> w[i]; cin >> v[i]; } for (i = 1; i < n + 1; i++) { for (j = 1; j < c + 1; j++) { if (w[i] > j) kp[i][j] = kp[i - 1][j]; else { kp[i][j] = max(kp[i - 1][j], kp[i - 1][j - w[i]] + v[i]); } } } cout << kp[n][c]; }
#include <bits/stdc++.h> using namespace std; int main() { int n, c, i, j; cin >> n; cin >> c; vector<int> w(n + 1); vector<long int> v(n + 1); vector<vector<long int>> kp(n + 1, vector<long int>(c + 1)); kp[0] = vector<long int>(c + 1, 0); for (i = 1; i < n + 1; i++) kp[i][0] = 0; w[0] = 0; v[0] = 0; for (i = 1; i < n + 1; i++) { cin >> w[i]; cin >> v[i]; } for (i = 1; i < n + 1; i++) { for (j = 1; j < c + 1; j++) { if (w[i] > j) kp[i][j] = kp[i - 1][j]; else { kp[i][j] = max(kp[i - 1][j], kp[i - 1][j - w[i]] + v[i]); } } } cout << kp[n][c]; }
[ "variable_declaration.type.widen.change" ]
966,837
966,838
u596879772
cpp
p03163
#include <bits/stdc++.h> #define int long long #define rep(i, a, b) for (int i = a; i < b; i += 1) #define vi vector<int> using namespace std; int helper(int n, int w, int *weights, int *values) { int ans[2][w + 1]; rep(i, 0, w + 1) ans[0][i] = 0; int res = 1; rep(i, 1, n + 1) { rep(j, 0, w + 1) { if (weights[i - 1] <= w) ans[res][j] = max(values[i - 1] + ans[res ^ 1][w - weights[i - 1]], ans[res ^ 1][j]); else ans[res][j] = ans[res ^ 1][j]; } res = res ^ 1; } return ans[res ^ 1][w]; } int32_t main(void) { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, w; cin >> n >> w; int *weights = new int[n]; int *values = new int[n]; rep(i, 0, n) cin >> weights[i] >> values[i]; cout << helper(n, w, weights, values) << endl; delete[] weights; delete[] values; }
#include <bits/stdc++.h> #define int long long #define rep(i, a, b) for (int i = a; i < b; i += 1) #define vi vector<int> using namespace std; int helper(int n, int w, int *weights, int *values) { int ans[2][w + 1]; rep(i, 0, w + 1) ans[0][i] = 0; int res = 1; rep(i, 1, n + 1) { rep(j, 0, w + 1) { if (weights[i - 1] <= j) ans[res][j] = max(values[i - 1] + ans[res ^ 1][j - weights[i - 1]], ans[res ^ 1][j]); else ans[res][j] = ans[res ^ 1][j]; } res = res ^ 1; } return ans[res ^ 1][w]; } int32_t main(void) { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, w; cin >> n >> w; int *weights = new int[n]; int *values = new int[n]; rep(i, 0, n) cin >> weights[i] >> values[i]; cout << helper(n, w, weights, values) << endl; delete[] weights; delete[] values; }
[ "identifier.change", "control_flow.branch.if.condition.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
966,847
966,848
u547231875
cpp
p03163
// youngjinp20 // 2020 03 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 100; int N, W; int w[MAX]; int v[MAX]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } int dp[W + 1] = {0}; for (int j = 0; j < N; j++) { for (int i = W; i > 0; i--) { if (i >= w[j]) { dp[i] = max(dp[i - w[j]] + v[j], dp[i]); } } } cout << dp[W]; return 0; }
// youngjinp20 // 2020 03 #include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAX = 100; int N, W; int w[MAX]; int v[MAX]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } ll dp[W + 1] = {0}; for (int j = 0; j < N; j++) { for (int i = W; i > 0; i--) { if (i >= w[j]) { dp[i] = max(dp[i - w[j]] + v[j], dp[i]); } } } cout << dp[W]; return 0; }
[ "variable_declaration.type.change" ]
966,849
966,850
u688683948
cpp
p03163
/* _ __ _ _ _ ____ _____ | |/ / / \ | | | / ___|_ _| | ' / / _ \| | | \___ \ | | | . \ / ___ \ |_| |___) || | |_|\_\/_/ \_\___/|____/ |_| */ #include <bits/stdc++.h> #include <fstream> #define rep(i, a, b) for (long long i = (a); i < (b); i++) #define per(i, a, b) for (long long i = (a); i > (b); i--) #define a(x) (x.begin(), x.end()) #define ar(x) (x.rbegin(), x.rend()) #define pb push_back #define Pb() pop_back() #define ll long long int #define ull unsigned long long int #define pii pair<int, int> #define pll pair<ll, ll> #define sc scanf #define scin(x) sc("%d", &(x)) #define scln(x) sc("%lld", &(x)) #define pf prllf #define ms(a, b) memset(a, b, sizeof(a)) #define mp make_pair #define db double #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x) * (x) #define vi vector<int> #define vl vector<ll> #define vii vector<vector<int>> #define vll vector<vector<ll>> #define DBG pf("HI\n") #define MOD 1000000007 #define CIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++) #define CASE(t) prllf("Case %d: ", t) #define CASEL(t) prllf("Case %d:\n", t) #define intlimit 2147483647 #define longlimit 9223372036854775807 #define infinity (1 << 28) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a) * (b) / gcd(a, b)) #define PI 2 * acos(0.0) using namespace std; int main() { CIN; int n, k; cin >> n >> k; vi v(n), v1(n); rep(i, 0, n) { cin >> v[i] >> v1[i]; } int dp[n + 1][k + 1]; rep(i, 0, n + 1) { rep(j, 0, k + 1) { dp[i][j] = -1; } } dp[0][0] = 0; int maxi = 0; rep(i, 0, n) { rep(j, 0, k + 1) { if (dp[i][j] == -1) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if (j + v[i] <= k) dp[i + 1][j + v[i]] = max(dp[i + 1][j + v[i]], dp[i][j] + v1[i]); } } rep(i, 0, k + 1) { maxi = max(maxi, dp[n][i]); } cout << maxi; }
/* _ __ _ _ _ ____ _____ | |/ / / \ | | | / ___|_ _| | ' / / _ \| | | \___ \ | | | . \ / ___ \ |_| |___) || | |_|\_\/_/ \_\___/|____/ |_| */ #include <bits/stdc++.h> #include <fstream> #define rep(i, a, b) for (long long i = (a); i < (b); i++) #define per(i, a, b) for (long long i = (a); i > (b); i--) #define a(x) (x.begin(), x.end()) #define ar(x) (x.rbegin(), x.rend()) #define pb push_back #define Pb() pop_back() #define ll long long int #define ull unsigned long long int #define pii pair<int, int> #define pll pair<ll, ll> #define sc scanf #define scin(x) sc("%d", &(x)) #define scln(x) sc("%lld", &(x)) #define pf prllf #define ms(a, b) memset(a, b, sizeof(a)) #define mp make_pair #define db double #define EPS 10E-10 #define ff first #define ss second #define sqr(x) (x) * (x) #define vi vector<int> #define vl vector<ll> #define vii vector<vector<int>> #define vll vector<vector<ll>> #define DBG pf("HI\n") #define MOD 1000000007 #define CIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++) #define CASE(t) prllf("Case %d: ", t) #define CASEL(t) prllf("Case %d:\n", t) #define intlimit 2147483647 #define longlimit 9223372036854775807 #define infinity (1 << 28) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a) * (b) / gcd(a, b)) #define PI 2 * acos(0.0) using namespace std; int main() { CIN; int n, k; cin >> n >> k; vl v(n), v1(n); rep(i, 0, n) { cin >> v[i] >> v1[i]; } ll dp[n + 1][k + 1]; rep(i, 0, n + 1) { rep(j, 0, k + 1) { dp[i][j] = -1; } } dp[0][0] = 0; ll maxi = 0; rep(i, 0, n) { rep(j, 0, k + 1) { if (dp[i][j] == -1) continue; dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if (j + v[i] <= k) dp[i + 1][j + v[i]] = max(dp[i + 1][j + v[i]], dp[i][j] + v1[i]); } } rep(i, 0, k + 1) { maxi = max(maxi, dp[n][i]); } cout << maxi; }
[ "variable_declaration.type.change" ]
966,851
966,852
u054759548
cpp
p03163
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- #include <bits/stdc++.h> #define ll long long using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> //lower_bound , upper_bound // using namespace __gnu_pbds;//kth smallest : *pd.find_by_order(k-1) , no. of // elem < X : pd.order_of_key(X) , delete X : pd.erase(X). typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define f(i, a, b) for (ll i = a; i < b; i++) #define fb(i, a, b) for (ll i = a; i >= b; i--) #define pb push_back #define mp make_pair #define ff first #define ss second #define nl '\n' #define pl pair<ll, ll> #define all(v) v.begin(), v.end() const ll mod = (1e+9) + 7; const ll sz = 2e5 + 9; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll m = mod) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; b = b >> 1; a = (a * a) % m; } return res; } void solve() { ll tt = 1, n; cin >> tt; while (tt--) { ll cap; cin >> n >> cap; vector<ll> wt(n), val(n); f(i, 0, n) { cin >> wt[i] >> val[i]; } ll ans[n + 1][cap + 1]; f(i, 0, n + 1) { f(w, 0, cap + 1) { if (i == 0 || w == 0) ans[i][w] = 0; else if (wt[i - 1] <= w) ans[i][w] = max(val[i - 1] + ans[i - 1][w - wt[i - 1]], ans[i - 1][w]); else ans[i][w] = ans[i - 1][w]; } } cout << ans[n][cap] << nl; } } int main() { #ifdef JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec, Copyright %c 2019 PyThor. \n", double(end - beg) / CLOCKS_PER_SEC, 184); return 0; }
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- #include <bits/stdc++.h> #define ll long long using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> //lower_bound , upper_bound // using namespace __gnu_pbds;//kth smallest : *pd.find_by_order(k-1) , no. of // elem < X : pd.order_of_key(X) , delete X : pd.erase(X). typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define f(i, a, b) for (ll i = a; i < b; i++) #define fb(i, a, b) for (ll i = a; i >= b; i--) #define pb push_back #define mp make_pair #define ff first #define ss second #define nl '\n' #define pl pair<ll, ll> #define all(v) v.begin(), v.end() const ll mod = (1e+9) + 7; const ll sz = 2e5 + 9; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll m = mod) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; b = b >> 1; a = (a * a) % m; } return res; } void solve() { ll tt = 1, n; // cin>>tt; while (tt--) { ll cap; cin >> n >> cap; vector<ll> wt(n), val(n); f(i, 0, n) { cin >> wt[i] >> val[i]; } ll ans[n + 1][cap + 1]; f(i, 0, n + 1) { f(w, 0, cap + 1) { if (i == 0 || w == 0) ans[i][w] = 0; else if (wt[i - 1] <= w) ans[i][w] = max(val[i - 1] + ans[i - 1][w - wt[i - 1]], ans[i - 1][w]); else ans[i][w] = ans[i - 1][w]; } } cout << ans[n][cap] << nl; } } int main() { #ifdef JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec, Copyright %c 2019 PyThor. \n", double(end - beg) / CLOCKS_PER_SEC, 184); return 0; }
[]
966,857
966,858
u307290797
cpp
p03163
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- #include <bits/stdc++.h> #define ll long long using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> //lower_bound , upper_bound // using namespace __gnu_pbds;//kth smallest : *pd.find_by_order(k-1) , no. of // elem < X : pd.order_of_key(X) , delete X : pd.erase(X). typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define f(i, a, b) for (ll i = a; i < b; i++) #define fb(i, a, b) for (ll i = a; i >= b; i--) #define pb push_back #define mp make_pair #define ff first #define ss second #define nl '\n' #define pl pair<ll, ll> #define all(v) v.begin(), v.end() const ll mod = (1e+9) + 7; const ll sz = 2e5 + 9; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll m = mod) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; b = b >> 1; a = (a * a) % m; } return res; } void solve() { ll tt = 1, n; // cin>>tt; while (tt--) { ll cap; cin >> cap >> n; vector<ll> wt(n), val(n); f(i, 0, n) { cin >> wt[i] >> val[i]; } ll ans[n + 1][cap + 1]; f(i, 0, n + 1) { f(w, 0, cap + 1) { if (i == 0 || w == 0) ans[i][w] = 0; else if (wt[i - 1] <= w) ans[i][w] = max(val[i - 1] + ans[i - 1][w - wt[i - 1]], ans[i - 1][w]); else ans[i][w] = ans[i - 1][w]; } } cout << ans[n][cap] << nl; } } int main() { #ifdef JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec, Copyright %c 2019 PyThor. \n", double(end - beg) / CLOCKS_PER_SEC, 184); return 0; }
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- #include <bits/stdc++.h> #define ll long long using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> //lower_bound , upper_bound // using namespace __gnu_pbds;//kth smallest : *pd.find_by_order(k-1) , no. of // elem < X : pd.order_of_key(X) , delete X : pd.erase(X). typedef tree<ll, // null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define f(i, a, b) for (ll i = a; i < b; i++) #define fb(i, a, b) for (ll i = a; i >= b; i--) #define pb push_back #define mp make_pair #define ff first #define ss second #define nl '\n' #define pl pair<ll, ll> #define all(v) v.begin(), v.end() const ll mod = (1e+9) + 7; const ll sz = 2e5 + 9; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll power(ll a, ll b, ll m = mod) { ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % m; b = b >> 1; a = (a * a) % m; } return res; } void solve() { ll tt = 1, n; // cin>>tt; while (tt--) { ll cap; cin >> n >> cap; vector<ll> wt(n), val(n); f(i, 0, n) { cin >> wt[i] >> val[i]; } ll ans[n + 1][cap + 1]; f(i, 0, n + 1) { f(w, 0, cap + 1) { if (i == 0 || w == 0) ans[i][w] = 0; else if (wt[i - 1] <= w) ans[i][w] = max(val[i - 1] + ans[i - 1][w - wt[i - 1]], ans[i - 1][w]); else ans[i][w] = ans[i - 1][w]; } } cout << ans[n][cap] << nl; } } int main() { #ifdef JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t beg = clock(); solve(); clock_t end = clock(); fprintf(stderr, "%.3f sec, Copyright %c 2019 PyThor. \n", double(end - beg) / CLOCKS_PER_SEC, 184); return 0; }
[ "expression.operation.binary.remove" ]
966,859
966,858
u307290797
cpp
p03163
#include <algorithm> #include <iostream> #include <vector> #define lli long long int #define endl "\n" #define whats(x) cout << #x << " is: " << x << endl; using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; lli weights[n + 1]; lli values[n + 1]; lli dp[n + 1][w + 1]; for (int i = 1; i <= n; ++i) { cin >> weights[i]; cin >> values[i]; } for (int i = 0; i <= n; ++i) dp[0][i] = 0; // have no item to take for (int i = 0; i <= n; ++i) dp[i][0] = 0; // max available weight 0, can't include anything for (int i = 1; i <= n; ++i) { for (int j = 1; j <= w; ++j) { // max(include,not include) if (j >= weights[i]) { dp[i][j] = max(values[i] + dp[i - 1][j - weights[i]], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #define lli long long int #define endl "\n" #define whats(x) cout << #x << " is: " << x << endl; using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; lli weights[n + 1]; lli values[n + 1]; lli dp[n + 1][w + 1]; for (int i = 1; i <= n; ++i) { cin >> weights[i]; cin >> values[i]; } for (int i = 0; i <= w; ++i) dp[0][i] = 0; // have no item to take for (int i = 0; i <= n; ++i) dp[i][0] = 0; // max available weight 0, can't include anything for (int i = 1; i <= n; ++i) { for (int j = 1; j <= w; ++j) { // max(include,not include) if (j >= weights[i]) { dp[i][j] = max(values[i] + dp[i - 1][j - weights[i]], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << endl; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
966,867
966,866
u519787311
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long #define loop(i, a, b) for (int i = a; i < b; ++i) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N, W; cin >> N >> W; vector<ll> weights(N + 1), values(N + 1); for (int i = 1; i <= N; ++i) cin >> weights[i] >> values[i]; vector<vector<ll>> dp(N + 1, vector<ll>(W + 1)); for (int i = 0; i <= W; ++i) dp[0][i] = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; i <= W; ++j) { if (weights[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + values[i]); } } cout << dp[N][W] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define loop(i, a, b) for (int i = a; i < b; ++i) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N, W; cin >> N >> W; vector<ll> weights(N + 1), values(N + 1); for (int i = 1; i <= N; ++i) cin >> weights[i] >> values[i]; vector<vector<ll>> dp(N + 1, vector<ll>(W + 1)); for (int i = 0; i <= W; ++i) dp[0][i] = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= W; ++j) { if (weights[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + values[i]); } } cout << dp[N][W] << "\n"; return 0; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
966,868
966,869
u212258177
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define MAX_N 101 #define MAX_W 100001 int N, W; long long Lookup[MAX_N][MAX_W]; int wei[MAX_N]; long long val[MAX_N]; long long Knapsack(int c, int n) { if (W == 0 || n == 0) return 0; if (Lookup[n][c] != -1) return Lookup[n][c]; if (W - wei[n] >= 0) return Lookup[n][c] = max(Knapsack(c - wei[n], n - 1) + val[n], Knapsack(c, n - 1)); return Knapsack(c, n - 1); } void fillDp() { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_W; j++) Lookup[i][j] = -1; } } int main(int argc, char **argv) { cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> wei[i] >> val[i]; } fillDp(); cout << Knapsack(W, N) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MAX_N 101 #define MAX_W 100001 int N, W; long long Lookup[MAX_N][MAX_W]; int wei[MAX_N]; long long val[MAX_N]; long long Knapsack(int c, int n) { if (c == 0 || n == 0) return 0; if (Lookup[n][c] != -1) return Lookup[n][c]; if (c - wei[n] >= 0) return Lookup[n][c] = max(Knapsack(c - wei[n], n - 1) + val[n], Knapsack(c, n - 1)); return Knapsack(c, n - 1); } void fillDp() { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_W; j++) Lookup[i][j] = -1; } } int main(int argc, char **argv) { cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> wei[i] >> val[i]; } fillDp(); cout << Knapsack(W, N) << endl; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
966,870
966,871
u212258177
cpp
p03163
// A Dynamic Programming based solution for 0-1 Knapsack problem #include <bits/stdc++.h> using namespace std; int max(int a, int b) { return (a > b) ? a : b; } double K[102][100005]; // Returns the maximum value that can be put in a knapsack of capacity W int knapSack(int W, int wt[], int val[], int n) { int i, w; // Build table K[][] in bottom up manner for (i = 0; i <= n; i++) { for (w = 0; w <= W; w++) { if (i == 0 || w == 0) K[i][w] = 0; else if (wt[i - 1] <= w) K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]); else K[i][w] = K[i - 1][w]; } } return K[n][W]; } int main() { int n, w; cin >> n >> w; int a[n + 1], b[w + 1]; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; knapSack(w, a, b, n); cout << K[n][w]; return 0; }
// A Dynamic Programming based solution for 0-1 Knapsack problem #include <bits/stdc++.h> using namespace std; int max(int a, int b) { return (a > b) ? a : b; } long int K[102][100005]; // Returns the maximum value that can be put in a knapsack of capacity W int knapSack(int W, int wt[], int val[], int n) { int i, w; // Build table K[][] in bottom up manner for (i = 0; i <= n; i++) { for (w = 0; w <= W; w++) { if (i == 0 || w == 0) K[i][w] = 0; else if (wt[i - 1] <= w) K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w]); else K[i][w] = K[i - 1][w]; } } return K[n][W]; } int main() { int n, w; cin >> n >> w; int a[n + 1], b[w + 1]; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; knapSack(w, a, b, n); cout << K[n][w]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,872
966,873
u431571098
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long bool compare(const pair<int, int> &a, const pair<int, int> &b) { return (a.second > b.second); } int findmax(int arr[], int n) { int curr_max = -1; for (int i = 0; i < n; i++) { curr_max = max(curr_max, arr[i]); } return curr_max; } int findmin(int arr[], int n) { int curr_max = INT_MAX; for (int i = 0; i < n; i++) { curr_max = min(curr_max, arr[i]); } return curr_max; } bool help(int arr[], int mid, int n, int c) { int last_pos = arr[0]; int cows = 1; for (int i = 0; i < n; i++) { if (abs(arr[i] - last_pos) >= mid) { last_pos = arr[i]; if (++cows == c) return true; last_pos = arr[i]; } } return false; } int main() { ll t; t = 1; while (t--) { ll n, W; cin >> n >> W; int wt[n + 1], val[n + 1]; for (int i = 0; i < n; i++) cin >> wt[i] >> val[i]; int dp[n + 1][W + 1]; for (int i = 0; i <= n; i++) { for (int w = 0; w <= W; w++) { if (i == 0 or w == 0) dp[i][w] = 0; else if (wt[i - 1] <= w) { dp[i][w] = max(val[i - 1] + dp[i - 1][w - wt[i - 1]], dp[i - 1][w]); } else { dp[i][w] = dp[i - 1][w]; } } } cout << dp[n][W]; } }
#include <bits/stdc++.h> using namespace std; #define ll long long bool compare(const pair<int, int> &a, const pair<int, int> &b) { return (a.second > b.second); } int findmax(int arr[], int n) { int curr_max = -1; for (int i = 0; i < n; i++) { curr_max = max(curr_max, arr[i]); } return curr_max; } int findmin(int arr[], int n) { int curr_max = INT_MAX; for (int i = 0; i < n; i++) { curr_max = min(curr_max, arr[i]); } return curr_max; } bool help(int arr[], int mid, int n, int c) { int last_pos = arr[0]; int cows = 1; for (int i = 0; i < n; i++) { if (abs(arr[i] - last_pos) >= mid) { last_pos = arr[i]; if (++cows == c) return true; last_pos = arr[i]; } } return false; } int main() { ll t; t = 1; while (t--) { ll n, W; cin >> n >> W; ll wt[n], val[n]; for (int i = 0; i < n; i++) cin >> wt[i] >> val[i]; ll dp[n + 1][W + 1]; for (int i = 0; i <= n; i++) { for (int w = 0; w <= W; w++) { if (i == 0 or w == 0) dp[i][w] = 0; else if (wt[i - 1] <= w) { dp[i][w] = max(val[i - 1] + dp[i - 1][w - wt[i - 1]], dp[i - 1][w]); } else { dp[i][w] = dp[i - 1][w]; } } } cout << dp[n][W]; } }
[ "variable_declaration.type.change", "expression.operation.binary.remove" ]
966,874
966,875
u058292044
cpp
p03163
#include <bits/stdc++.h> #define ll long long int #define maxy __LONG_LONG_MAX__ #define mod 1000000007 using namespace std; int main() { ll n, w; cin >> n >> w; int wt[n], val[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } int v[n + 1][w + 1]; for (int i = 0; i <= n; i++) { v[i][0] = 0; } for (int i = 0; i <= w; i++) { v[0][i] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (wt[i - 1] <= j) { v[i][j] = max(v[i - 1][j], val[i - 1] + v[i - 1][j - wt[i - 1]]); } else { v[i][j] = v[i - 1][j]; } } } cout << v[n][n]; return 0; }
#include <bits/stdc++.h> #define ll long long int #define maxy __LONG_LONG_MAX__ #define mod 1000000007 using namespace std; int main() { ll n, w; cin >> n >> w; ll wt[n], val[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } ll v[n + 1][w + 1]; for (int i = 0; i <= n; i++) { v[i][0] = 0; } for (int i = 0; i <= w; i++) { v[0][i] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (wt[i - 1] <= j) { v[i][j] = max(v[i - 1][j], val[i - 1] + v[i - 1][j - wt[i - 1]]); } else { v[i][j] = v[i - 1][j]; } } } cout << v[n][w]; return 0; }
[ "variable_declaration.type.change", "identifier.change", "variable_access.subscript.index.change", "io.output.change" ]
966,876
966,877
u521434647
cpp
p03163
#include <iostream> using namespace std; long long dp[110][100010]; int main() { int n, m; int v[110], w[110]; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = dp[i - 1][j]; if (w[i] <= j) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } cout << dp[n][m]; }
#include <iostream> using namespace std; long long dp[110][100010]; int main() { int n, m; int v[110], w[110]; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] = dp[i - 1][j]; if (w[i] <= j) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } cout << dp[n][m]; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
966,878
966,879
u987727193
cpp
p03163
#include <iostream> #include <math.h> using namespace std; int dp[100010][110]; main() { int n, m, v[1500], w[1500]; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 1; i <= m; i++) { for (int k = 1; k <= n; k++) { dp[i][k] = dp[i][k - 1]; if (w[k] <= i) dp[i][k] = max(dp[i][k - 1], dp[i - w[k]][k - 1] + v[k]); } } cout << dp[m][n]; }
#include <iostream> #include <math.h> using namespace std; long long dp[100010][110]; main() { int n, m, v[1500], w[1500]; cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 1; i <= m; i++) { for (int k = 1; k <= n; k++) { dp[i][k] = dp[i][k - 1]; if (w[k] <= i) dp[i][k] = max(dp[i][k], dp[i - w[k]][k - 1] + v[k]); } } cout << dp[m][n]; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "expression.operation.binary.remove" ]
966,882
966,883
u787900397
cpp
p03163
/** * Think twice, code once. * 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b) * 2.runtime error * 3.boundary condition * --------------------------------------------------------------------------------------- * Author : zzy * Date : 2020-03-19-18.25.37 Thursday */ #include <bits/stdc++.h> #define eb emplace_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, r, l) for (int i = (r); i >= (l); i--) #define ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) ((int)(x).size()) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const int maxn = (int)1e5 + 1000; int N, W, w[maxn], v[maxn], dp[110][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif cin >> N >> W; for1(i, N) cin >> w[i] >> v[i]; ms(dp, 0); for (int i = 1; i <= N; ++i) { for (int j = 0; j <= W; ++j) { dp[i][j] = dp[i - 1][j]; if (j >= w[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } cout << dp[N][W] << '\n'; #ifdef LOCAL_DEFINE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
/** * Think twice, code once. * 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b) * 2.runtime error * 3.boundary condition * --------------------------------------------------------------------------------------- * Author : zzy * Date : 2020-03-19-18.25.37 Thursday */ #include <bits/stdc++.h> #define eb emplace_back #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, r, l) for (int i = (r); i >= (l); i--) #define ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) ((int)(x).size()) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } const i64 maxn = (i64)1e5 + 1000; i64 N, W, w[maxn], v[maxn], dp[110][maxn]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif cin >> N >> W; for1(i, N) cin >> w[i] >> v[i]; ms(dp, 0); for (int i = 1; i <= N; ++i) { for (int j = 0; j <= W; ++j) { dp[i][j] = dp[i - 1][j]; if (j >= w[i]) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } cout << dp[N][W] << '\n'; #ifdef LOCAL_DEFINE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
[ "variable_declaration.type.change", "expression.operation.binary.change" ]
966,884
966,885
u172885996
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n, w, i, j; cin >> n; cin >> w; int a[n], wt[n], dp[n + 1][w + 1]; for (i = 0; i < n; i++) { cin >> wt[i] >> a[i]; } for (i = 0; i <= n; i++) { for (j = 0; j <= w; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + a[i - 1], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, w, i, j; cin >> n; cin >> w; long long int a[n], wt[n], dp[n + 1][w + 1]; for (i = 0; i < n; i++) { cin >> wt[i] >> a[i]; } for (i = 0; i <= n; i++) { for (j = 0; j <= w; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + a[i - 1], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
966,888
966,889
u100931490
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long #define mod 1000000007 #define do double #define loop(i, n) for (int i = 0; i < n; i++) #define lop(a, b) for (int i = a; i <= b; i++) #define pb push_back #define mkp make_pair typedef vector<int> vi; typedef map<int, int> mii; typedef set<int> si; typedef pair<int, int> pii; typedef unordered_map<int, int> um; typedef unordered_set<int> us; typedef multiset<int> ms; typedef vector<pair<int, int>> vpii; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, W; cin >> n >> W; int wt[n + 1], v[n + 1], K[n + 1][W + 1] = {}; loop(i, n) cin >> wt[i] >> v[i]; for (int i = 0; i <= n; i++) { for (int w = 0; w <= W; w++) { if (i == 0 || w == 0) K[i][w] = 0; else if (wt[i - 1] <= w) K[i][w] = max(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] << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long #define mod 1000000007 #define do double #define loop(i, n) for (int i = 0; i < n; i++) #define lop(a, b) for (int i = a; i <= b; i++) #define pb push_back #define mkp make_pair typedef vector<int> vi; typedef map<int, int> mii; typedef set<int> si; typedef pair<int, int> pii; typedef unordered_map<int, int> um; typedef unordered_set<int> us; typedef multiset<int> ms; typedef vector<pair<int, int>> vpii; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, W; cin >> n >> W; ll wt[n + 1], v[n + 1], K[n + 1][W + 1] = {}; loop(i, n) cin >> wt[i] >> v[i]; for (ll i = 0; i <= n; i++) { for (ll 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] << "\n"; }
[ "variable_declaration.type.change", "control_flow.loop.for.initializer.change" ]
966,896
966,897
u580376304
cpp
p03163
#include <bits/stdc++.h> #define LL long long int #define Max(x, y) (x > y ? x : y) #define Min(x, y) (x < y ? x : y) #define Abs(x) ((x) > 0 ? (x) : -(x)) #define Swap(x, y) \ do { \ x = x ^ y; \ y = x ^ y; \ x = x ^ y; \ } while (0) #define IO_BOOST \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define setp(x) fixed << setprecision(x) #define INF 0x3f3f3f3f #define Lowbit(x) ((x) & (-x)) #define Pii pair<int, int> #define x first #define y second #define MOD ((int)1e9 + 7) using namespace std; struct Node { int w, v; }; Node a[(int)2e5 + 5]; int dp[101][(int)2e5 + 5] = {0}; int n, k, w; void solve() { for (int i = 1; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j >= a[i].w) { dp[i][j] = Max(dp[i - 1][j], dp[i - 1][j - a[i].w] + a[i].v); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << '\n'; } int main() { IO_BOOST; cin >> n >> w; for (int i = 1; i <= n; i++) cin >> a[i].w >> a[i].v; solve(); }
#include <bits/stdc++.h> #define LL long long int #define Max(x, y) (x > y ? x : y) #define Min(x, y) (x < y ? x : y) #define Abs(x) ((x) > 0 ? (x) : -(x)) #define Swap(x, y) \ do { \ x = x ^ y; \ y = x ^ y; \ x = x ^ y; \ } while (0) #define IO_BOOST \ ios_base::sync_with_stdio(false); \ cin.tie(0) #define setp(x) fixed << setprecision(x) #define INF 0x3f3f3f3f #define Lowbit(x) ((x) & (-x)) #define Pii pair<int, int> #define x first #define y second #define MOD ((int)1e9 + 7) using namespace std; struct Node { LL w, v; }; Node a[(int)2e5 + 5]; LL dp[101][(int)2e5 + 5] = {0}; int n, k, w; void solve() { for (int i = 1; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j >= a[i].w) { dp[i][j] = Max(dp[i - 1][j], dp[i - 1][j - a[i].w] + a[i].v); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << '\n'; } int main() { IO_BOOST; cin >> n >> w; for (int i = 1; i <= n; i++) cin >> a[i].w >> a[i].v; solve(); }
[ "variable_declaration.type.change" ]
966,898
966,899
u369631563
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100; const int CAP = 1e5 + 10; int n, cap; int v[N], w[N]; ll dp[N][CAP]; ll run(int idx, int cur) { if (dp[idx][cur] != -1) return dp[idx][cur]; ll res = 0; if (idx == n or cur == 0) res = 0; else if (w[idx] > cur) res = run(idx + 1, cur); else res = max(run(idx + 1, cur), run(idx + 1, cur - w[idx]) + v[idx]); return dp[idx][cur] = res; } ll run() { for (int i = 1; i <= n; ++i) { for (int k = 1; k <= cap; ++k) { if (w[i - 1] > k) dp[i][k] = dp[i - 1][k]; else dp[i][k] = max(dp[i - 1][k], dp[i - 1][k - w[i - 1]] + v[i - 1]); } } return dp[n][cap]; } int main() { scanf("%d %d", &n, &cap); for (int i = 0; i < n; ++i) scanf("%d %d", &w[i], &v[i]); memset(dp, -1, sizeof dp); ll ans = run(); printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 100 + 10; const int CAP = 1e5 + 10; int n, cap; int v[N], w[N]; ll dp[N][CAP]; ll run(int idx, int cur) { if (dp[idx][cur] != -1) return dp[idx][cur]; ll res = 0; if (idx == n or cur == 0) res = 0; else if (w[idx] > cur) res = run(idx + 1, cur); else res = max(run(idx + 1, cur), run(idx + 1, cur - w[idx]) + v[idx]); return dp[idx][cur] = res; } ll run() { for (int i = 1; i <= n; ++i) { for (int k = 1; k <= cap; ++k) { if (w[i - 1] > k) dp[i][k] = dp[i - 1][k]; else dp[i][k] = max(dp[i - 1][k], dp[i - 1][k - w[i - 1]] + v[i - 1]); } } return dp[n][cap]; } int main() { scanf("%d %d", &n, &cap); for (int i = 0; i < n; ++i) scanf("%d %d", &w[i], &v[i]); memset(dp, -1, sizeof dp); ll ans = run(0, cap); printf("%lld\n", ans); return 0; }
[ "call.arguments.add" ]
966,904
966,903
u537359793
cpp
p03163
#include <bits/stdc++.h> using namespace std; const int haha = 15000; long long int n, W, best, w[100000], v[100000], dp[haha][haha]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> W; for (long long int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (long long int i = 0; i <= n; i++) { for (long long int j = 0; j <= W; j++) { if (i == 0 or j == 0) { dp[i][j] = 0; } else { best = dp[i - 1][j]; if (j >= w[i]) { best = max(best, dp[i - 1][j - w[i]] + v[i]); } dp[i][j] = best; } } } cout << dp[n][W] << endl; }
#include <bits/stdc++.h> using namespace std; const int haha = 15000; long long int n, W, best, w[10005], v[100005], dp[110][100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> W; for (long long int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (long long int i = 0; i <= n; i++) { for (long long int j = 0; j <= W; j++) { if (i == 0 or j == 0) { dp[i][j] = 0; } else { best = dp[i - 1][j]; if (j >= w[i]) { best = max(best, dp[i - 1][j - w[i]] + v[i]); } dp[i][j] = best; } } } cout << dp[n][W] << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "identifier.replace.remove", "literal.replace.add" ]
966,907
966,908
u010686961
cpp
p03163
#include <bits/stdc++.h> using namespace std; const int haha = 15000; long long int n, W, best, w[100000], v[100000], dp[haha][haha]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> W; for (long long int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (long long int i = 0; i <= n; i++) { for (long long int j = 0; j <= W; j++) { if (i == 0 or j == 0) { dp[i][j] = 0; } else { best = dp[i - 1][j]; if (j >= w[i]) { best = max(best, dp[i - 1][j - w[i]] + v[i]); } dp[i][j] = best; } } } cout << dp[n][W] << endl; }
#include <bits/stdc++.h> using namespace std; const int haha = 15000; long long int n, W, best, w[100000], v[100000], dp[110][100005]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> W; for (long long int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (long long int i = 0; i <= n; i++) { for (long long int j = 0; j <= W; j++) { if (i == 0 or j == 0) { dp[i][j] = 0; } else { best = dp[i - 1][j]; if (j >= w[i]) { best = max(best, dp[i - 1][j - w[i]] + v[i]); } dp[i][j] = best; } } } cout << dp[n][W] << endl; }
[ "identifier.replace.remove", "literal.replace.add", "variable_declaration.array_dimensions.change" ]
966,907
966,909
u010686961
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n, W, w, v; cin >> n >> W; vector<int> dp(W + 1); for (int i = 0; i < n; i++) { // cout<<"working;"; cin >> w >> v; for (int k = W - w; k >= 0; k--) { dp[k + w] = max(dp[k + w], v + dp[k]); } } cout << *max_element(dp.begin(), dp.end()); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, W, w, v; cin >> n >> W; vector<long long> dp(W + 1); for (int i = 0; i < n; i++) { // cout<<"working;"; cin >> w >> v; for (int k = W - w; k >= 0; k--) { dp[k + w] = max(dp[k + w], v + dp[k]); } } cout << *max_element(dp.begin(), dp.end()); return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,910
966,911
u783777606
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> wt(N, 0); vector<int> val(N, 0); for (int i = 0; i < N; i++) cin >> wt[i] >> val[i]; vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (j >= wt[i - 1]) dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> wt(N, 0); vector<int> val(N, 0); for (int i = 0; i < N; i++) cin >> wt[i] >> val[i]; vector<vector<long long>> dp(N + 1, vector<long long>(W + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (j >= wt[i - 1]) dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,912
966,913
u180641794
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> wt(N, 0); vector<int> val(N, 0); for (int i = 0; i < N; i++) cin >> wt[i] >> val[i]; vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (j >= wt[i - 1]) dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> wt(N, 0); vector<int> val(N, 0); for (int i = 0; i < N; i++) cin >> wt[i] >> val[i]; vector<vector<long long>> dp(N + 1, vector<long long>(W + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (j >= wt[i - 1]) dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,914
966,913
u180641794
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; void maxVal(int &a, int b) { a = max(a, b); } void solve() { int n, w, res = 0; cin >> n >> w; vector<int> dp(w + 1, 0); for (int i = 0; i < n; ++i) { int weight, val; cin >> weight >> val; for (int j = w; j >= weight; --j) { maxVal(dp[j], dp[j - weight] + val); } } for (auto d : dp) { maxVal(res, d); } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); // #endif solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; void maxVal(ll &a, ll b) { a = max(a, b); } void solve() { ll n, w, res = 0; cin >> n >> w; vector<ll> dp(w + 1, 0); for (int i = 0; i < n; ++i) { ll weight, val; cin >> weight >> val; for (int j = w; j >= weight; --j) { maxVal(dp[j], dp[j - weight] + val); } } for (auto d : dp) { maxVal(res, d); } cout << res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); // #endif solve(); return 0; }
[ "variable_declaration.type.change" ]
966,915
966,916
u719103039
cpp
p03163
// // Created by Hideaki Imamura on 2020-03-15. // #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define EPS (1e-7) //# define INF (1e9) #define PI (acos(-1)) // const ll mod = 1000000007; ll N, W; ll w[110], v[110]; int main() { cin >> N >> W; for (int i = 0; i < N; ++i) cin >> w[i] >> v[i]; vector<ll> dp(N + 1, 0); for (int i = 0; i < N; ++i) { for (int j = W; j >= 0; --j) { if (j - w[i] >= 0) chmax(dp[j], dp[j - w[i]] + v[i]); } } cout << dp[W] << endl; return 0; }
// // Created by Hideaki Imamura on 2020-03-15. // #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } #define EPS (1e-7) //# define INF (1e9) #define PI (acos(-1)) // const ll mod = 1000000007; ll N, W; ll w[110], v[110]; int main() { cin >> N >> W; for (int i = 0; i < N; ++i) cin >> w[i] >> v[i]; vector<ll> dp(W + 1, 0); for (int i = 0; i < N; ++i) { for (int j = W; j >= 0; --j) { if (j - w[i] >= 0) chmax(dp[j], dp[j - w[i]] + v[i]); } } cout << dp[W] << endl; return 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
966,919
966,920
u477855214
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { long long n, p; cin >> n >> p; long long w[n], v[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; long long track[n + 1][p + 1]; for (int i = 0; i < p + 1; i++) track[0][i] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 1; j < p + 1; j++) { if (w[i - 1] <= j) track[i][j] = max(v[i - 1] + track[i - 1][j - w[i - 1]], track[i - 1][j]); else track[i][j] = track[i - 1][j]; } } cout << track[n][p]; return (0); }
#include <bits/stdc++.h> using namespace std; int main() { long long n, p; cin >> n >> p; long long w[n], v[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; long long track[n + 1][p + 1]; for (int i = 0; i < p + 1; i++) track[0][i] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < p + 1; j++) { if (w[i - 1] <= j) track[i][j] = max(v[i - 1] + track[i - 1][j - w[i - 1]], track[i - 1][j]); else track[i][j] = track[i - 1][j]; } } cout << track[n][p]; return (0); }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
966,925
966,926
u123706464
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define here(x) cout << " #x = " << x << endl; #define show(x) \ { \ for (auto ii : x) \ cout << ii << en; \ cout << endl; \ } #define shop(n, x) \ { \ for (int i = 0; i < n; i++) \ cout << x << en; \ cout << endl; \ } #define ff first #define ss second #define sq(x) (x * x) #define endl '\n' #define en " " #define pb push_back #define mpair make_pair ll mod = 1000000007; double pi = 3.1415926536; int main() { fastio(); int tt = 1; // cin >> tt; while (tt--) { // go fast check // CHECK -> if() else // if() ll n, x = 0, m = 0, y = 0, d = 1, k = mod; cin >> n >> m; ll a[n + 1], v[n + 1]; ll dp[n + 1][m + 1] = {}; for (int i = 0; i < n; i++) cin >> a[i] >> v[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j >= a[i]) dp[i][j] = max(v[i] + dp[i - 1][j - a[i]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][m] << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define here(x) cout << " #x = " << x << endl; #define show(x) \ { \ for (auto ii : x) \ cout << ii << en; \ cout << endl; \ } #define shop(n, x) \ { \ for (int i = 0; i < n; i++) \ cout << x << en; \ cout << endl; \ } #define ff first #define ss second #define sq(x) (x * x) #define endl '\n' #define en " " #define pb push_back #define mpair make_pair ll mod = 1000000007; double pi = 3.1415926536; int main() { fastio(); int tt = 1; // cin >> tt; while (tt--) { // go fast check // CHECK -> if() else // if() ll n, x = 0, m = 0, y = 0, d = 1, k = mod; cin >> n >> m; ll a[n + 1], v[n + 1]; ll dp[n + 1][m + 1] = {}; for (int i = 1; i <= n; i++) cin >> a[i] >> v[i]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j >= a[i]) dp[i][j] = max(v[i] + dp[i - 1][j - a[i]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][m] << endl; } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.condition.change" ]
966,927
966,928
u756247155
cpp
p03163
#include <bits/stdc++.h> #define ll long long using namespace std; int N, W; int w[105], v[105]; int cache[105][10005]; int dp(int n, int wt) { if (wt > W) return -1e8; if (n == N) return 0; if (cache[n][wt] != -1) return cache[n][wt]; cache[n][wt] = max(dp(n + 1, wt), v[n] + dp(n + 1, wt + w[n])); return cache[n][wt]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(cache, -1, sizeof(cache)); cin >> N >> W; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; cout << dp(0, 0); return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; int N, W; int w[105], v[105]; int cache[105][100005]; int dp(int n, int wt) { if (wt > W) return -1e15; if (n == N) return 0; if (cache[n][wt] != -1) return cache[n][wt]; cache[n][wt] = max(dp(n + 1, wt), v[n] + dp(n + 1, wt + w[n])); return cache[n][wt]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(cache, -1, sizeof(cache)); cin >> N >> W; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; cout << dp(0, 0); return 0; }
[ "identifier.change", "literal.number.change", "variable_declaration.array_dimensions.change", "function.return_value.change", "variable_declaration.type.primitive.change" ]
966,939
966,936
u554003615
cpp
p03163
#include <bits/stdc++.h> #define ll long long using namespace std; int N, W; int w[105], v[105]; int cache[105][105]; int dp(int n, int wt) { if (wt > W) return -1e8; if (n == N) return 0; if (cache[n][wt] != -1) return cache[n][wt]; cache[n][wt] = max(dp(n + 1, wt), v[n] + dp(n + 1, wt + w[n])); return cache[n][wt]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(cache, -1, sizeof(cache)); cin >> N >> W; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; cout << dp(0, 0); return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; int N, W; int w[105], v[105]; int cache[105][100005]; int dp(int n, int wt) { if (wt > W) return -1e15; if (n == N) return 0; if (cache[n][wt] != -1) return cache[n][wt]; cache[n][wt] = max(dp(n + 1, wt), v[n] + dp(n + 1, wt + w[n])); return cache[n][wt]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(cache, -1, sizeof(cache)); cin >> N >> W; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; cout << dp(0, 0); return 0; }
[ "identifier.change", "literal.number.change", "variable_declaration.array_dimensions.change", "function.return_value.change", "variable_declaration.type.primitive.change" ]
966,940
966,936
u554003615
cpp
p03163
#include <bits/stdc++.h> using namespace std; int d[101][100001]; int main() { int n, m; cin >> n >> m; int a[n + 1], b[n + 1]; for (int k = 1; k <= n; k++) cin >> a[k] >> b[k]; for (int k = 1; k <= m; k++) if (k >= a[1]) d[1][k] = b[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j >= a[i]) d[i][j] = max(d[i - 1][j], d[i - 1][j - a[i]] + b[i]); else d[i][j] = d[i - 1][j]; } } cout << d[n][m]; return 0; }
#include <bits/stdc++.h> using namespace std; long long d[101][100001]; int main() { int n, m; cin >> n >> m; int a[n + 1], b[n + 1]; for (int k = 1; k <= n; k++) cin >> a[k] >> b[k]; for (int k = 1; k <= m; k++) if (k >= a[1]) d[1][k] = b[1]; for (int i = 2; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j >= a[i]) d[i][j] = max(d[i - 1][j], d[i - 1][j - a[i]] + b[i]); else d[i][j] = d[i - 1][j]; } } cout << d[n][m]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,951
966,952
u350462185
cpp
p03163
#include <bits/stdc++.h> using namespace std; int64_t dp[100][100000]; int64_t recurse(auto &v, auto &w, int64_t i, int64_t m) { if (!i == 0 or !m) return 0; int64_t &state = dp[i][m]; if (state != -1) return state; state = numeric_limits<int64_t>::min(); if (m >= w[i]) { state = max(state, recurse(v, w, i - 1, m - w[i]) + v[i]); } state = max(state, recurse(v, w, i - 1, m)); return state; } signed main() { int64_t n, m; cin >> n >> m; vector<int64_t> v(n), w(n); for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; } memset(dp, -1, sizeof dp); cout << recurse(v, w, n - 1, m); return 0; }
#include <bits/stdc++.h> using namespace std; int64_t dp[101][100001]; int64_t recurse(auto &v, auto &w, int64_t i, int64_t m) { if (i < 0 or !m) return 0; int64_t &state = dp[i][m]; if (state != -1) return state; state = numeric_limits<int64_t>::min(); if (m >= w[i]) { state = max(state, recurse(v, w, i - 1, m - w[i]) + v[i]); } state = max(state, recurse(v, w, i - 1, m)); return state; } signed main() { int64_t n, m; cin >> n >> m; vector<int64_t> v(n), w(n); for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; } memset(dp, -1, sizeof dp); cout << recurse(v, w, n - 1, m); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "expression.operation.unary.logical.remove", "control_flow.branch.if.condition.change", "expression.operator.compare.change" ]
966,958
966,957
u683739220
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, w, i, j, a, b; cin >> n >> w; vector<pair<int, int>> v; for (i = 0; i < n; ++i) { cin >> a >> b; v.push_back(make_pair(a, b)); } sort(v.begin(), v.end()); int dp[n + 1][w + 1] = {}; for (i = 1; i <= n; ++i) { for (j = 1; j <= w; j++) { if (j >= v[i - 1].first) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - v[i - 1].first] + v[i - 1].second); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, w, i, j, a, b; cin >> n >> w; vector<pair<int, long long int>> v; for (i = 0; i < n; ++i) { cin >> a >> b; v.push_back(make_pair(a, b)); } sort(v.begin(), v.end()); long long int dp[n + 1][w + 1] = {}; for (i = 1; i <= n; ++i) { for (j = 1; j <= w; j++) { if (j >= v[i - 1].first) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - v[i - 1].first] + v[i - 1].second); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; }
[ "variable_declaration.type.widen.change" ]
966,959
966,960
u723607904
cpp
p03163
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const int inf = 1 << 30; int dp[110][100010]; int main() { int n, W; cin >> n >> W; vector<int> w(n); vector<int> v(n); rep(i, n) { cin >> w[i] >> v[i]; } rep(i, n) { rep(j, W + 1) { if (j + w[i] <= W) chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } int ans = 0; rep(j, W + 1) { chmax(ans, dp[n][j]); } cout << ans << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const ll mod = 1e9 + 7; const int inf = 1 << 30; ll dp[110][100010]; int main() { int n, W; cin >> n >> W; vector<int> w(n); vector<int> v(n); rep(i, n) { cin >> w[i] >> v[i]; } rep(i, n) { rep(j, W + 1) { if (j + w[i] <= W) chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } ll ans = 0; rep(j, W + 1) { chmax(ans, dp[n][j]); } cout << ans << endl; }
[ "variable_declaration.type.change" ]
966,961
966,962
u136342563
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MOD = 1e9 + 7; const int INF = 1 << 30; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int dp[110][100010]; int main() { int N, W; cin >> N >> W; vector<int> v(N); vector<int> w(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(j, W + 1) { rep(i, N) { if (j + w[i] <= W) chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MOD = 1e9 + 7; const int INF = 1 << 30; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll dp[110][100010]; int main() { int N, W; cin >> N >> W; vector<ll> v(N); vector<ll> w(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(j, W + 1) { rep(i, N) { if (j + w[i] <= W) chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
[ "variable_declaration.type.change" ]
966,963
966,964
u136342563
cpp
p03163
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; const int Nmax = 110; const int Wmax = 100010; int N, W; ll dp[Nmax][Wmax]; ll v[Nmax]; ll w[Nmax]; const ll INF = 1LL << 60; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j < W; j++) { for (int i = 0; i < N; i++) { if (j + w[i + 1] <= W) chmax(dp[i + 1][j + w[i + 1]], dp[i][j] + v[i + 1]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; const int Nmax = 110; const int Wmax = 100010; int N, W; ll dp[Nmax][Wmax]; ll v[Nmax]; ll w[Nmax]; const ll INF = 1LL << 60; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j <= W; j++) { for (int i = 0; i < N; i++) { if (j + w[i + 1] <= W) chmax(dp[i + 1][j + w[i + 1]], dp[i][j] + v[i + 1]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
966,965
966,966
u136342563
cpp
p03163
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; const int Nmax = 110; const int Wmax = 100010; int N, W; ll dp[Nmax][Wmax]; int v[Nmax]; int w[Nmax]; const ll INF = 1LL << 60; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j < W; j++) { for (int i = 0; i < N; i++) { if (j + w[i + 1] <= W) chmax(dp[i + 1][j + w[i + 1]], dp[i][j] + v[i + 1]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; const int Nmax = 110; const int Wmax = 100010; int N, W; ll dp[Nmax][Wmax]; ll v[Nmax]; ll w[Nmax]; const ll INF = 1LL << 60; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int j = 0; j <= W; j++) { for (int i = 0; i < N; i++) { if (j + w[i + 1] <= W) chmax(dp[i + 1][j + w[i + 1]], dp[i][j] + v[i + 1]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
[ "variable_declaration.type.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
966,967
966,966
u136342563
cpp
p03163
#include <cmath> #include <cstring> #include <iostream> #include <string> #include <vector> #define ll long long 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; } // const ll INF = 1LL << 60; int N, W; vector<ll> weight, value; int main() { cin >> N >> W; weight.resize(N); value.resize(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } // dp[i][w]: // i番目(0-index)までの品物の中から、重さの総和がw以下である時の価値の総和の最大値 vector<vector<ll>> dp(N, vector<ll>(W, 0)); for (int w = 0; w <= W; w++) { if (w >= weight[0]) { dp[0][w] = value[0]; } } for (int i = 1; i < N; i++) { for (int w = 0; w <= W; w++) { if (w >= weight[i]) { chmax(dp[i][w], dp[i - 1][w - weight[i]] + value[i]); } chmax(dp[i][w], dp[i - 1][w]); } } cout << dp[N - 1][W] << endl; }
#include <cmath> #include <cstring> #include <iostream> #include <string> #include <vector> #define ll long long 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; } // const ll INF = 1LL << 60; int N, W; vector<ll> weight, value; int main() { cin >> N >> W; weight.resize(N); value.resize(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } // dp[i][w]: // i番目(0-index)までの品物の中から、重さの総和がw以下である時の価値の総和の最大値 vector<vector<ll>> dp(N, vector<ll>(W + 1, 0)); for (int w = 0; w <= W; w++) { if (w >= weight[0]) { dp[0][w] = value[0]; } } for (int i = 1; i < N; i++) { for (int w = 0; w <= W; w++) { if (w >= weight[i]) { chmax(dp[i][w], dp[i - 1][w - weight[i]] + value[i]); } chmax(dp[i][w], dp[i - 1][w]); } } cout << dp[N - 1][W] << endl; }
[ "assignment.change" ]
966,972
966,973
u465478140
cpp
p03163
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <vector> using namespace std; #define LOCAL 1 #define UPLOAD 2 #define ll long long const long long INF = 1LL << 60; template <class T = long long> T input() { T x; cin >> x; return x; } template <class T> void output(T x) { cout << x << endl; } #define debug(x) cerr << #x << ": " << x << '\n'; #define debugBit(x, n) cerr << #x << ": " << std::bitset<n>(x) << '\n'; 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; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } const long long mod = 1e9 + 7; int main() { #if ENVIRONMENT == LOCAL std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif ll N = input(); ll W = input(); std::vector<std::pair<ll, ll>> values; for (int i = 0; i < N; i++) { values.push_back({input(), input()}); } vector<vector<ll>> dp(N + 1, vector<ll>(W)); for (ll i = 0; i < N; i++) { for (ll w = 0; w <= W; w++) { if (values[i].first <= w) { chmax(dp[i + 1][w], dp[i][w - values[i].first] + values[i].second); } chmax(dp[i + 1][w], dp[i][w]); } } output(dp[N][W]); return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <vector> using namespace std; #define LOCAL 1 #define UPLOAD 2 #define ll long long const long long INF = 1LL << 60; template <class T = long long> T input() { T x; cin >> x; return x; } template <class T> void output(T x) { cout << x << endl; } #define debug(x) cerr << #x << ": " << x << '\n'; #define debugBit(x, n) cerr << #x << ": " << std::bitset<n>(x) << '\n'; 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; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } const long long mod = 1e9 + 7; int main() { #if ENVIRONMENT == LOCAL std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif ll N = input(); ll W = input(); std::vector<std::pair<ll, ll>> values; for (int i = 0; i < N; i++) { values.push_back({input(), input()}); } vector<vector<ll>> dp(N + 1, vector<ll>(W + 1)); for (ll i = 0; i < N; i++) { for (ll w = 0; w <= W; w++) { if (values[i].first <= w) { chmax(dp[i + 1][w], dp[i][w - values[i].first] + values[i].second); } chmax(dp[i + 1][w], dp[i][w]); } } output(dp[N][W]); return 0; }
[ "assignment.change" ]
966,974
966,975
u214712859
cpp
p03163
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <vector> using namespace std; #define LOCAL 1 #define UPLOAD 2 #define ll long long ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T = long long> T input() { T x; cin >> x; return x; } template <class T> void output(T x) { cout << x << endl; } #define debug(x) cerr << #x << ": " << x << '\n'; #define debugBit(x, n) cerr << #x << ": " << std::bitset<n>(x) << '\n'; int main() { #if LOCAL_ENVIRONMENT == 1 std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif ll N = input(); ll W = input(); vector<ll> weight; vector<ll> value; for (ll i = 0; i < N; i++) { ll w = input(); ll v = input(); weight.push_back(w); value.push_back(v); } ll dp[N + 1][W + 1]; for (int w = 0; w <= W; w++) { dp[0][w] = 0; } for (int i = 0; i < N; i++) { for (int w = 0; w <= W; w++) { if (weight[i] <= w) { dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + value[i]); } else { dp[i + 1][w] = dp[i][w]; } } } debug(dp[N][W]); return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <vector> using namespace std; #define LOCAL 1 #define UPLOAD 2 #define ll long long ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } template <class T = long long> T input() { T x; cin >> x; return x; } template <class T> void output(T x) { cout << x << endl; } #define debug(x) cerr << #x << ": " << x << '\n'; #define debugBit(x, n) cerr << #x << ": " << std::bitset<n>(x) << '\n'; int main() { #if LOCAL_ENVIRONMENT == 1 std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); #endif ll N = input(); ll W = input(); vector<ll> weight; vector<ll> value; for (ll i = 0; i < N; i++) { ll w = input(); ll v = input(); weight.push_back(w); value.push_back(v); } ll dp[N + 1][W + 1]; for (int w = 0; w <= W; w++) { dp[0][w] = 0; } for (int i = 0; i < N; i++) { for (int w = 0; w <= W; w++) { if (weight[i] <= w) { dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + value[i]); } else { dp[i + 1][w] = dp[i][w]; } } } output(dp[N][W]); return 0; }
[ "identifier.change", "call.function.change" ]
966,976
966,977
u214712859
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using i3 = pair<int, ii>; using li = pair<ll, int>; using lii = pair<ll, ii>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<ii>; using vli = vector<li>; using vpll = vector<pll>; using vi3 = vector<i3>; using vlii = vector<lii>; const int N = 2e5 + 5; const ll INF = 1e17 + 7; const double eps = 1e-9, PI = acos(-1); ll dp[110][N]; void solve(int testCase) { int n, W; scanf("%d %d", &n, &W); vi v(n, 0), w(n, 0); for (int i = 1; i <= n; i++) { scanf("%d %d", &w[i], &v[i]); } for (int i = 1; i <= n; i++) { for (int j = 0; j <= W; j++) { dp[i][j] = dp[i - 1][j]; if (j - w[i] >= 0) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } } ll ans = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= W; j++) { ans = max(ans, dp[i][j]); } } printf("%lld\n", ans); /* vl dp(W + 1 , 0); for(int i = 0 ; i < n ; i ++){ for(int j = W ; j >= 0 ; j --){ if(j - w[i] < 0)continue; dp[j] = max(dp[j] , dp[j - w[i]] + 1ll * v[i]); } } ll ans = *max_element(dp.begin() , dp.end()); printf("%lld\n" , ans); */ } main() { int t = 1; // scanf("%d" , &t); for (int testCase = 1; testCase <= t; testCase++) { solve(testCase); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using i3 = pair<int, ii>; using li = pair<ll, int>; using lii = pair<ll, ii>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<ii>; using vli = vector<li>; using vpll = vector<pll>; using vi3 = vector<i3>; using vlii = vector<lii>; const int N = 2e5 + 5; const ll INF = 1e17 + 7; const double eps = 1e-9, PI = acos(-1); ll dp[110][N]; void solve(int testCase) { int n, W; scanf("%d %d", &n, &W); vi v(n + 1, 0), w(n + 1, 0); for (int i = 1; i <= n; i++) { scanf("%d %d", &w[i], &v[i]); } for (int i = 1; i <= n; i++) { for (int j = 0; j <= W; j++) { dp[i][j] = dp[i - 1][j]; if (j - w[i] >= 0) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } } ll ans = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= W; j++) { ans = max(ans, dp[i][j]); } } printf("%lld\n", ans); /* vl dp(W + 1 , 0); for(int i = 0 ; i < n ; i ++){ for(int j = W ; j >= 0 ; j --){ if(j - w[i] < 0)continue; dp[j] = max(dp[j] , dp[j - w[i]] + 1ll * v[i]); } } ll ans = *max_element(dp.begin() , dp.end()); printf("%lld\n" , ans); */ } main() { int t = 1; // scanf("%d" , &t); for (int testCase = 1; testCase <= t; testCase++) { solve(testCase); } return 0; }
[ "assignment.change" ]
966,987
966,988
u284539389
cpp
p03163
#include <algorithm> #include <iostream> using namespace std; const int N = 1e5 + 7; int w[105], v[105], f[N]; int main() { int n, W; cin >> n >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; for (int i = 1; i <= n; ++i) for (int j = W; j >= w[i]; --j) f[j] = max(f[j], f[j - w[i]] + v[i]); cout << f[W]; return 0; }
#include <algorithm> #include <iostream> using namespace std; const int N = 1e5 + 7; long long w[105], v[105], f[N]; int main() { int n, W; cin >> n >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; for (int i = 1; i <= n; ++i) for (int j = W; j >= w[i]; --j) f[j] = max(f[j], f[j - w[i]] + v[i]); cout << f[W]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
966,991
966,992
u067001883
cpp
p03163
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; ll MOD = 1000000007; // a^p // 2^3 = 2 * 2^2 // 2^2 = 2 * (2^1) // 2^1 = 2 ll modpow(ll a, ll p, ll mod) { if (p == 0) return 1; if (p % 2 == 0) { ll half = modpow(a, p / 2, mod) % mod; return half * half % mod; } else { return a * modpow(a, p - 1, mod) % mod; } } // nCa を求める ll modCombination(ll n, ll a, ll mod) { if (n - a < a) { return modCombination(n, n - a, mod); } ll denominator = 1; // 分母 ll numerator = 1; // 分子 for (ll i = 0; i < a; i++) { denominator *= a - i; numerator *= n - i; denominator %= mod; numerator %= mod; } return numerator * modpow(denominator, mod - 2, mod) % mod; } class UnionFind { private: vector<ll> parents; public: UnionFind(ll n) : parents(n, -1) {} bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(ll x, ll y) { if (issame(x, y)) return false; ll rx = root(x); ll ry = root(y); if (parents[rx] > parents[ry]) swap(rx, ry); // サイズ情報を更新 parents[rx] += parents[ry]; // yの親を更新 parents[ry] = rx; return true; } ll size(ll x) { return -parents[root(x)]; } private: ll root(ll x) { if (parents[x] < 0) return x; // 根の親の値に木の(-)サイズの情報を入れる return parents[x] = root(parents[x]); } }; // 配るDP ll dp1(const vector<ll> &values, const vector<ll> &weights, vector<vector<ll>> &dp, ll N, ll W) { for (ll i = 0; i < N; i++) { for (ll w = 0; w < W + 1; w++) { if (w + weights[i] <= W) { dp[i + 1][w + weights[i]] = max(dp[i][w] + values[i], dp[i][w + weights[i]]); } dp[i + 1][w] = max(dp[i][w], dp[i + 1][w]); } } ll ans = 0; for (auto d : dp[N]) { ans = max(ans, d); } return ans; } ll dp2(const vector<ll> &values, const vector<ll> &weights, vector<vector<ll>> &dp, ll N, ll W) { for (ll i = 0; i < N; i++) { for (ll w = 0; w < W + 1; w++) { if (w - weights[i] >= 0) { dp[i + 1][w] = max(dp[i][w - weights[i]] + values[i], dp[i][w]); } else { // dp[i + 1][w] = max(dp[i][w], dp[i + 1][w]); dp[i + 1][w] = dp[i + 1][w]; } } } ll ans = 0; for (auto d : dp[N]) { ans = max(ans, d); } return ans; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); ll N, W; cin >> N >> W; vector<ll> values(N); vector<ll> weights(N); for (ll i = 0; i < N; i++) { cin >> weights[i] >> values[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0)); // for (ll i = 0; i < N + 1; i++) { // for (ll w = 0; w < W + 1; w++) { // cout << dp[i][w] << " "; // } // cout << endl; // } cout << dp2(values, weights, dp, N, W) << endl; return 0; }
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } typedef long long ll; ll MOD = 1000000007; // a^p // 2^3 = 2 * 2^2 // 2^2 = 2 * (2^1) // 2^1 = 2 ll modpow(ll a, ll p, ll mod) { if (p == 0) return 1; if (p % 2 == 0) { ll half = modpow(a, p / 2, mod) % mod; return half * half % mod; } else { return a * modpow(a, p - 1, mod) % mod; } } // nCa を求める ll modCombination(ll n, ll a, ll mod) { if (n - a < a) { return modCombination(n, n - a, mod); } ll denominator = 1; // 分母 ll numerator = 1; // 分子 for (ll i = 0; i < a; i++) { denominator *= a - i; numerator *= n - i; denominator %= mod; numerator %= mod; } return numerator * modpow(denominator, mod - 2, mod) % mod; } class UnionFind { private: vector<ll> parents; public: UnionFind(ll n) : parents(n, -1) {} bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(ll x, ll y) { if (issame(x, y)) return false; ll rx = root(x); ll ry = root(y); if (parents[rx] > parents[ry]) swap(rx, ry); // サイズ情報を更新 parents[rx] += parents[ry]; // yの親を更新 parents[ry] = rx; return true; } ll size(ll x) { return -parents[root(x)]; } private: ll root(ll x) { if (parents[x] < 0) return x; // 根の親の値に木の(-)サイズの情報を入れる return parents[x] = root(parents[x]); } }; // 配るDP ll dp1(const vector<ll> &values, const vector<ll> &weights, vector<vector<ll>> &dp, ll N, ll W) { for (ll i = 0; i < N; i++) { for (ll w = 0; w < W + 1; w++) { if (w + weights[i] <= W) { dp[i + 1][w + weights[i]] = max(dp[i][w] + values[i], dp[i][w + weights[i]]); } dp[i + 1][w] = max(dp[i][w], dp[i + 1][w]); } } ll ans = 0; for (auto d : dp[N]) { ans = max(ans, d); } return ans; } ll dp2(const vector<ll> &values, const vector<ll> &weights, vector<vector<ll>> &dp, ll N, ll W) { for (ll i = 0; i < N; i++) { for (ll w = 0; w < W + 1; w++) { if (w - weights[i] >= 0) { dp[i + 1][w] = max(dp[i][w - weights[i]] + values[i], dp[i][w]); } else { dp[i + 1][w] = dp[i][w]; } } } ll ans = 0; for (auto d : dp[N]) { ans = max(ans, d); } return ans; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); ll N, W; cin >> N >> W; vector<ll> values(N); vector<ll> weights(N); for (ll i = 0; i < N; i++) { cin >> weights[i] >> values[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0)); // for (ll i = 0; i < N + 1; i++) { // for (ll w = 0; w < W + 1; w++) { // cout << dp[i][w] << " "; // } // cout << endl; // } cout << dp2(values, weights, dp, N, W) << endl; return 0; }
[ "expression.operation.binary.remove" ]
967,001
967,002
u237620737
cpp
p03163
#include <bits/stdc++.h> using namespace std; long long i, j, n, m, t, k, dp[500][500], a[200001], b[200001]; int main() { cin >> n >> m; for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { if (j - a[i] <= 0) { dp[i][j] = dp[i - 1][j]; continue; } dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i]] + b[i]); } } cout << dp[n][m] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long i, j, n, m, t, k, dp[101][100001], a[200001], b[200001]; int main() { cin >> n >> m; for (i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { if (j - a[i] < 0) { dp[i][j] = dp[i - 1][j]; continue; } dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - a[i]] + b[i]); } } cout << dp[n][m] << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
967,007
967,008
u427421765
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; int main() { int N, W; cin >> N >> W; vector<vector<int>> dp(N + 1, vector<int>(W + 1)); for (int i = 0; i <= W; i++) { dp[0][i] = 0; } int w, v; 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 - w] + v, dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << *max_element(dp[N].begin(), dp[N].end()) << endl; ; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) typedef long long ll; int main() { int N, W; cin >> N >> W; vector<vector<ll>> dp(N + 1, vector<ll>(W + 1)); for (int i = 0; i <= W; i++) { dp[0][i] = 0; } ll w, v; 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 - w] + v, dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << *max_element(dp[N].begin(), dp[N].end()) << endl; ; }
[ "call.arguments.change", "variable_declaration.type.change" ]
967,018
967,019
u552357043
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; const int INF = 1000000007; const LL INFLL = 1000000000000000007; #define st first #define nd second #define pb push_back #define _boost \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // ***************************** CODE ***************************** // const int MAX = 107; const int MAX2 = 1e5 + 7; int waga[MAX], c[MAX]; int dp[MAX][MAX2]; int main() { _boost; int n, w; cin >> n >> w; for (int i = 1; i <= n; i++) cin >> waga[i] >> c[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= w; j++) { if (waga[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - waga[i]] + c[i]); } cout << dp[n][w]; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; const int INF = 1000000007; const LL INFLL = 1000000000000000007; #define st first #define nd second #define pb push_back #define _boost \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // ***************************** CODE ***************************** // const int MAX = 107; const int MAX2 = 1e5 + 7; LL waga[MAX], c[MAX]; LL dp[MAX][MAX2]; int main() { _boost; int n, w; cin >> n >> w; for (int i = 1; i <= n; i++) cin >> waga[i] >> c[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= w; j++) { if (waga[i] > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - waga[i]] + c[i]); } cout << dp[n][w]; return 0; }
[ "variable_declaration.type.change" ]
967,020
967,021
u694246042
cpp
p03163
#include <bits/stdc++.h> #define ll long long #define mx 200005 #define mod 1000000007 #define mxm 999999999999 using namespace std; ll dp[mx][200]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, p, w[200], v[200], i, j; cin >> n >> p; for (i = 1; i < n + 1; i++) { cin >> w[i] >> v[i]; // dp[i][0]=0; } for (i = 1; i < n + 1; i++) { for (j = 1; j < p + 1; j++) { if (j < w[i]) dp[i][j] = dp[i - 1][j]; else { dp[i][j] = max(v[i] + dp[i - 1][j - w[i]], dp[i][j - 1]); } } } ll ans = dp[n][p]; cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define mx 200005 #define mod 1000000007 #define mxm 999999999999 using namespace std; ll dp[200][mx]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, p, w[200], v[200], i, j; cin >> n >> p; for (i = 1; i < n + 1; i++) { cin >> w[i] >> v[i]; // dp[i][0]=0; } for (i = 1; i < n + 1; i++) { for (j = 1; j < p + 1; j++) { if (j < w[i]) dp[i][j] = dp[i - 1][j]; else { dp[i][j] = max(v[i] + dp[i - 1][j - w[i]], dp[i - 1][j]); } } } ll ans = dp[n][p]; cout << ans; return 0; }
[ "identifier.replace.remove", "literal.replace.add", "variable_declaration.array_dimensions.change", "identifier.replace.add", "literal.replace.remove", "assignment.change", "expression.operation.binary.remove" ]
967,022
967,023
u720296041
cpp
p03163
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define st first #define nd second #define turbo \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define vi vector<int> #define vvi vector<vi> #define qi queue<int> #define ld long double using namespace std; /*---------------------------------------------------------///CODE///---------------------------------------------------------*/ const int N = 1e5; int dp[101][N + 10]; int weight[N + 10]; int value[N + 10]; int main() { turbo int n, w; cin >> n >> w; for (int i = 1; i <= n; i++) cin >> weight[i] >> value[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= w; j++) if (weight[i] <= j) dp[i][j] = max(dp[i - 1][j - weight[i]] + value[i], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; return cout << dp[n][w], 0; }
#include <bits/stdc++.h> #define ll long long #define pii pair<int, int> #define st first #define nd second #define turbo \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define vi vector<int> #define vvi vector<vi> #define qi queue<int> #define ld long double using namespace std; /*---------------------------------------------------------///CODE///---------------------------------------------------------*/ const int N = 1e5; ll dp[101][N + 10]; int weight[N + 10]; ll value[N + 10]; int main() { turbo int n, w; cin >> n >> w; for (int i = 1; i <= n; i++) cin >> weight[i] >> value[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= w; j++) if (weight[i] <= j) dp[i][j] = max(dp[i - 1][j - weight[i]] + value[i], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; return cout << dp[n][w], 0; }
[ "variable_declaration.type.change" ]
967,024
967,025
u317997849
cpp
p03163
#include <iostream> using namespace std; int dp[200007]; int main() { int N, W; cin >> N >> W; for (int i = 0; i < N; i++) { int n, w; cin >> n >> w; if (n > W) continue; for (int j = W; j > 0; j--) if (dp[j] != 0) dp[j + n] = max(dp[j + n], dp[j] + w); dp[n] = max(dp[n], w); } int wynik = 0; for (int i = 1; i <= W; i++) wynik = max(wynik, dp[i]); cout << wynik; }
#include <iostream> using namespace std; long long dp[200007]; int main() { int N, W; cin >> N >> W; for (int i = 0; i < N; i++) { long long n, w; cin >> n >> w; if (n > W) continue; for (int j = W; j > 0; j--) if (dp[j] != 0) dp[j + n] = max(dp[j + n], dp[j] + w); dp[n] = max(dp[n], w); } long long wynik = 0; for (int i = 1; i <= W; i++) wynik = max(wynik, dp[i]); cout << wynik; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
967,054
967,055
u098482829
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int dy[] = {1, -1, 0, 0}; int dx[] = {0, 0, 1, -1}; int main() { 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<ll>> dp(N, vector<ll>(1e7 + 1, -1)); dp[0][0] = 0; dp[0][w[0]] = v[0]; for (int i = 1; i < N; i++) { for (int j = 0; j <= W; j++) { dp[i][j] = dp[i - 1][j]; if (j - w[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } ll ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[N - 1][i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int dy[] = {1, -1, 0, 0}; int dx[] = {0, 0, 1, -1}; int main() { 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<ll>> dp(N, vector<ll>(1e5 + 1, -1)); dp[0][0] = 0; dp[0][w[0]] = v[0]; for (int i = 1; i < N; i++) { for (int j = 0; j <= W; j++) { dp[i][j] = dp[i - 1][j]; if (j - w[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]); } } ll ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[N - 1][i]); } cout << ans << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
967,060
967,061
u854831509
cpp
p03163
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; typedef long long ll; 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() { int N, W; cin >> N >> W; int w, v; int dp[N + 1][W + 1]; for (int i = 0; i <= N; i++) { for (int j = 0; j <= W; j++) { dp[i][j] = 0; } } for (int i = 1; i <= N; i++) { cin >> w >> v; for (int j = 1; 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]; } // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << " "; } // cout << endl; } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; typedef long long ll; 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() { int N, W; cin >> N >> W; ll w, v; ll dp[N + 1][W + 1]; for (int i = 0; i <= N; i++) { for (int j = 0; j <= W; j++) { dp[i][j] = 0; } } for (int i = 1; i <= N; i++) { cin >> w >> v; for (int j = 1; 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]; } // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << " "; } // cout << endl; } cout << dp[N][W] << endl; }
[ "variable_declaration.type.change" ]
967,066
967,067
u613931538
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define llt long long int #define pb push_back #define pii pair<int, int> #define mk make_pair #define f first #define s second // int dp[100001]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, w; cin >> n >> w; vector<pii> v(n); int x, y; for (int i = 0; i < n; i++) { cin >> x >> y; v[i].f = x; v[i].s = y; } int dp[n + 1][w + 1]; memset(dp, 0, sizeof dp); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (v[i - 1].f > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(v[i - 1].s + dp[i - 1][j - v[i - 1].f], dp[i - 1][j]); } } } cout << dp[n][w]; return 0; }
#include <bits/stdc++.h> using namespace std; #define llt long long int #define pb push_back #define pii pair<int, int> #define mk make_pair #define f first #define s second // int dp[100001]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, w; cin >> n >> w; vector<pii> v(n); int x, y; for (int i = 0; i < n; i++) { cin >> x >> y; v[i].f = x; v[i].s = y; } llt dp[n + 1][w + 1]; memset(dp, 0, sizeof dp); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (v[i - 1].f > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(v[i - 1].s + dp[i - 1][j - v[i - 1].f], dp[i - 1][j]); } } } cout << dp[n][w]; return 0; }
[ "variable_declaration.type.change" ]
967,070
967,071
u356063349
cpp
p03163
#include <bits/stdc++.h> #define ll long long int #define mod 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, W, i, j; cin >> n >> W; ll v[n + 1], w[n + 1]; for (i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } ll dp[W + 1][n + 1]; memset(dp, 0, sizeof(dp)); for (i = 1; i <= W; i++) { for (j = 1; j <= n; j++) { if (i < w[j]) { dp[i][j] = dp[i][j - 1]; } else { dp[i][j] = max(dp[i][j - 1], v[j] + dp[i - w[j]][j]); } } } cout << dp[W][n]; }
#include <bits/stdc++.h> #define ll long long int #define mod 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, W, i, j; cin >> n >> W; ll v[n + 1], w[n + 1]; for (i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } ll dp[W + 1][n + 1]; memset(dp, 0, sizeof(dp)); for (i = 1; i <= W; i++) { for (j = 1; j <= n; j++) { if (i < w[j]) { dp[i][j] = dp[i][j - 1]; } else { dp[i][j] = max(dp[i][j - 1], v[j] + dp[i - w[j]][j - 1]); } } } cout << dp[W][n]; }
[ "assignment.change" ]
967,072
967,073
u741672523
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const ll inf = 1LL << 60; const double eps = 1e-9; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int dp[100 + 1][100 + 1] = {0}; int main() { int N, W; cin >> N >> W; int w[N], v[N]; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; // for (int i = 0; i < N; i++) cout << w[i] << v[i] << endl; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j >= w[i]) { // cout << dp[i][j-w[i]] << endl; chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); // cout << dp[i+1][j] << endl; } chmax(dp[i + 1][j], dp[i][j]); } } /* for (int i = 0; i <= N; i++) { for (int j = 0; j <= W; j++) { cout << dp[i][j] << " "; } cout << endl; }*/ cout << dp[N][W] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; const ll inf = 1LL << 60; const double eps = 1e-9; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll dp[100 + 1][100000 + 1] = {0}; int main() { int N, W; cin >> N >> W; ll w[N], v[N]; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; // for (int i = 0; i < N; i++) cout << w[i] << v[i] << endl; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j >= w[i]) { // cout << dp[i][j-w[i]] << endl; chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); // cout << dp[i+1][j] << endl; } chmax(dp[i + 1][j], dp[i][j]); } } /* for (int i = 0; i <= N; i++) { for (int j = 0; j <= W; j++) { cout << dp[i][j] << " "; } cout << endl; }*/ cout << dp[N][W] << endl; return 0; }
[ "variable_declaration.type.change", "literal.number.change", "expression.operation.binary.change" ]
967,079
967,078
u831873811
cpp
p03163
#include <bits/stdc++.h> #define int long long #define double long double #define endl "\n" const int INF = (int)1e9 + 9; const int maxn = (int)1e6 + 6; // const mod = (int) 1e9 + 7; using namespace std; signed main() { int N, W; cin >> N >> W; vector<int> v(N), w(N); vector<vector<int>> dp(N + 1, vector<int>(W + 1)); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0][w[0]] = v[0]; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j >= w[i]) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]]) + v[i]; } dp[i][j] = max(dp[i][j], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[N - 1][i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define double long double #define endl "\n" const int INF = (int)1e9 + 9; const int maxn = (int)1e6 + 6; // const mod = (int) 1e9 + 7; using namespace std; signed main() { int N, W; cin >> N >> W; vector<int> v(N), w(N); vector<vector<int>> dp(N + 1, vector<int>(W + 1)); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0][w[0]] = v[0]; for (int i = 1; i < N; i++) { for (int j = 0; j <= W; j++) { if (j >= w[i]) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]]) + v[i]; } dp[i][j] = max(dp[i][j], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[N - 1][i]); } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
967,085
967,086
u699731638
cpp
p03163
#include <bits/stdc++.h> #define int long long #define double long double #define endl "\n" const int INF = (int)1e9 + 9; const int maxn = (int)1e6 + 6; // const mod = (int) 1e9 + 7; using namespace std; signed main() { int N, W; cin >> N >> W; vector<int> v(N), w(N); vector<vector<int>> dp(N + 1, vector<int>(W + 1)); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0][w[0]] = v[0]; for (int i = 0; i <= N; i++) { for (int j = 0; j <= W; j++) { if (j >= w[i]) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]]) + v[i]; } dp[i][j] = max(dp[i][j], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[N - 1][i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define double long double #define endl "\n" const int INF = (int)1e9 + 9; const int maxn = (int)1e6 + 6; // const mod = (int) 1e9 + 7; using namespace std; signed main() { int N, W; cin >> N >> W; vector<int> v(N), w(N); vector<vector<int>> dp(N + 1, vector<int>(W + 1)); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0][w[0]] = v[0]; for (int i = 1; i < N; i++) { for (int j = 0; j <= W; j++) { if (j >= w[i]) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]]) + v[i]; } dp[i][j] = max(dp[i][j], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[N - 1][i]); } cout << ans << endl; return 0; }
[ "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", "expression.operation.binary.change" ]
967,087
967,086
u699731638
cpp
p03163
#include "bits/stdc++.h" using namespace std; int main() { int n, W; cin >> n >> W; int wt[n + 1]; int v[n + 1]; for (int i = 0; i < n; i++) cin >> wt[i] >> v[i]; int dp[n + 1] [W + 1]; // the cells consider the subproblem where we have the first i // elements with maximum capacity of j,for example dp[1,10] // considers the subproblem with first element available and 10 capacity 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; continue; } if (j - wt[i - 1] >= 0) { // if at the current capacity j we can put at least element i-1 dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + v[i - 1]); // the solution for the subproblem // is the maximum between // the value dp[i-1][j] which is the solution with the items up to i-1 // available,and the result when we try to add // the previous element with some element with weight [j-wt[i-1]] IF // EXISTANT in the dp cell of a precomputed subproblem } else { dp[i][j] = dp[i - 1][j]; } } } // for(int i=0;i<=n;i++){ // for(int j=0;j<=W;j++){ // cout<<dp[i][j]<<" "; //} // cout<<endl; //} cout << dp[n][W]; }
#include "bits/stdc++.h" using namespace std; int main() { long n, W; cin >> n >> W; long wt[n + 1]; long v[n + 1]; for (int i = 0; i < n; i++) cin >> wt[i] >> v[i]; long dp[n + 1] [W + 1]; // the cells consider the subproblem where we have the first i // elements with maximum capacity of j,for example dp[1,10] // considers the subproblem with first element available and 10 capacity memset(dp, 0, sizeof(dp)); for (int i = 0; i <= n; i++) { for (long j = 0; j <= W; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; continue; } if (j - wt[i - 1] >= 0) { // if at the current capacity j we can put at least element i-1 dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + v[i - 1]); // the solution for the subproblem // is the maximum between // the value dp[i-1][j] which is the solution with the items up to i-1 // available,and the result when we try to add // the previous element with some element with weight [j-wt[i-1]] IF // EXISTANT in the dp cell of a precomputed subproblem } else { dp[i][j] = dp[i - 1][j]; } } } /* for(int i=0;i<=n;i++){ for(long j=0;j<=W;j++){ cout<<dp[i][j]<<" "; } cout<<endl; } */ cout << dp[n][W]; }
[ "variable_declaration.type.primitive.change", "control_flow.loop.for.initializer.change" ]
967,088
967,089
u552846576
cpp
p03163
//*******Abhijit Burman***********// // Jalpaiguri Government Engineering College// #include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mk make_pair #define MAXX (1000000000000000000 + 7) #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL) ll dp[10000][10000]; ll knapsack(ll a[], ll b[], ll wt, ll index) { // cout<<wt<<endl; if (index < 0) { return 0; } if (dp[wt][index] != -1) { return dp[wt][index]; } else { if (wt - a[index] < 0) { dp[wt][index] = knapsack(a, b, wt, index - 1); } else dp[wt][index] = max(b[index] + knapsack(a, b, wt - a[index], index - 1), knapsack(a, b, wt, index - 1)); return dp[wt][index]; } } void solve(ll t) { ll n, w; cin >> n >> w; ll a[n], b[n]; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } ll ans = knapsack(a, b, w, n - 1); cout << ans << endl; } int main() { ll t = 1; // cin>>t; while (t--) { solve(t); } return 0; }
//*******Abhijit Burman***********// // Jalpaiguri Government Engineering College// #include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mk make_pair #define MAXX (1000000000000000000 + 7) #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL) ll dp[100100][110]; ll knapsack(ll a[], ll b[], ll wt, ll index) { // cout<<wt<<endl; if (index < 0) { return 0; } if (dp[wt][index] != -1) { return dp[wt][index]; } else { if (wt - a[index] < 0) { dp[wt][index] = knapsack(a, b, wt, index - 1); } else dp[wt][index] = max(b[index] + knapsack(a, b, wt - a[index], index - 1), knapsack(a, b, wt, index - 1)); return dp[wt][index]; } } void solve(ll t) { ll n, w; cin >> n >> w; ll a[n], b[n]; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } ll ans = knapsack(a, b, w, n - 1); cout << ans << endl; } int main() { ll t = 1; // cin>>t; while (t--) { solve(t); } return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
967,095
967,091
u915235255
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF 1000000000 typedef long long ll; typedef pair<int, int> P; int dp[101][100001] = {}; int main() { int n, w, w_i, v, i, j; cin >> n >> w; for (i = 1; i <= n; i++) { cin >> w_i >> v; for (j = 0; j <= w; j++) { if (j >= w_i) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w_i] + v); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define INF 1000000000 typedef long long ll; typedef pair<int, int> P; ll dp[101][100001] = {}; int main() { ll n, w, w_i, v, i, j; cin >> n >> w; for (i = 1; i <= n; i++) { cin >> w_i >> v; for (j = 0; j <= w; j++) { if (j >= w_i) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w_i] + v); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << "\n"; return 0; }
[ "variable_declaration.type.change" ]
967,096
967,097
u058348416
cpp
p03163
#include <bits/stdc++.h> #define rep(i, a, n) for (ll i = a; i < n; i++) #define per(i, a, n) for (ll i = n - 1; i >= a; i--) #define fill0(n) setfill('0') << right << setw(n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define LONGMAX 1e18 #define INTMAX 1000000000 using namespace std; typedef long long ll; typedef pair<int, int> P; const ll mod = 1e9 + 7; const long double EPS = 0.0000000001; int n, w; int main() { cin >> n >> w; vector<int> weight(n), value(n); for (int i = 0; i < n; i++) cin >> weight[i] >> value[i]; ll dp[n + 1][w + 1]; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < w + 1; j++) { dp[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < w; j++) { if (j - weight[i] >= 0) { ll tmp = dp[i][j - weight[i]] + value[i]; dp[i + 1][j] = max(tmp, dp[i][j]); } else { dp[i + 1][j] = dp[i][j]; } } } cout << dp[n][w] << endl; }
#include <bits/stdc++.h> #define rep(i, a, n) for (ll i = a; i < n; i++) #define per(i, a, n) for (ll i = n - 1; i >= a; i--) #define fill0(n) setfill('0') << right << setw(n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define LONGMAX 1e18 #define INTMAX 1000000000 using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1e9 + 7; const long double EPS = 0.0000000001; int n, w; int main() { cin >> n >> w; vector<int> weight(n), value(n); for (int i = 0; i < n; i++) cin >> weight[i] >> value[i]; ll dp[n + 1][w + 1]; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < w + 1; j++) { dp[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < w + 1; j++) { if (j - weight[i] >= 0) { ll tmp = dp[i][j - weight[i]] + value[i]; dp[i + 1][j] = max(tmp, dp[i][j]); } else { dp[i + 1][j] = dp[i][j]; } } } cout << dp[n][w] << endl; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
967,098
967,099
u255001744
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define pb push_back vector<int> w, v; long int dpv[100001][2]; /*long int dp(int W,int N) { if(dpv[W][N]) return dpv[W][N]; if(W==0 || N==0) return 0; if(w[N]<=W) dpv[W][N]=max(dp(W-w[N],N-1)+v[N],dp(W,N-1)); else dpv[W][N]=dp(W,N-1); return dpv[W][N]; }*/ long int dp(int W, int N) { int i, j; if (W == 0 || N == 0) return 0; for (j = 1; j <= N; j++) for (i = 1; i <= W; i++) { if (w[j] <= i) dpv[i][j % 2] = max(dpv[i - w[j]][(j - 1) % 2] + v[j], dpv[i][(j - 1) % 2]); else dpv[i][j % 2] = dpv[i][(j - 1) % 2]; } j--; return dpv[i][j % 2]; } int main() { w.pb(0); v.pb(0); int N, W, i, w1, v1; cin >> N >> W; for (i = 1; i <= N; i++) { cin >> w1 >> v1; w.pb(w1); v.pb(v1); } cout << dp(W, N); }
#include <bits/stdc++.h> using namespace std; #define pb push_back vector<int> w, v; long int dpv[100001][3]; /*long int dp(int W,int N) { if(dpv[W][N]) return dpv[W][N]; if(W==0 || N==0) return 0; if(w[N]<=W) dpv[W][N]=max(dp(W-w[N],N-1)+v[N],dp(W,N-1)); else dpv[W][N]=dp(W,N-1); return dpv[W][N]; }*/ long int dp(int W, int N) { int i, j; if (W == 0 || N == 0) return 0; for (j = 1; j <= N; j++) for (i = 1; i <= W; i++) { if (w[j] <= i) dpv[i][j % 2] = max(dpv[i - w[j]][(j - 1) % 2] + v[j], dpv[i][(j - 1) % 2]); else dpv[i][j % 2] = dpv[i][(j - 1) % 2]; } j--; return dpv[W][N % 2]; } int main() { w.pb(0); v.pb(0); int N, W, i, w1, v1; cin >> N >> W; for (i = 1; i <= N; i++) { cin >> w1 >> v1; w.pb(w1); v.pb(v1); } cout << dp(W, N); }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "identifier.change", "variable_access.subscript.index.change", "function.return_value.change", "expression.operation.binary.change" ]
967,100
967,101
u476597830
cpp
p03163
#include <bits/stdc++.h> using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree < int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update > #define smallk order_of_key #define kth find_by_order */ #define nl '\n' #define F first #define S second #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define pb push_back typedef long long ll; const int N = 1e5 + 123; const int M = 1e9 + 7; const int K = 500; int n, W; int dp[111][N]; int w[111], p[111]; int main() { ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0); #ifdef LOCAL // freopen("A.txt", "r", stdin); #endif // LOCAL cin >> n >> W; for (int i = 1; i <= n; ++i) { cin >> w[i] >> p[i]; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= W; ++j) { dp[i][j] = dp[i - 1][j]; if (w[i] <= j) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + p[i]); } } } cout << dp[n][W]; return 0; }
#include <bits/stdc++.h> using namespace std; /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree < int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update > #define smallk order_of_key #define kth find_by_order */ #define nl '\n' #define F first #define S second #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define pb push_back typedef long long ll; const int N = 1e5 + 123; const int M = 1e9 + 7; const int K = 500; int n, W; long long dp[111][N]; int w[111], p[111]; int main() { ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0); #ifdef LOCAL // freopen("A.txt", "r", stdin); #endif // LOCAL cin >> n >> W; for (int i = 1; i <= n; ++i) { cin >> w[i] >> p[i]; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= W; ++j) { dp[i][j] = dp[i - 1][j]; if (w[i] <= j) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + p[i]); } } } cout << dp[n][W]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
967,102
967,103
u653739037
cpp
p03163
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll inf = 1LL << 60; const long double pi = 3.14159265358979323846; // ****************************************CODE***************************************// ll n, w, weight[100100], value[100100]; ll dp[110][100100]; int main() { cin >> n >> w; for (int i = 0; i < n; i++) cin >> weight[i] >> value[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < 100100; j++) { if (j - weight[i] >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } cout << dp[n][w] << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll inf = 1LL << 60; const long double pi = 3.14159265358979323846; // ****************************************CODE***************************************// ll n, w, weight[100100], value[100100]; ll dp[110][100100]; int main() { cin >> n >> w; for (int i = 0; i < n; i++) cin >> weight[i] >> value[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < 100100; j++) { if (j - weight[i] >= 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]); dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } cout << dp[n][w] << endl; }
[ "misc.opposites", "assignment.value.change", "identifier.change", "call.function.change" ]
967,104
967,105
u195054737
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" int main() { int n, w; cin >> n >> w; vector<pair<int, int>> v(n); for (auto &i : v) { cin >> i.first >> i.second; } sort(v.begin(), v.end()); vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (j - v[i - 1].first >= 0) { dp[i][j] = max(dp[i - 1][j], v[i - 1].second + dp[i - 1][j - v[i - 1].first]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl "\n" int main() { ll n, w; cin >> n >> w; vector<pair<ll, ll>> v(n); for (auto &i : v) { cin >> i.first >> i.second; } sort(v.begin(), v.end()); vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (j - v[i - 1].first >= 0) { dp[i][j] = max(dp[i - 1][j], v[i - 1].second + dp[i - 1][j - v[i - 1].first]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][w] << endl; }
[ "variable_declaration.type.change", "call.arguments.change" ]
967,114
967,115
u435876834
cpp
p03163
#include <bits/stdc++.h> using namespace std; vector<vector<long>> a, dp; long w, n; long rec(long i, long j) { if (i >= n) { // cout<<"rec("<<i<<","<<j<<")"<<endl; return 0; } else { if (dp[i][j] == 0) { // cout<<"rec("<<i+1<<","<<j-a[i][0]<<")+"<<a[i][1]<<" "; // cout<<"rec("<<i+1<<","<<j<<")"<<endl; if (j < a[i][0]) { dp[i][j] = rec(i - 1, j); } else { dp[i][j] = max(rec(i + 1, j), rec(i + 1, j - a[i][0]) + a[i][1]); } } return dp[i][j]; } } int main() { cin >> n >> w; a.resize(n, vector<long>(2, 0)); for (vector<long> &i : a) { for (long &x : i) { cin >> x; } } dp.resize(n, vector<long>(w + 1, 0)); cout << rec(0, w) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<vector<long>> a, dp; long w, n; long rec(long i, long j) { if (i >= n) { return 0; } else { if (dp[i][j] == 0) { if (j < a[i][0]) { dp[i][j] = rec(i + 1, j); } else { dp[i][j] = max(rec(i + 1, j), rec(i + 1, j - a[i][0]) + a[i][1]); } } return dp[i][j]; } } int main() { cin >> n >> w; a.resize(n, vector<long>(2, 0)); for (vector<long> &i : a) { for (long &x : i) { cin >> x; } } dp.resize(n, vector<long>(w + 1, 0)); cout << rec(0, w) << endl; return 0; }
[ "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change" ]
967,122
967,123
u639264808
cpp
p03163
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int N, W; int w[110], v[110]; int dp[110][100010]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; for (int i = 0; i < N; i++) { for (int sum = 0; sum <= W; sum++) { if (sum - w[i] >= 0) { chmax(dp[i + 1][sum], dp[i][sum - w[i]] + v[i]); } chmax(dp[i + 1][sum], dp[i][sum]); } } cout << dp[N][W] << endl; }
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } ll N, W; ll w[110], v[110]; ll dp[110][100010]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; for (int i = 0; i < N; i++) { for (int sum = 0; sum <= W; sum++) { if (sum - w[i] >= 0) { chmax(dp[i + 1][sum], dp[i][sum - w[i]] + v[i]); } chmax(dp[i + 1][sum], dp[i][sum]); } } cout << dp[N][W] << endl; }
[ "variable_declaration.type.change" ]
967,126
967,127
u110653681
cpp
p03163
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) #define RFOR(i, b, a) for (int i = (b)-1; i >= (a); i--) #define ITER(it, a) for (typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a, value) memset(a, value, sizeof(a) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const double EPS = 1e-7; const int MAX = 20 * 1000 + 47; const int MAS = 1e5 * 6; const int MOD = 1000 * 1000 * 1000 + 7; double DIST(double x1, double x2, double y1, double y2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } int main() { int n, w; cin >> n >> w; vector<pair<int, int>> v(n); vector<LL> dp(w + 1); rep(i, n) { int v, cost; cin >> v >> cost; RFOR(i, w - v + 1, 0) { dp[i + v] = max(dp[i + v], dp[i] + cost); } } int ans = 0; rep(i, w + 1) { // cout << dp[i] << endl; ans = max((LL)ans, dp[i]); } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) #define RFOR(i, b, a) for (int i = (b)-1; i >= (a); i--) #define ITER(it, a) for (typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a, value) memset(a, value, sizeof(a) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const double EPS = 1e-7; const int MAX = 20 * 1000 + 47; const int MAS = 1e5 * 6; const int MOD = 1000 * 1000 * 1000 + 7; double DIST(double x1, double x2, double y1, double y2) { return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); } int main() { int n, w; cin >> n >> w; vector<pair<int, int>> v(n); vector<LL> dp(w + 1); rep(i, n) { int v, cost; cin >> v >> cost; RFOR(i, w - v + 1, 0) { dp[i + v] = max(dp[i + v], dp[i] + cost); } } LL ans = 0; rep(i, w + 1) { // cout << dp[i] << endl; ans = max((LL)ans, dp[i]); } cout << ans << endl; }
[ "variable_declaration.type.change" ]
967,128
967,129
u035166659
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int i, j, temp, n, total, w, v; cin >> n >> total; vector<int> val[n]; int dp[n + 1][total + 1]; for (i = 0; i < n; i++) { cin >> w >> v; val[i].push_back(v); val[i].push_back(w); } for (i = 0; i <= n; i++) { for (j = 0; j <= total; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else if (val[i - 1][1] <= j) { dp[i][j] = max(val[i - 1][0] + dp[i - 1][j - val[i - 1][1]], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][total] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, temp, n, total, w, v; cin >> n >> total; vector<long long int> val[n]; long long int dp[n + 1][total + 1]; for (i = 0; i < n; i++) { cin >> w >> v; val[i].push_back(v); val[i].push_back(w); } for (i = 0; i <= n; i++) { for (j = 0; j <= total; j++) { if (i == 0 || j == 0) { dp[i][j] = 0; } else if (val[i - 1][1] <= j) { dp[i][j] = max(val[i - 1][0] + dp[i - 1][j - val[i - 1][1]], dp[i - 1][j]); // cout << "i: " << i << " j: " << j << " " << dp[i][j] << endl; } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[n][total] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
967,135
967,136
u282921790
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define INF 1e9 + 7 void max_self(int &a, int b) { a = max(a, b); } int main() { int n, W; cin >> n >> W; vector<int> KS(W + 1); for (int i = 0; i < n; i++) { int w, v; cin >> w >> v; for (int w_base = W - w; w_base >= 0; w_base--) { max_self(KS[w_base + w], KS[w_base] + v); } } cout << KS[W]; }
#include <bits/stdc++.h> using namespace std; #define INF 1e9 + 7 void max_self(long long &a, long long b) { a = max(a, b); } int main() { int n, W; cin >> n >> W; vector<long long> KS(W + 1); for (int i = 0; i < n; i++) { int w, v; cin >> w >> v; for (int w_base = W - w; w_base >= 0; w_base--) { max_self(KS[w_base + w], KS[w_base] + v); } } cout << KS[W]; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
967,144
967,145
u370274941
cpp
p03163
#include <bits/stdc++.h> #define rep1(i, n, a) for (int i = 0; i < n; i += a) #define rep2(i, n, a) for (int i = a; i < n; i++) #define rep3(n) for (int i = 0; i < n; i++) #define inarr(arr, n) rep1(i, n, 1) cin >> arr[i] #define ll long long int #define pb push_back #define all(v) v.begin(), v.end() #define trav(a, x) for (auto x : a) #define endl "\n" #define eb emplace_back #define fr first #define sc second #define gcd(a, b) __gcd(a, b) #define pres(a, x) a.find(x) != a.end() #define sz(a) (int)a.size() #define pii pair<int, int> #define psi pair<string, int> #define pss pair<string, string> #define pll pair<ll, ll> #define vec vector<int> #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ret return 0 #define pi 3.1415926536 #define hell 1000000007 #define narak 998244353 const int inf1 = 1e9; const ll inf2 = 1e18; const int N = 100000; using namespace std; int dirs[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; // syntax for min priority_queue of pairs // priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q; int solve() { int n, W; cin >> n >> W; int w[n + 1], v[n + 1]; rep3(n) cin >> w[i + 1] >> v[i + 1]; int dp[W + 1][n + 1]; for (int i = 0; i <= W; i++) { for (int j = 0; j <= n; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (w[j] > i) dp[i][j] = dp[i][j - 1]; else { dp[i][j] = max(dp[i - w[j]][j - 1] + v[j], dp[i][j - 1]); } } } cout << dp[W][n] << endl; ret; } int main() { IOS; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin>>t; while (t--) { solve(); } ret; }
#include <bits/stdc++.h> #define rep1(i, n, a) for (int i = 0; i < n; i += a) #define rep2(i, n, a) for (int i = a; i < n; i++) #define rep3(n) for (int i = 0; i < n; i++) #define inarr(arr, n) rep1(i, n, 1) cin >> arr[i] #define ll long long int #define pb push_back #define all(v) v.begin(), v.end() #define trav(a, x) for (auto x : a) #define endl "\n" #define eb emplace_back #define fr first #define sc second #define gcd(a, b) __gcd(a, b) #define pres(a, x) a.find(x) != a.end() #define sz(a) (int)a.size() #define pii pair<int, int> #define psi pair<string, int> #define pss pair<string, string> #define pll pair<ll, ll> #define vec vector<int> #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ret return 0 #define pi 3.1415926536 #define hell 1000000007 #define narak 998244353 const int inf1 = 1e9; const ll inf2 = 1e18; const int N = 100000; using namespace std; int dirs[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; // syntax for min priority_queue of pairs // priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q; int solve() { ll n, W; cin >> n >> W; ll w[n + 1], v[n + 1]; rep3(n) cin >> w[i + 1] >> v[i + 1]; ll dp[W + 1][n + 1]; for (int i = 0; i <= W; i++) { for (int j = 0; j <= n; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (w[j] > i) dp[i][j] = dp[i][j - 1]; else { dp[i][j] = max(dp[i - w[j]][j - 1] + v[j], dp[i][j - 1]); } } } cout << dp[W][n] << endl; ret; } int main() { IOS; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int t = 1; // cin>>t; while (t--) { solve(); } ret; }
[ "variable_declaration.type.change" ]
967,148
967,149
u676474080
cpp
p03163
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; int main() { ll n, W; cin >> n >> W; vll w(n), v(n); rep(i, n) cin >> w[i] >> v[i]; vvll dp(101, vll(100010)); for (int i = 0; i < n; i++) { for (int j = 0; j <= W; j++) { if (w[i] >= j) { 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]); }
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; int main() { ll n, W; cin >> n >> W; vll w(n), v(n); rep(i, n) cin >> w[i] >> v[i]; vvll dp(110, vll(100010)); for (int i = 0; i < n; i++) { for (int j = 0; j <= W; j++) { if (w[i] <= j) { 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]); }
[ "literal.number.change", "call.arguments.change", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
967,150
967,151
u103850114
cpp
p03163
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; int main() { ll n, W; cin >> n >> W; vll w(n), v(n); rep(i, n) cin >> w[i] >> v[i]; vvll dp(101, vll(100010)); for (int i = 0; i < n; i++) { for (int j = 0; j < 100010; j++) { if (w[i] >= j) { 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]); }
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <string> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORR(i, a, b) for (ll i = (a); i <= (b); i++) #define repR(i, n) for (ll i = n; i >= 0; i--) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define F first #define S second #define pb push_back #define pu push #define COUT(x) cout << (x) << endl #define PQ priority_queue<ll> #define PQR priority_queue<ll, vector<ll>, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define mp make_pair #define maxs(x, y) (x = max(x, y)) #define mins(x, y) (x = min(x, y)) #define sz(x) (int)(x).size() typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll MOD = 1000000007LL; const ll INF = 1LL << 60; using vll = vector<ll>; using vb = vector<bool>; using vvb = vector<vb>; using vvll = vector<vll>; using vstr = vector<string>; using pll = pair<ll, ll>; using vc = vector<char>; using vvc = vector<vc>; ll dx[4] = {0, 1, 0, -1}; ll dy[4] = {1, 0, -1, 0}; int main() { ll n, W; cin >> n >> W; vll w(n), v(n); rep(i, n) cin >> w[i] >> v[i]; vvll dp(110, vll(100010)); for (int i = 0; i < n; i++) { for (int j = 0; j <= W; j++) { if (w[i] <= j) { 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]); }
[ "literal.number.change", "call.arguments.change", "control_flow.loop.for.condition.change", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
967,152
967,151
u103850114
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define rp(i, s, e) for (int i = (s); i < (e); ++i) int main() { int n, w; cin >> n >> w; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } vector<vector<int>> dp(n + 100, vector<int>(w + 100)); for (int i = 0; i < n; i++) { for (int j = 0; j < w + 10; j++) { if (j >= a[i]) { dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i]] + b[i]); } else { dp[i + 1][j] = dp[i][j]; } } } cout << dp[n][w] << endl; }
#include <bits/stdc++.h> using namespace std; #define rp(i, s, e) for (int i = (s); i < (e); ++i) int main() { int n, w; cin >> n >> w; vector<int> a(n); vector<int> b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } vector<vector<long long>> dp(n + 100, vector<long long>(w + 100)); for (int i = 0; i < n; i++) { for (int j = 0; j < w + 10; j++) { if (j >= a[i]) { dp[i + 1][j] = max(dp[i][j], dp[i][j - a[i]] + b[i]); } else { dp[i + 1][j] = dp[i][j]; } } } cout << dp[n][w] << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
967,153
967,154
u103850114
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) typedef long long ll; int main() { int N, W; cin >> N >> W; int w[N], v[N]; REP(i, N) cin >> w[i] >> v[i]; int dp[N + 1][W + 1]; REP(i, N + 1) REP(j, W + 1) dp[i][j] = 0; REP(i, N) REP(j, W + 1) { dp[i + 1][j] = dp[i][j]; if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]); } } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) typedef long long ll; int main() { int N, W; cin >> N >> W; int w[N], v[N]; REP(i, N) cin >> w[i] >> v[i]; ll dp[N + 1][W + 1]; REP(i, N + 1) REP(j, W + 1) dp[i][j] = 0; REP(i, N) REP(j, W + 1) { dp[i + 1][j] = dp[i][j]; if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]); } } cout << dp[N][W] << endl; }
[ "variable_declaration.type.change" ]
967,167
967,168
u303884911
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define endl '\n' typedef long long ll; int n; ll peso; ll dp[102][100005], w[100005], v[100005]; ll f(int i, ll p) { if (i == 0 || p <= 0) return 0; if (w[i] > p) return dp[i][p] = f(i - 1, p); if (dp[i][p] != -1) return dp[i][p]; return dp[i][p] = max(f(i - 1, p), f(i - 1, p - w[i]) + v[i]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> peso; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int i = 1; i <= 100; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = -1; } } cout << f(n, peso) << endl; }
#include <bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define endl '\n' typedef long long ll; int n; ll peso; ll dp[102][100005], w[100005], v[100005]; ll f(int i, ll p) { // cout << i << " " << p << endl; if (i == 0 || p <= 0) return 0; if (w[i] > p) return dp[i][p] = f(i - 1, p); if (dp[i][p] != -1) return dp[i][p]; return dp[i][p] = max(f(i - 1, p), f(i - 1, p - w[i]) + v[i]); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> peso; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int i = 1; i <= 100; i++) { for (int j = 1; j <= 100000; j++) { dp[i][j] = -1; } } cout << f(n, peso) << endl; }
[ "identifier.replace.remove", "literal.replace.add", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
967,169
967,170
u673781079
cpp
p03163
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(n, i) for (int i = n - 1; i >= 0; --i) #define PI 3.14159265 #define INF 1e9 using namespace std; using ll = long long; void self_max(int &a, int b) { a = max(a, b); } void self_min(int &a, int b) { a = min(a, b); } int main() { int n, w; cin >> n >> w; vector<int> h(n), we(n); rep(i, n) { cin >> h[i] >> we[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(w + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j >= h[i]) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - h[i]] + we[i]); } else { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } } cout << dp[n][w] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(n, i) for (int i = n - 1; i >= 0; --i) #define PI 3.14159265 #define INF 1e9 using namespace std; using ll = long long; void self_max(int &a, int b) { a = max(a, b); } void self_min(int &a, int b) { a = min(a, b); } int main() { int n, w; cin >> n >> w; vector<int> h(n), we(n); rep(i, n) { cin >> h[i] >> we[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(w + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j >= h[i]) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - h[i]] + we[i]); } else { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } } cout << dp[n][w] << endl; return 0; }
[]
967,172
967,173
u366686355
cpp
p03163
#include <bits/stdc++.h> #define ll long long #define ii pair<ll, ll> #define vi vector<ll> #define vii vector<ii> #define vs vector<string> #define si set<ll> #define endl "\n" #define pb push_back #define x first #define y second // g++ -std=c++11 -Wall -Wextra -pedantic-errors main.cpp -o main const int ms = 1e3 + 5, base = 31, mod = 1e9 + 7; using namespace std; int N = 105, P = 1e5; int dp[105][100005]; vector<int> weight, value; si uses; int bt(int i, int j) { // Get items if (i - 1 < 0) return 0; if (dp[i][j] == dp[i - 1][j]) { return bt(i - 1, j); } uses.insert(i); return bt(i - 1, j - weight[i]) + 1; } int main() { cin >> N >> P; weight.push_back(0); value.push_back(0); memset(dp, 0, sizeof(dp)); for (int i = 0; i <= N; i++) { int w, v; cin >> w >> v; weight.push_back(w); value.push_back(v); } for (int i = 0; i <= N; i++) { // Iterative part for (int j = 0; j <= P; j++) { int a, b; (i > 0) ? a = dp[i - 1][j] : a = 0; (i > 0 && j - weight[i] >= 0) ? b = dp[i - 1][j - weight[i]] + value[i] : b = 0; dp[i][j] = max(a, b); } } cout << dp[N][P] << endl; return 0; cout << "Max value: " << dp[N][P] << endl; cout << "Number of itens in the bag: " << bt(N, P) << endl; for (int i : uses) cout << "Weight: " << weight[i] << " Value: " << value[i] << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define ii pair<ll, ll> #define vi vector<ll> #define vii vector<ii> #define vs vector<string> #define si set<ll> #define endl "\n" #define pb push_back #define x first #define y second // g++ -std=c++11 -Wall -Wextra -pedantic-errors main.cpp -o main const int ms = 1e3 + 5, base = 31, mod = 1e9 + 7; using namespace std; int N = 105, P = 1e5; ll dp[105][100005]; vector<ll> weight, value; si uses; int bt(int i, ll j) { // Get items if (i - 1 < 0) return 0; if (dp[i][j] == dp[i - 1][j]) { return bt(i - 1, j); } uses.insert(i); return bt(i - 1, j - weight[i]) + 1; } int main() { cin >> N >> P; weight.push_back(0); value.push_back(0); memset(dp, 0, sizeof(dp)); for (int i = 0; i <= N; i++) { ll w, v; cin >> w >> v; weight.push_back(w); value.push_back(v); } for (int i = 0; i <= N; i++) { // Iterative part for (int j = 0; j <= P; j++) { ll a, b; (i > 0) ? a = dp[i - 1][j] : a = 0; (i > 0 && j - weight[i] >= 0) ? b = dp[i - 1][j - weight[i]] + value[i] : b = 0; dp[i][j] = max(a, b); } } cout << dp[N][P] << endl; return 0; cout << "Max value: " << dp[N][P] << endl; cout << "Number of itens in the bag: " << bt(N, P) << endl; for (int i : uses) cout << "Weight: " << weight[i] << " Value: " << value[i] << endl; return 0; }
[ "variable_declaration.type.change" ]
967,178
967,179
u772495372
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld double #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define pb emplace_back #define X first #define Y second const int N = 2e5 + 5; typedef pair<int, int> ii; int f[105][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int W; cin >> W; for (int i = 1; i <= n; ++i) { int w; cin >> w; int v; cin >> v; for (int j = 0; j <= W; ++j) f[i][j] = f[i - 1][j]; for (int j = w; j <= W; ++j) f[i][j] = max(f[i][j], f[i - 1][j - w] + v); } cout << f[n][W]; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld double #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define pb emplace_back #define X first #define Y second const int N = 2e5 + 5; typedef pair<int, int> ii; ll f[105][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int W; cin >> W; for (int i = 1; i <= n; ++i) { int w; cin >> w; int v; cin >> v; for (int j = 0; j <= W; ++j) f[i][j] = f[i - 1][j]; for (int j = w; j <= W; ++j) f[i][j] = max(f[i][j], f[i - 1][j - w] + v); } cout << f[n][W]; }
[ "variable_declaration.type.change" ]
967,180
967,181
u466655539
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, w; cin >> n >> w; ll wt[n], val[n], i, j; for (i = 0; i < n; i++) cin >> wt[i] >> val[i]; ll dp[n + 1][w + 1]; for (i = 0; i <= n; i++) { for (j = 0; j <= w; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][w - wt[i - 1]] + val[i - 1], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, w; cin >> n >> w; ll wt[n], val[n], i, j; for (i = 0; i < n; i++) cin >> wt[i] >> val[i]; ll dp[n + 1][w + 1]; for (i = 0; i <= n; i++) { for (j = 0; j <= w; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j - wt[i - 1]] + val[i - 1], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; return 0; }
[ "assignment.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
967,182
967,183
u939889620
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define ALL(v) v.begin(), v.end() typedef long long ll; typedef pair<int, int> P; const int INF = 1000000005; int dp[101][100001]; int main() { int N, W; cin >> N >> W; vector<int> v(N), w(N); rep(i, N) { cin >> w[i] >> v[i]; } fill(dp[0], dp[N + 1], 0); rep(i, N) { rep(j, W + 1) { if (j - w[i] < 0) dp[i + 1][j] = dp[i][j]; else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); // cout<<dp[i+1][j]<<endl; } } int ans = 0; cout << dp[N][W] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; ++i) #define ALL(v) v.begin(), v.end() typedef long long ll; typedef pair<int, int> P; const int INF = 1000000005; ll dp[101][100001]; int main() { ll N, W; cin >> N >> W; vector<ll> v(N), w(N); rep(i, N) { cin >> w[i] >> v[i]; } fill(dp[0], dp[N + 1], 0); rep(i, N) { rep(j, W + 1) { if (j - w[i] < 0) dp[i + 1][j] = dp[i][j]; else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); // cout<<dp[i+1][j]<<endl; } } ll ans = 0; cout << dp[N][W] << endl; return 0; }
[ "variable_declaration.type.change" ]
967,184
967,185
u184929210
cpp
p03163
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; vi weights, vals; int main() { int n, w; cin >> n >> w; weights.resize(n + 1); vals.resize(n + 1); for (int i = 1; i <= n; i++) { cin >> weights[i] >> vals[i]; } vector<vi> dp; dp.resize(n + 1); for (int i = 0; i <= n; i++) { dp[i].resize(w + 1); } for (int item = 1; item <= n; item++) { for (int wei = 0; wei <= w; wei++) { if (wei >= weights[item]) { dp[item][wei] = max(vals[item] + dp[item - 1][wei - weights[item]], dp[item - 1][wei]); } else { dp[item][wei] = dp[item - 1][wei]; } } } cout << dp[n][w]; return 0; }
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; vi weights, vals; int main() { int n, w; cin >> n >> w; weights.resize(n + 1); vals.resize(n + 1); for (int i = 1; i <= n; i++) { cin >> weights[i] >> vals[i]; } vector<vector<ll>> dp; dp.resize(n + 1); for (int i = 0; i <= n; i++) { dp[i].resize(w + 1); } for (int item = 1; item <= n; item++) { for (int wei = 0; wei <= w; wei++) { if (wei >= weights[item]) { dp[item][wei] = max(vals[item] + dp[item - 1][wei - weights[item]], dp[item - 1][wei]); } else { dp[item][wei] = dp[item - 1][wei]; } } } cout << dp[n][w]; return 0; }
[]
967,186
967,187
u058183675
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define mp make_pair #define pb push_back #define pf push_front #define speed_up ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define debug cerr << "OK\n"; #define ub upper_bound #define lb lower_bound #define treap_pair pair<treap *, treap *> typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef set<int> si; typedef set<ll> sll; typedef multiset<int> msi; typedef multiset<ll> msll; typedef map<int, int> mi; typedef map<ll, ll> mll; const int N = 1e5 + 2; const int M = 1e5 + 2; const int mod = 1e9 + 7; const int inf = 1e9; const ll INF = 1e18 + 100; void data() { #ifdef PC freopen("main.in", "r", stdin); freopen("main.out", "w", stdout); #endif } template <typename T> void scerr(T nums) { for (auto it : nums) cerr << it << " | "; cerr << "\n"; } ll n, c, w[N], v[N], dp[N], ans = -INF; int main() { data(); scanf("%lld %lld", &n, &c); for (int i = 1; i <= n; ++i) scanf("%lld %lld", &w[i], &v[i]); for (int i = 0; i < N; ++i) dp[i] = -INF; dp[0] = 0; for (int i = 1; i <= n; ++i) for (int j = c; j >= 0; --j) if (j >= w[i]) dp[j] = max(dp[j - w[i]] + v[i], dp[j]); for (int i = c; i >= 0; --i) ans = max(ans, dp[i]); printf("%d", ans); } /* Timus: 288481RF CodeForces: fractal */
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define mp make_pair #define pb push_back #define pf push_front #define speed_up ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define debug cerr << "OK\n"; #define ub upper_bound #define lb lower_bound #define treap_pair pair<treap *, treap *> typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef set<int> si; typedef set<ll> sll; typedef multiset<int> msi; typedef multiset<ll> msll; typedef map<int, int> mi; typedef map<ll, ll> mll; const int N = 1e5 + 2; const int M = 1e5 + 2; const int mod = 1e9 + 7; const int inf = 1e9; const ll INF = 1e18 + 100; void data() { #ifdef PC freopen("main.in", "r", stdin); freopen("main.out", "w", stdout); #endif } template <typename T> void scerr(T nums) { for (auto it : nums) cerr << it << " | "; cerr << "\n"; } ll n, c, w[N], v[N], dp[N], ans = -INF; int main() { data(); scanf("%lld %lld", &n, &c); for (int i = 1; i <= n; ++i) scanf("%lld %lld", &w[i], &v[i]); for (int i = 0; i < N; ++i) dp[i] = -INF; dp[0] = 0; for (int i = 1; i <= n; ++i) for (int j = c; j >= 0; --j) if (j >= w[i]) dp[j] = max(dp[j - w[i]] + v[i], dp[j]); for (int i = c; i >= 0; --i) ans = max(ans, dp[i]); printf("%lld", ans); } /* Timus: 288481RF CodeForces: fractal */
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
967,191
967,192
u426777622
cpp
p03163
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #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 << endl; } 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__) << "] " #define pb push_back #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; void solve(); const int N = 1e5 + 10; int main() { fast_cin(); int t = 1; // cin >> t; while (t--) { solve(); } } void solve() { int n, w; cin >> n >> w; // int a[N]; // for (int i=1; i <= n; i++) { // cin >> a[i]; // } vector<int> dp(N, 0); for (int i = 1; i <= n; i++) { int weight, value; cin >> weight >> value; for (int j = w - weight; j >= 0; j--) { dp[j + weight] = max(dp[j + weight], dp[j] + value); } } cout << dp[w] << '\n'; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #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 << endl; } 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__) << "] " #define pb push_back #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; void solve(); const int N = 1e5 + 10; int main() { fast_cin(); int t = 1; // cin >> t; while (t--) { solve(); } } void solve() { int n, w; cin >> n >> w; // int a[N]; // for (int i=1; i <= n; i++) { // cin >> a[i]; // } vector<ll> dp(N, 0); for (int i = 1; i <= n; i++) { int weight, value; cin >> weight >> value; for (int j = w - weight; j >= 0; j--) { dp[j + weight] = max(dp[j + weight], dp[j] + value); } } cout << dp[w] << '\n'; }
[]
967,201
967,202
u255532979
cpp
p03163
/* Those who cannot remember the past are condemned to repeat it.*/ /* author:Ajeet */ #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; #define ll long long int #define pb push_back #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) const int sz = 1e7; #define mod 1000000007 #define ull unsigned long long int int main() { int n; cin >> n; int w; cin >> w; int weight[n], profit[n]; for (int i = 0; i < n; i++) cin >> weight[i] >> profit[i]; int dp[n + 1][w + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { int weightWithoutCurr = dp[i - 1][j]; int weightWithCurr = 0; int currWeight = weight[i - 1]; if (i == 0 or j == 0) { dp[i][j] = 0; continue; } else if (currWeight <= j) { weightWithCurr = profit[i - 1]; int remain = j - currWeight; weightWithCurr += dp[i - 1][remain]; } dp[i][j] = max(weightWithoutCurr, weightWithCurr); } } // for(int i=0;i<=n;i++) // { // for(int j=0;j<=w;j++){ // cout<<dp[i][j]<<" "; // } // cout<<endl; // } cout << dp[n][w] << endl; return 0; }
/* Those who cannot remember the past are condemned to repeat it.*/ /* author:Ajeet */ #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> using namespace std; #define ll long long int #define pb push_back #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) const int sz = 1e7; #define mod 1000000007 #define ull unsigned long long int int main() { int n; cin >> n; int w; cin >> w; ll weight[n], profit[n]; for (int i = 0; i < n; i++) cin >> weight[i] >> profit[i]; ll dp[n + 1][w + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { ll weightWithoutCurr = dp[i - 1][j]; ll weightWithCurr = 0; ll currWeight = weight[i - 1]; if (i == 0 or j == 0) { dp[i][j] = 0; continue; } else if (currWeight <= j) { weightWithCurr = profit[i - 1]; ll remain = j - currWeight; weightWithCurr += dp[i - 1][remain]; } dp[i][j] = max(weightWithoutCurr, weightWithCurr); } } cout << dp[n][w] << endl; return 0; }
[ "variable_declaration.type.change" ]
967,205
967,206
u348641375
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define MAXN 105 #define MAXW 100005 int memo[MAXN][MAXW]; vector<int> values, weights; int N, W; long long knap(int curr, int wRim) { if (memo[curr][wRim] != -1) return memo[curr][wRim]; if (curr == N) return 0; long long tot = knap(curr + 1, wRim); if (wRim - weights[curr] >= 0) tot = max(tot, values[curr] + knap(curr + 1, wRim - weights[curr])); return memo[curr][wRim] = tot; } int main() { cin >> N >> W; int tempv, tempw; for (int i = 0; i < N; i++) { cin >> tempw >> tempv; values.push_back(tempv); weights.push_back(tempw); } memset(memo, -1, sizeof memo); cout << knap(0, W); }
#include <bits/stdc++.h> using namespace std; #define MAXN 105 #define MAXW 100005 long long memo[MAXN][MAXW]; vector<int> values, weights; int N, W; long long knap(int curr, int wRim) { if (memo[curr][wRim] != -1) return memo[curr][wRim]; if (curr == N) return 0; long long tot = knap(curr + 1, wRim); if (wRim - weights[curr] >= 0) tot = max(tot, values[curr] + knap(curr + 1, wRim - weights[curr])); return memo[curr][wRim] = tot; } int main() { cin >> N >> W; int tempv, tempw; for (int i = 0; i < N; i++) { cin >> tempw >> tempv; values.push_back(tempv); weights.push_back(tempw); } memset(memo, -1, sizeof memo); cout << knap(0, W); }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
967,237
967,238
u172805707
cpp
p03163
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n - 1); i >= 0; i--) #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define br cout << endl; using namespace std; const int INF = 1e9; const int MOD = 1e9 + 7; using Graph = vector<vector<ll>>; 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; } // 0 false, 1 true // stringの数字をint型にしてアスキーコードになったら -48する // 切り上げ ceil(a) int main() { ll n, w; cin >> n >> w; vector<ll> weight(n); vector<ll> value(n); vector<vector<ll>> dp(n + 1, vector<ll>(w + 1)); rep(i, n) { cin >> weight.at(i) >> value.at(i); } rep(i, n) { for (ll sum_w = 0; sum_w <= w; sum_w++) { if (sum_w - weight.at(i) >= 0) { chmax(dp.at(i + 1).at(sum_w), dp.at(i).at(sum_w - weight.at(i)) + value.at(i)); } else { chmax(dp.at(i + 1).at(sum_w), dp.at(i).at(sum_w)); } } } cout << dp.at(n).at(w) << endl; }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n - 1); i >= 0; i--) #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define br cout << endl; using namespace std; const int INF = 1e9; const int MOD = 1e9 + 7; using Graph = vector<vector<ll>>; 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; } // 0 false, 1 true // stringの数字をint型にしてアスキーコードになったら -48する // 切り上げ ceil(a) int main() { ll n, w; cin >> n >> w; vector<ll> weight(n); vector<ll> value(n); vector<vector<ll>> dp(n + 1, vector<ll>(w + 1)); rep(i, n) { cin >> weight.at(i) >> value.at(i); } rep(i, n) { for (ll sum_w = 0; sum_w <= w; sum_w++) { if (sum_w - weight.at(i) >= 0) { chmax(dp.at(i + 1).at(sum_w), dp.at(i).at(sum_w - weight.at(i)) + value.at(i)); } chmax(dp.at(i + 1).at(sum_w), dp.at(i).at(sum_w)); } } cout << dp.at(n).at(w) << endl; }
[]
967,256
967,257
u799939777
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = long long; ll max(ll a, ll b) { return a > b ? a : b; } int main() { int n, W; cin >> n >> W; vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, 0)); for (int i = 1; i <= n; i++) { int wt, v; cin >> wt >> v; for (int w = 0; w <= W; w++) { dp[i][w] = dp[i - 1][w]; if (w >= wt) dp[i][w] = max(dp[i][w], v + dp[i - 1][w - wt]); } } ll ans = 0; for (int a : dp[n]) { ans = max(ans, a); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; ll max(ll a, ll b) { return a > b ? a : b; } int main() { int n, W; cin >> n >> W; vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, 0)); for (int i = 1; i <= n; i++) { int wt, v; cin >> wt >> v; for (int w = 0; w <= W; w++) { dp[i][w] = dp[i - 1][w]; if (w >= wt) dp[i][w] = max(dp[i][w], v + dp[i - 1][w - wt]); } } ll ans = 0; for (ll a : dp[n]) { ans = max(ans, a); } cout << ans << endl; }
[ "variable_declaration.type.widen.change" ]
967,262
967,263
u493143669
cpp
p03163
// Author : Radhesh Sarma #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define rep(i, a, b) for (int i = a; i <= b; i++) #define rep2(i, a, b) for (int i = a; i >= b; i--) #define f first #define s second #define PB push_back #define MP make_pair #define db long double #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) #define INF 2000000000 const double PI = acos(-1); const int N = 200005; int dp[N]; int wt[105]; int v[105]; bool vis[105]; int32_t main() { IOS // dp[i] denotes the maximum possible sum of values that can be in // Knapsack of weight i dp[0] = 0; // using backward dp to prevent double counting int n, W; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> wt[i] >> v[i]; } for (int i = 1; i <= 2; i++) { for (int j = W; j >= 0; j--) { if (j + wt[i] <= W) dp[j + wt[i]] = max(dp[j + wt[i]], dp[j] + v[i]); } } cout << dp[W]; return 0; }
// Author : Radhesh Sarma #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define rep(i, a, b) for (int i = a; i <= b; i++) #define rep2(i, a, b) for (int i = a; i >= b; i--) #define f first #define s second #define PB push_back #define MP make_pair #define db long double #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) #define INF 2000000000 const double PI = acos(-1); const int N = 200005; int dp[N]; int wt[105]; int v[105]; bool vis[105]; int32_t main() { IOS // dp[i] denotes the maximum possible sum of values that can be in // Knapsack of weight i dp[0] = 0; // dp[i] = max(dp[i],dp[i-w[j]] + v[j]) int n, W; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> wt[i] >> v[i]; } for (int i = 1; i <= n; i++) { for (int j = W; j >= 0; j--) { if (j + wt[i] <= W) dp[j + wt[i]] = max(dp[j + wt[i]], dp[j] + v[i]); } } cout << dp[W]; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
967,278
967,279
u021648187
cpp