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
p03164
#include "bits/stdc++.h" using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") // wierd debugging stuff #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << "\n"; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " // end of weird debugging stuff typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ll> vll; typedef vector<vector<int>> vvi; #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define F_OR(i, a, b, s) \ for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define foe(i, x) for (auto &i : x) #define ar array #define pb push_back #define vt vector #define F first #define S second template <class T> bool umin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool umax(T &a, const T &b) { return b > a ? a = b, 1 : 0; } template <class A> void read(vt<A> &v); template <class A, size_t S> void read(ar<A, S> &a); template <class T> void read(T &x) { cin >> x; } void read(double &d) { string t; read(t); d = stod(t); } void read(long double &d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } template <class A> void read(vt<A> &x) { foe(a, x) read(a); } int nxt() { int a; cin >> a; return a; } // no change const ll MOD = 1e9 + 7; int n; const int mx = 2e5 + 1; void Titan() { int w; read(n, w); vll W(n), V(n); fo(n) { cin >> W[i] >> V[i]; } ll sum_values = 0; fo(n) { sum_values += V[i]; } const ll inf = 1e18l + 1; vll dp(sum_values + 1, inf); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = sum_values - V[i]; j >= 0; --j) { // for(int j = 98values - V[i];j++){ umin(dp[j + V[i]], dp[j] + W[i]); } } ll ans = 0; fo(sum_values) { if (dp[i] <= w) umax(ans, (ll)i); } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; // cin >> T; //cmt if one test case fo(T) { // cout << "Case #" << i+1 << ": " ; Titan(); } } /*/////////////////////////////////////////////////////////// Important Notes : * check long long * check base cases * do not loose Hope * if case fails on 2nd test case maybe some cases are missing check them * do not sit idle * try to do it using pen/paper. */
#include "bits/stdc++.h" using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") // wierd debugging stuff #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << "\n"; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " // end of weird debugging stuff typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ll> vll; typedef vector<vector<int>> vvi; #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define F_OR(i, a, b, s) \ for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define fo(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define foe(i, x) for (auto &i : x) #define ar array #define pb push_back #define vt vector #define F first #define S second template <class T> bool umin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template <class T> bool umax(T &a, const T &b) { return b > a ? a = b, 1 : 0; } template <class A> void read(vt<A> &v); template <class A, size_t S> void read(ar<A, S> &a); template <class T> void read(T &x) { cin >> x; } void read(double &d) { string t; read(t); d = stod(t); } void read(long double &d) { string t; read(t); d = stold(t); } template <class H, class... T> void read(H &h, T &...t) { read(h); read(t...); } template <class A> void read(vt<A> &x) { foe(a, x) read(a); } int nxt() { int a; cin >> a; return a; } // no change const ll MOD = 1e9 + 7; int n; const int mx = 2e5 + 1; void Titan() { ll w; read(n, w); vll W(n), V(n); fo(n) { cin >> W[i] >> V[i]; } ll sum_values = 0; fo(n) { sum_values += V[i]; } const ll inf = 1e18l + 1; vll dp(sum_values + 1, inf); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = sum_values - V[i]; j >= 0; --j) { // for(int j = 98values - V[i];j++){ umin(dp[j + V[i]], dp[j] + W[i]); } } ll ans = 0; fo(sum_values + 1) { if (dp[i] <= w) umax(ans, (ll)i); } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; // cin >> T; //cmt if one test case fo(T) { // cout << "Case #" << i+1 << ": " ; Titan(); } } /*/////////////////////////////////////////////////////////// Important Notes : * check long long * check base cases * do not loose Hope * if case fails on 2nd test case maybe some cases are missing check them * do not sit idle * try to do it using pen/paper. */
[ "variable_declaration.type.change", "io.output.newline.add" ]
969,372
969,371
u161309389
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18l + 5; int main() { int n, W; cin >> n >> W; vector<ll> dp(10005, INF); dp[0] = 0; for (int i = 0; i < n; ++i) { int v, w; cin >> w >> v; for (int j = 10005 - v; j >= 0; --j) { dp[v + j] = min(dp[v + j], dp[j] + w); } } ll ans = 0; for (ll i = 0; i <= 10005; ++i) { if (dp[i] <= W) ans = max(i, ans); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18l + 5; int main() { int n, W; cin >> n >> W; vector<ll> dp(100005, INF); dp[0] = 0; for (int i = 0; i < n; ++i) { int v, w; cin >> w >> v; for (int j = 100005 - v; j >= 0; --j) { dp[v + j] = min(dp[v + j], dp[j] + w); } } ll ans = 0; for (ll i = 0; i < 100005; ++i) { if (dp[i] <= W) ans = max(i, ans); } cout << ans << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "control_flow.loop.for.initializer.change", "expression.operation.binary.change", "control_flow.loop.for.condition.change" ]
969,375
969,374
u741042758
cpp
p03164
// CODE ยฉ by ๐•Œ๐•ฅ๐•œ๐•’๐•ฃ๐•ค๐•™ ๐”พ๐•’๐•ฃ๐•˜ // Copying or sharing of this code without permission of the Author is strictly // prohibited!!! #include <bits/stdc++.h> using namespace std; #define ll long long #define mx 1000000009 int main() { ll n, W; cin >> n >> W; ll v[n + 1], w[n + 1]; ll sum = 0; for (ll i = 1; i <= n; i++) { cin >> v[i] >> w[i]; } for (ll i = 1; i <= n; i++) sum += v[i]; ll dp[sum + 1]; // memset(dp, ll_MAX, sizeof(dp)); for (ll i = 1; i <= sum; i++) dp[i] = mx; dp[0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = sum; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } for (ll i = sum; i >= 0; i--) { if (dp[i] <= W) { cout << i; break; } } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mx 1000000009 int main() { ll n, W; cin >> n >> W; ll v[n + 1], w[n + 1]; ll sum = 0; for (ll i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (ll i = 1; i <= n; i++) sum += v[i]; ll dp[sum + 1]; // memset(dp, ll_MAX, sizeof(dp)); for (ll i = 1; i <= sum; i++) dp[i] = mx; dp[0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = sum; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } for (ll i = sum; i >= 0; i--) { if (dp[i] <= W) { cout << i; break; } } }
[ "expression.operation.binary.remove" ]
969,376
969,377
u279896753
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n, W, s = 0; cin >> n >> W; vector<int> w(n), c(n); for (int i = 0; i < n; i++) { cin >> w[i] >> c[i]; s += c[i]; } vector<int> dp(s + 1, INT_MAX); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = s - c[i]; j >= 0; j--) { dp[j + c[i]] = min(dp[j] + c[i], dp[j] + w[i]); } } int ans = 0; for (int i = 0; i <= s; i++) { if (dp[i] <= W) { ans = i; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n, W, s = 0; cin >> n >> W; vector<int> w(n), c(n); for (int i = 0; i < n; i++) { cin >> w[i] >> c[i]; s += c[i]; } vector<int> dp(s + 1, INT_MAX); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = s - c[i]; j >= 0; j--) { dp[j + c[i]] = min(dp[j + c[i]], dp[j] + w[i]); } } int ans = 0; for (int i = 0; i <= s; i++) { if (dp[i] <= W) { ans = i; } } cout << ans; return 0; }
[ "call.arguments.change" ]
969,382
969,383
u345762875
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 105, W = 1e9 + 5, V = 1e3 + 5, INF = 1e9 + 5; ll dp[N][N * V]; int main() { ios_base::sync_with_stdio(0); cin.tie(); int n, w; cin >> n >> w; fill(dp[0], dp[0] + N * V, INF); dp[0][0] = 0; for (int i = 1; i <= n; i++) { int wi, vi; cin >> wi >> vi; for (int j = 0; j < wi; j++) dp[i][j] = dp[i - 1][j]; for (int j = vi; j < N * V; j++) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - vi] + wi); } for (int i = N * V - 1; i >= 0; i--) if (dp[n][i] <= w) { cout << i << "\n"; return 0; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 105, W = 1e9 + 5, V = 1e3 + 5, INF = 1e9 + 5; ll dp[N][N * V]; int main() { ios_base::sync_with_stdio(0); cin.tie(); int n, w; cin >> n >> w; fill(dp[0], dp[0] + N * V, INF); dp[0][0] = 0; for (int i = 1; i <= n; i++) { int wi, vi; cin >> wi >> vi; for (int j = 0; j < vi; j++) dp[i][j] = dp[i - 1][j]; for (int j = vi; j < N * V; j++) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - vi] + wi); } for (int i = N * V - 1; i >= 0; i--) if (dp[n][i] <= w) { cout << i << "\n"; return 0; } }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
969,384
969,385
u319048282
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 105, W = 1e9 + 5, V = 1e3 + 5, INF = 1e9 + 5; ll dp[N][N * V]; int main() { ios_base::sync_with_stdio(0); cin.tie(); int n, w; cin >> n >> w; fill(dp[0], dp[0] + N * V, INF); dp[0][0] = 0; for (int i = 1; i <= n; i++) { int wi, vi; cin >> wi >> vi; for (int j = 0; j < wi; j++) dp[i][j] = dp[i - 1][j]; for (int j = wi; j < N * V; j++) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - wi] + vi); } for (int i = N * V - 1; i >= 0; i--) if (dp[n][i] <= w) { cout << i << "\n"; return 0; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 105, W = 1e9 + 5, V = 1e3 + 5, INF = 1e9 + 5; ll dp[N][N * V]; int main() { ios_base::sync_with_stdio(0); cin.tie(); int n, w; cin >> n >> w; fill(dp[0], dp[0] + N * V, INF); dp[0][0] = 0; for (int i = 1; i <= n; i++) { int wi, vi; cin >> wi >> vi; for (int j = 0; j < vi; j++) dp[i][j] = dp[i - 1][j]; for (int j = vi; j < N * V; j++) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - vi] + wi); } for (int i = N * V - 1; i >= 0; i--) if (dp[n][i] <= w) { cout << i << "\n"; return 0; } }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change" ]
969,386
969,385
u319048282
cpp
p03164
#include <bits/stdc++.h> using namespace std; long long dp[101][100002]; int main() { long long N, W; cin >> N >> W; long long w[N + 1]; long long v[N + 1]; long long V = 100001; w[0] = 0, v[0] = 0; for (long long i = 1; i <= N; ++i) { cin >> w[i] >> v[i]; } for (long long i = 0; i <= N; ++i) { for (long long j = 0; j <= V; ++j) { dp[i][j] = 10000000000001; } } // for(long long j=1;j<=V;++j){ // if(v[1]>=j){ dp[1][v[1]] = w[1]; // } // } dp[1][0] = 0; for (long long i = 2; i <= N; ++i) { for (long long j = 1; j <= V; ++j) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i]) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } } long long ans = 0; for (int j = 1; j <= V; ++j) { if (dp[N][j] <= W) ans = j; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long dp[101][100002]; int main() { long long N, W; cin >> N >> W; long long w[N + 1]; long long v[N + 1]; long long V = 100000; w[0] = 0, v[0] = 0; for (long long i = 1; i <= N; ++i) { cin >> w[i] >> v[i]; } for (long long i = 0; i <= N; ++i) { for (long long j = 0; j <= V; ++j) { dp[i][j] = 10000000000001; } } // for(long long j=1;j<=V;++j){ // if(v[1]>=j){ dp[1][v[1]] = w[1]; // } // } dp[1][0] = 0; for (long long i = 2; i <= N; ++i) { for (long long j = 0; j <= V; ++j) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i]) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } } long long ans = 0; for (int j = 1; j <= V; ++j) { if (dp[N][j] <= W) ans = j; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
969,401
969,402
u440697133
cpp
p03164
#include <bits/stdc++.h> using namespace std; long long dp[101][100001]; int main() { long long N, W; cin >> N >> W; long long w[N + 1]; long long v[N + 1]; long long V = 100001; w[0] = 0, v[0] = 0; for (long long i = 1; i <= N; ++i) { cin >> w[i] >> v[i]; } for (long long i = 0; i <= N; ++i) { for (long long j = 0; j <= V; ++j) { dp[i][j] = 10000000000001; } } // for(long long j=1;j<=V;++j){ // if(v[1]>=j){ dp[1][v[1]] = w[1]; // } // } dp[1][0] = 0; for (long long i = 2; i <= N; ++i) { for (long long j = 1; j <= V; ++j) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i]) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } } long long ans = 0; for (int j = 1; j <= V; ++j) { if (dp[N][j] <= W) ans = j; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; long long dp[101][100002]; int main() { long long N, W; cin >> N >> W; long long w[N + 1]; long long v[N + 1]; long long V = 100000; w[0] = 0, v[0] = 0; for (long long i = 1; i <= N; ++i) { cin >> w[i] >> v[i]; } for (long long i = 0; i <= N; ++i) { for (long long j = 0; j <= V; ++j) { dp[i][j] = 10000000000001; } } // for(long long j=1;j<=V;++j){ // if(v[1]>=j){ dp[1][v[1]] = w[1]; // } // } dp[1][0] = 0; for (long long i = 2; i <= N; ++i) { for (long long j = 0; j <= V; ++j) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i]) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } } long long ans = 0; for (int j = 1; j <= V; ++j) { if (dp[N][j] <= W) ans = j; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
969,403
969,402
u440697133
cpp
p03164
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define endl "\n" #define ll long long #define pb emplace_back #define fi first #define se second #define pll pair<ll, ll> #define ull unsigned long long #define ld long double #define debug(x) cout << #x << " :: " << x << endl; #define debug2(x, y) \ cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl; #define debug3(x, y, z) \ cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z \ << " :: " << z << endl; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define repa(i, a, b) for (ll i = (a); i <= (b); i++) #define all(x) (x).begin(), (x).end() #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> /* Ordered set docs: order_of_key (k) : Number of items strictly smaller than k . find_by_order(k) : K-th element in a set (counting from zero). */ #define blc boost::lexical_cast<long long> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; using namespace __gnu_pbds; const int MOD = 1e9 + 7; const ll INF = 1e18; ll add(ll x, ll y) { ll res = x + y; return (res >= MOD ? res - MOD : res); } ll sub(ll x, ll y) { ll res = x - y; return (res < 0 ? res + MOD : res); } ll lcm(ll x, ll y) { ll res = (x * y) / __gcd(x, y); return res; } ll powerLL(ll x, ll n, ll mod) { ll result = 1; while (n) { if (n & 1) result = (result % mod * x % mod) % mod; n = n / 2; x = (x % mod * x % mod) % mod; } return result; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void solve() { ll n, w; cin >> n >> w; vector<ll> wei(n); vector<ll> val(n); ll s = 0; rep(i, n) { cin >> wei[i] >> val[i]; s += val[i]; } ll dp[n + 1][s + 1]; rep(i, s + 1) dp[0][i] = INF; dp[0][0] = 0; ll maxi = 0; for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= s; j++) { if (val[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i - 1]] + wei[i - 1]); else dp[i][j] = dp[i - 1][j]; if (dp[i][j] <= w) maxi = max(maxi, j); } } cout << maxi << endl; } int32_t main() { fast; int t; t = 1; // cin>>t; while (t--) solve(); return 0; } /* 6 15 6 5 5 6 6 4 6 6 3 5 7 2 */
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define endl "\n" #define ll long long #define pb emplace_back #define fi first #define se second #define pll pair<ll, ll> #define ull unsigned long long #define ld long double #define debug(x) cout << #x << " :: " << x << endl; #define debug2(x, y) \ cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl; #define debug3(x, y, z) \ cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z \ << " :: " << z << endl; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = n - 1; i >= 0; i--) #define repa(i, a, b) for (ll i = (a); i <= (b); i++) #define all(x) (x).begin(), (x).end() #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> /* Ordered set docs: order_of_key (k) : Number of items strictly smaller than k . find_by_order(k) : K-th element in a set (counting from zero). */ #define blc boost::lexical_cast<long long> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; using namespace __gnu_pbds; const int MOD = 1e9 + 7; const ll INF = 1e18; ll add(ll x, ll y) { ll res = x + y; return (res >= MOD ? res - MOD : res); } ll sub(ll x, ll y) { ll res = x - y; return (res < 0 ? res + MOD : res); } ll lcm(ll x, ll y) { ll res = (x * y) / __gcd(x, y); return res; } ll powerLL(ll x, ll n, ll mod) { ll result = 1; while (n) { if (n & 1) result = (result % mod * x % mod) % mod; n = n / 2; x = (x % mod * x % mod) % mod; } return result; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void solve() { ll n, w; cin >> n >> w; vector<ll> wei(n); vector<ll> val(n); ll s = 0; rep(i, n) { cin >> wei[i] >> val[i]; s += val[i]; } ll dp[n + 5][s + 5]; rep(i, s + 5) dp[0][i] = INF; dp[0][0] = 0; ll maxi = 0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= s; j++) { if (val[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i - 1]] + wei[i - 1]); else dp[i][j] = dp[i - 1][j]; if (dp[i][j] <= w) maxi = max(maxi, j); } } cout << maxi << endl; } int32_t main() { fast; int t; t = 1; // cin>>t; while (t--) solve(); return 0; } /* 6 15 6 5 5 6 6 4 6 6 3 5 7 2 */
[ "literal.number.change", "expression.operation.binary.change", "assignment.variable.change", "call.arguments.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
969,434
969,435
u298511956
cpp
p03164
/* โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„ โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–„ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–Œโ–‘โ–Œ โ–โ–‘โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–Œ โ–โ–‘โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œ โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€ โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ */ //#pragma optimization_level 3 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <assert.h> #include <bitset> #include <chrono> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define pld pair<ld, ld> #define vi vector<int> #define vpi vector<pii> #define vld vector<ld> #define try tr #define left left11 #define right right11 #define lb lower_bound #define ub upper_bound #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define pb push_back #define pf push_front #define sqr(a) ((a) * (a)) #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define x first #define y second mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); clock_t START; inline ld TIME() { return (ld)(clock() - START) / CLOCKS_PER_SEC; } ld TL = 2.0; int calls = 0; inline bool IS() { if (++calls == 1000) { calls = 0; if (TL - TIME() < 0.1) return true; } return false; } template <typename T1, typename T2> inline void amin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 b) { if (a < b) a = b; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << p.first << ' ' << p.second << endl; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &u : v) is >> u; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto &u : v) os << u << ' '; os << endl; return os; } int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937}, mod = hash_mod[rnd() % 4]; int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4]; int binpow(int x, int p) { int res = 1; while (p) { if (p % 2) res = (res * x) % mod; x = (x * x) % mod; p /= 2; } return res; } const int N = 1e6 + 7, NS = 2e3 + 7, lg = 20, sq = 550, inf = 2e9 + 7, SM = 1e2 + 7; const ld eps = 1e-9; int a[N], b[N], d[N]; void solve() { int n, w; cin >> n >> w; fill(d + 1, d + N, inf); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; for (int j = N; j >= a[i]; j--) { amin(d[j], d[j - b[i]] + a[i]); } } int ans = 0; for (int i = 0; i < N; i++) { if (d[i] <= w) { amax(ans, i); } } cout << ans; } signed main() { fast solve(); }
/* โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„ โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–„ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–€โ–€โ–€โ–€โ–€โ–€โ–ˆโ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œโ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–„ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–Œโ–‘โ–Œ โ–โ–‘โ–โ–‘โ–Œ โ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œโ–โ–‘โ–ˆโ–„โ–„โ–„โ–„โ–„โ–„โ–„โ–ˆโ–‘โ–Œ โ–โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–Œ โ–โ–‘โ–‘โ–Œ โ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œโ–โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–Œ โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€ โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€โ–€ */ //#pragma optimization_level 3 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <algorithm> #include <assert.h> #include <bitset> #include <chrono> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define int long long #define ll long long #define ull unsigned long long #define ld long double #define pii pair<int, int> #define pld pair<ld, ld> #define vi vector<int> #define vpi vector<pii> #define vld vector<ld> #define try tr #define left left11 #define right right11 #define lb lower_bound #define ub upper_bound #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define pb push_back #define pf push_front #define sqr(a) ((a) * (a)) #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define x first #define y second mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); clock_t START; inline ld TIME() { return (ld)(clock() - START) / CLOCKS_PER_SEC; } ld TL = 2.0; int calls = 0; inline bool IS() { if (++calls == 1000) { calls = 0; if (TL - TIME() < 0.1) return true; } return false; } template <typename T1, typename T2> inline void amin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 b) { if (a < b) a = b; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> &p) { os << p.first << ' ' << p.second << endl; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &u : v) is >> u; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto &u : v) os << u << ' '; os << endl; return os; } int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937}, mod = hash_mod[rnd() % 4]; int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4]; int binpow(int x, int p) { int res = 1; while (p) { if (p % 2) res = (res * x) % mod; x = (x * x) % mod; p /= 2; } return res; } const int N = 1e6 + 7, NS = 2e3 + 7, lg = 20, sq = 550, inf = 2e9 + 7, SM = 1e2 + 7; const ld eps = 1e-9; int a[N], b[N], d[N]; void solve() { int n, w; cin >> n >> w; fill(d + 1, d + N, inf); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; for (int j = N; j >= b[i]; j--) { amin(d[j], d[j - b[i]] + a[i]); } } int ans = 0; for (int i = 0; i < N; i++) { if (d[i] <= w) { amax(ans, i); } } cout << ans; } signed main() { fast solve(); }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
969,436
969,437
u642506891
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define INF 1000000000000000007 int main() { int n, w; cin >> n >> w; vector<ll> weight(n); vector<ll> value(n); for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } ll sum = 0; for (int i = 0; i < n; i++) { sum += value[i]; } vector<ll> dp(sum + 1, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = sum - value[i]; j >= 0; j--) { dp[value[i] + j] = min(dp[value[i] + j], dp[j] + weight[i]); } } for (int i = sum; i >= 0; i++) { if (dp[i] <= w) { cout << i << endl; break; } } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define INF 1000000000000000007 int main() { int n, w; cin >> n >> w; vector<ll> weight(n); vector<ll> value(n); for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } ll sum = 0; for (int i = 0; i < n; i++) { sum += value[i]; } vector<ll> dp(sum + 1, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = sum - value[i]; j >= 0; j--) { dp[value[i] + j] = min(dp[value[i] + j], dp[j] + weight[i]); } } for (int i = sum; i >= 0; i--) { if (dp[i] <= w) { cout << i << endl; break; } } }
[]
969,442
969,443
u204158532
cpp
p03164
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //#include <boost/multiprecision/cpp_int.hpp> // // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; /*** Typedef ***/ typedef long long ll; typedef long long int lli; typedef unsigned long long ull; typedef long double ld; // typedef unordered_set<ll> usll; // typedef unordered_multiset<ll> umsll; /*** Loops ***/ #define ffit(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) #define F(a, b) for (int i = a; i < b; i++) #define ff1(i, a, b) for (ll i = a; i < b; i++) #define ff2(i, a, b) for (ll i = b - 1; i >= a; i--) #define ff3(i, a, b, m) for (ll i = a; i < b; i += m) #define ipar(ar, n) \ ll ar[n]; \ ff1(i, 0, n) cin >> ar[i]; #define opar(ar, n) ff1(i, 0, n) cout << ar[i] << " "; #define foRev(num) for (ll i = num - 1; i >= 0; i--) #define forIn(arr, num) \ for (ll i = 0; i < num; i++) \ sc1(arr[i]); #define forIn1(arr, num) \ for (ll i = 1; i <= num; i++) \ sc1(arr[i]); #define vpnt(ans) \ for (ll i = 0; i < ans.size(); i++) \ cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n'); #define apnt(arr, num) \ for (ll i = 0; i < num; i++) \ cout << arr[i] << (i + 1 < num ? ' ' : '\n'); /*** Define Values ***/ #define PI acos(-1.0) #define eps 1e-7 #define size1 15 /*** STLs ***/ #define cu continue #define br break #define rsz resize #define ins insert #define ft front #define bk back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define ff first #define ss second #define mp make_pair #define mem(name, value) memset(name, value, sizeof(name)) #define MN3(n1, n2, n3) min(n1, min(n2, n3)) #define MN4(n1, n2, n3, n4) min(n1, min(n2, min(n3, n4))) #define MX3(n1, n2, n3) max(n1, max(n2, n3)) #define MX4(n1, n2, n3, n4) max(n1, max(n2, max(n3, n4))) #define mxar(a, n) *max_element(a, a + n) #define mnar(a, n) *min_element(a, a + n) #define arr_sm(a, n) accumulate(a, a + n, 0) #define vc_sm(ve) accumulate(ve.begin(), ve.end(), 0) #define mx_vc(ve) *max_element(ve.begin(), ve.end()) #define mn_vc(ve) *min_element(ve.begin(), ve.end()) //#define endl " \n" /*** STLs ***/ typedef vector<ll> vll; #define vvll vector<vll> typedef set<ll> sll; typedef multiset<ll> msll; // typedef multimap <ll> mpll; typedef queue<ll> qll; typedef map<ll, ll> mll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef priority_queue<pair<ll, ll>> pqpll; #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define ml unordered_map<ll, ll> /// typedef unordered_multiset<int> umsi; typedef unordered_set<ll> us; /// vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of /// 10 rows and 20 columns, with value 500. /*** Sorts ***/ #define czero(n) \ __builtin_popcountll( \ n) // count the number of 1's in the bit representation of a number #define cenzero(n) \ __builtin_ctzll(n) // count the number of zereos from the end of the bit // representation of a number until a 1 #define countbegzero(n) __builtin_clzxll(n) #define checkparity(n) \ __builtin_parityll(n) // checks whether the number of bits are even or odd #define all(v) (v).begin(), (v).end() #define rev(v) reverse(all(v)) #define srt(v) sort(all(v)) #define srtgrt(v) sort(all(v), greater<ll>()) #define prsrt greater<pair<int, int>>() /*** Some Prints ***/ #define ip(n) \ ll n; \ cin >> n; #define ipp(n, k) \ ll n; \ cin >> n; \ ll k; \ cin >> k; #define ip3(n, m, k) \ ll n; \ cin >> n; \ ll m; \ cin >> m; \ ll k; \ cin >> k; #define kl '\n' #define no cout << "NO" << '\n' #define yes cout << "YES" << '\n' #define case cout << "Case " << t++ << ": "; #define ps(x, y) fixed << setprecision(y) << x #define inf 1e18 #define w(x) \ ll x; \ cin >> x; \ while (x--) #define go(i, a) for (auto &i : a) #define go1(it, v) for (auto it = v.begin(); it != v.end(); ++it) #define mk(arr, n, type) type *arr = new type[n]; #define sz(obj) (int(obj.size())) #define ipve(vc, n) \ vll vc(n); \ ff1(i, 0, n) { cin >> vc[i]; } #define ipvc(vc, n) \ vll vc; \ ff1(i, 0, n) { \ ip(x); \ vc.pb(x); \ } #define cer \ cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC \ << "ms\n"; #define depressed() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // bool ans = all_of(arr, arr + 6, [](int x) {return x & 1; } ); const double pi = 3.141592653589793238460; #define TRC #ifdef TRC #define trc(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; // use cerr if u want to display at the bottom } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trc(...) #endif void fun() { ipp(n, w); vll a(101); vll b(101); ff1(i, 0, n) { cin >> a[i] >> b[i]; } vvll dp(101, vll(1000, inf)); dp[0][b[0]] = a[0]; dp[0][0] = 0; ff1(i, 1, n) { dp[i][0] = 0; for (ll j = 1; j <= 100; j++) { dp[i][j] = dp[i - 1][j]; if (j >= b[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j - b[i]] + a[i]); // trc(dp[i][j]); } } ll rs = 0; ff2(i, 0, 100) { if (dp[n - 1][i] <= w) { rs = i; br; } } cout << rs; } int main() { // ofstream cout ("ride.out"); // ifstream cin ("ride.in"); depressed(); ll t = 1; // cin>>t; while (t--) { fun(); } // cer; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> //#include <boost/multiprecision/cpp_int.hpp> // // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; /*** Typedef ***/ typedef long long ll; typedef long long int lli; typedef unsigned long long ull; typedef long double ld; // typedef unordered_set<ll> usll; // typedef unordered_multiset<ll> umsll; /*** Loops ***/ #define ffit(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) #define F(a, b) for (int i = a; i < b; i++) #define ff1(i, a, b) for (ll i = a; i < b; i++) #define ff2(i, a, b) for (ll i = b - 1; i >= a; i--) #define ff3(i, a, b, m) for (ll i = a; i < b; i += m) #define ipar(ar, n) \ ll ar[n]; \ ff1(i, 0, n) cin >> ar[i]; #define opar(ar, n) ff1(i, 0, n) cout << ar[i] << " "; #define foRev(num) for (ll i = num - 1; i >= 0; i--) #define forIn(arr, num) \ for (ll i = 0; i < num; i++) \ sc1(arr[i]); #define forIn1(arr, num) \ for (ll i = 1; i <= num; i++) \ sc1(arr[i]); #define vpnt(ans) \ for (ll i = 0; i < ans.size(); i++) \ cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n'); #define apnt(arr, num) \ for (ll i = 0; i < num; i++) \ cout << arr[i] << (i + 1 < num ? ' ' : '\n'); /*** Define Values ***/ #define PI acos(-1.0) #define eps 1e-7 #define size1 15 /*** STLs ***/ #define cu continue #define br break #define rsz resize #define ins insert #define ft front #define bk back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define ff first #define ss second #define mp make_pair #define mem(name, value) memset(name, value, sizeof(name)) #define MN3(n1, n2, n3) min(n1, min(n2, n3)) #define MN4(n1, n2, n3, n4) min(n1, min(n2, min(n3, n4))) #define MX3(n1, n2, n3) max(n1, max(n2, n3)) #define MX4(n1, n2, n3, n4) max(n1, max(n2, max(n3, n4))) #define mxar(a, n) *max_element(a, a + n) #define mnar(a, n) *min_element(a, a + n) #define arr_sm(a, n) accumulate(a, a + n, 0) #define vc_sm(ve) accumulate(ve.begin(), ve.end(), 0) #define mx_vc(ve) *max_element(ve.begin(), ve.end()) #define mn_vc(ve) *min_element(ve.begin(), ve.end()) //#define endl " \n" /*** STLs ***/ typedef vector<ll> vll; #define vvll vector<vll> typedef set<ll> sll; typedef multiset<ll> msll; // typedef multimap <ll> mpll; typedef queue<ll> qll; typedef map<ll, ll> mll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef priority_queue<pair<ll, ll>> pqpll; #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define ml unordered_map<ll, ll> /// typedef unordered_multiset<int> umsi; typedef unordered_set<ll> us; /// vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of /// 10 rows and 20 columns, with value 500. /*** Sorts ***/ #define czero(n) \ __builtin_popcountll( \ n) // count the number of 1's in the bit representation of a number #define cenzero(n) \ __builtin_ctzll(n) // count the number of zereos from the end of the bit // representation of a number until a 1 #define countbegzero(n) __builtin_clzxll(n) #define checkparity(n) \ __builtin_parityll(n) // checks whether the number of bits are even or odd #define all(v) (v).begin(), (v).end() #define rev(v) reverse(all(v)) #define srt(v) sort(all(v)) #define srtgrt(v) sort(all(v), greater<ll>()) #define prsrt greater<pair<int, int>>() /*** Some Prints ***/ #define ip(n) \ ll n; \ cin >> n; #define ipp(n, k) \ ll n; \ cin >> n; \ ll k; \ cin >> k; #define ip3(n, m, k) \ ll n; \ cin >> n; \ ll m; \ cin >> m; \ ll k; \ cin >> k; #define kl '\n' #define no cout << "NO" << '\n' #define yes cout << "YES" << '\n' #define case cout << "Case " << t++ << ": "; #define ps(x, y) fixed << setprecision(y) << x #define inf 1e18 #define w(x) \ ll x; \ cin >> x; \ while (x--) #define go(i, a) for (auto &i : a) #define go1(it, v) for (auto it = v.begin(); it != v.end(); ++it) #define mk(arr, n, type) type *arr = new type[n]; #define sz(obj) (int(obj.size())) #define ipve(vc, n) \ vll vc(n); \ ff1(i, 0, n) { cin >> vc[i]; } #define ipvc(vc, n) \ vll vc; \ ff1(i, 0, n) { \ ip(x); \ vc.pb(x); \ } #define cer \ cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC \ << "ms\n"; #define depressed() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // bool ans = all_of(arr, arr + 6, [](int x) {return x & 1; } ); const double pi = 3.141592653589793238460; #define TRC #ifdef TRC #define trc(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; // use cerr if u want to display at the bottom } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trc(...) #endif void fun() { ipp(n, w); vll a(101); vll b(101); ff1(i, 0, n) { cin >> a[i] >> b[i]; } vvll dp(101, vll(100001, inf)); dp[0][b[0]] = a[0]; dp[0][0] = 0; ff1(i, 1, n) { dp[i][0] = 0; for (ll j = 1; j <= 100001; j++) { dp[i][j] = dp[i - 1][j]; if (j >= b[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j - b[i]] + a[i]); // trc(dp[i][j]); } } ll rs = 0; ff2(i, 0, 100001) { if (dp[n - 1][i] <= w) { rs = i; br; } } cout << rs; } int main() { // ofstream cout ("ride.out"); // ifstream cin ("ride.in"); depressed(); ll t = 1; // cin>>t; while (t--) { fun(); } // cer; return 0; }
[ "literal.number.change", "call.arguments.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
969,444
969,445
u403290660
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define V_SUM_MAX 100000 #define N_MAX 100 #define W_MAX 1000000000 // To store the states of DP ll dp[V_SUM_MAX + 1][N_MAX]; bool v[V_SUM_MAX + 1][N_MAX]; // Function to solve the recurrence relation ll solveDp(ll r, ll i, ll *w, ll *val, ll n) { // Base cases if (r <= 0) return 0; if (i == n) return W_MAX; if (v[r][i]) return dp[r][i]; // Marking state as solved v[r][i] = 1; // Recurrence relation dp[r][i] = min(solveDp(r, i + 1, w, val, n), w[i] + solveDp(r - val[i], i + 1, w, val, n)); return dp[r][i]; } // Function to return the maximum weight ll maxWeight(ll *w, ll *val, ll n, ll c) { // Iterating through all possible values // to find the the largest value that can // be represented by the given weights for (ll i = V_SUM_MAX; i >= 0; i--) { if (solveDp(i, 0, w, val, n) <= c) { return i; } } return 0; } int main() { ll n, W; cin >> n >> W; ll w[n], v[n]; for (ll i = 0; i < n; i++) { cin >> w[i] >> v[i]; } cout << maxWeight(w, v, n, W) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define V_SUM_MAX 100000 #define N_MAX 100 #define W_MAX 100000000000 // To store the states of DP ll dp[V_SUM_MAX + 1][N_MAX]; bool v[V_SUM_MAX + 1][N_MAX]; // Function to solve the recurrence relation ll solveDp(ll r, ll i, ll *w, ll *val, ll n) { // Base cases if (r <= 0) return 0; if (i == n) return W_MAX; if (v[r][i]) return dp[r][i]; // Marking state as solved v[r][i] = 1; // Recurrence relation dp[r][i] = min(solveDp(r, i + 1, w, val, n), w[i] + solveDp(r - val[i], i + 1, w, val, n)); return dp[r][i]; } // Function to return the maximum weight ll maxWeight(ll *w, ll *val, ll n, ll c) { // Iterating through all possible values // to find the the largest value that can // be represented by the given weights for (ll i = V_SUM_MAX; i >= 0; i--) { if (solveDp(i, 0, w, val, n) <= c) { return i; } } return 0; } int main() { ll n, W; cin >> n >> W; ll w[n], v[n]; for (ll i = 0; i < n; i++) { cin >> w[i] >> v[i]; } cout << maxWeight(w, v, n, W) << "\n"; return 0; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
969,514
969,515
u671909786
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 ll isPrime[1000010] = {0}; vector<ll> Prime; void sieve() { ll i, j; isPrime[0] = isPrime[1] = 1; for (i = 2; i < 1000010; i++) if (isPrime[i] == 0) for (j = 2 * i; j < 1000010; j += i) isPrime[j] = 1; for (i = 1; i < 1000010; i++) if (isPrime[i] == 0) Prime.push_back(i); } ll modMul(ll a, ll b, ll mod) { ll res = 0; if (mod <= MOD) { return ((a % mod) * (b % mod)) % mod; } while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b = b / 2; } return res; } ll modPow(ll x, ll n, ll mod) { ll r = 1; while (n) { if (n & 1) r = modMul(r, x, mod); x = modMul(x, x, mod); n = (n >> 1); } return r; } vector<int> v; void printDivisors(int n) { // Vector to store half of the divisors 3343434 for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) // check if divisors are equal if (i % 2 != 0) { v.push_back(i); } else { if (i % 2 != 0) { v.push_back(i); } // push the second divisor in the vector if ((n / i) % 2 != 0) { v.push_back(n / i); } } } } // The vector will be printed in reverse } int sum = 0; long long int knapsack(int a[], int w[], int n, int W) { long long int dp[n + 1][sum + 1]; for (int i = 1; i <= sum; i++) { dp[0][i] = INT_MAX; } for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (a[i - 1] > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = min(dp[i - 1][j], w[i - 1] + dp[i - 1][j - a[i - 1]]); } } } int m = -1; for (int i = n; i >= 1; i--) { for (int j = sum; j >= 0; j--) { if (dp[i][j] <= W) { if (m < j) { m = j; } } } } return m; } void solve() { int n, W; cin >> n >> W; int a[n], w[n]; for (int i = 0; i < n; i++) { cin >> w[i]; cin >> a[i]; sum += a[i]; } knapsack(a, w, n, W); } int main() { int t; // cin>>t; t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 ll isPrime[1000010] = {0}; vector<ll> Prime; void sieve() { ll i, j; isPrime[0] = isPrime[1] = 1; for (i = 2; i < 1000010; i++) if (isPrime[i] == 0) for (j = 2 * i; j < 1000010; j += i) isPrime[j] = 1; for (i = 1; i < 1000010; i++) if (isPrime[i] == 0) Prime.push_back(i); } ll modMul(ll a, ll b, ll mod) { ll res = 0; if (mod <= MOD) { return ((a % mod) * (b % mod)) % mod; } while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b = b / 2; } return res; } ll modPow(ll x, ll n, ll mod) { ll r = 1; while (n) { if (n & 1) r = modMul(r, x, mod); x = modMul(x, x, mod); n = (n >> 1); } return r; } vector<int> v; void printDivisors(int n) { // Vector to store half of the divisors 3343434 for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) // check if divisors are equal if (i % 2 != 0) { v.push_back(i); } else { if (i % 2 != 0) { v.push_back(i); } // push the second divisor in the vector if ((n / i) % 2 != 0) { v.push_back(n / i); } } } } // The vector will be printed in reverse } int sum = 0; long long int knapsack(int a[], int w[], int n, int W) { long long int dp[n + 1][sum + 1]; for (int i = 1; i <= sum; i++) { dp[0][i] = INT_MAX; } for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (a[i - 1] > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = min(dp[i - 1][j], w[i - 1] + dp[i - 1][j - a[i - 1]]); } } } int m = -1; for (int i = n; i >= 1; i--) { for (int j = sum; j >= 0; j--) { if (dp[i][j] <= W) { if (m < j) { m = j; } } } } return m; } void solve() { int n, W; cin >> n >> W; int a[n], w[n]; for (int i = 0; i < n; i++) { cin >> w[i]; cin >> a[i]; sum += a[i]; } cout << knapsack(a, w, n, W) << endl; } int main() { int t; // cin>>t; t = 1; while (t--) { solve(); } }
[ "io.output.change", "io.output.newline.add" ]
969,518
969,519
u102044886
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 ll isPrime[1000010] = {0}; vector<ll> Prime; void sieve() { ll i, j; isPrime[0] = isPrime[1] = 1; for (i = 2; i < 1000010; i++) if (isPrime[i] == 0) for (j = 2 * i; j < 1000010; j += i) isPrime[j] = 1; for (i = 1; i < 1000010; i++) if (isPrime[i] == 0) Prime.push_back(i); } ll modMul(ll a, ll b, ll mod) { ll res = 0; if (mod <= MOD) { return ((a % mod) * (b % mod)) % mod; } while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b = b / 2; } return res; } ll modPow(ll x, ll n, ll mod) { ll r = 1; while (n) { if (n & 1) r = modMul(r, x, mod); x = modMul(x, x, mod); n = (n >> 1); } return r; } vector<int> v; void printDivisors(int n) { // Vector to store half of the divisors 3343434 for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) // check if divisors are equal if (i % 2 != 0) { v.push_back(i); } else { if (i % 2 != 0) { v.push_back(i); } // push the second divisor in the vector if ((n / i) % 2 != 0) { v.push_back(n / i); } } } } // The vector will be printed in reverse } int sum = 0; long long int knapsack(int a[], int w[], int n, int W) { long long int dp[n + 1][sum + 1]; for (int i = 1; i <= sum; i++) { dp[0][i] = INT_MAX; } for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (a[i - 1] > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = min(dp[i - 1][j], w[i - 1] + dp[i - 1][j - a[i - 1]]); } } } int m = -1; for (int i = n; i >= 1; i--) { for (int j = sum; j >= 0; j--) { if (dp[i][j] <= W) { if (m < j) { m = j; } } } } return m; } void solve() { int n, W; cin >> n >> W; int a[n], w[n]; for (int i = 0; i < n; i++) { cin >> w[i]; cin >> a[i]; sum += a[i]; } cout << knapsack(a, w, n, W) << endl; } int main() { int t; cin >> t; // t=1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 ll isPrime[1000010] = {0}; vector<ll> Prime; void sieve() { ll i, j; isPrime[0] = isPrime[1] = 1; for (i = 2; i < 1000010; i++) if (isPrime[i] == 0) for (j = 2 * i; j < 1000010; j += i) isPrime[j] = 1; for (i = 1; i < 1000010; i++) if (isPrime[i] == 0) Prime.push_back(i); } ll modMul(ll a, ll b, ll mod) { ll res = 0; if (mod <= MOD) { return ((a % mod) * (b % mod)) % mod; } while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b = b / 2; } return res; } ll modPow(ll x, ll n, ll mod) { ll r = 1; while (n) { if (n & 1) r = modMul(r, x, mod); x = modMul(x, x, mod); n = (n >> 1); } return r; } vector<int> v; void printDivisors(int n) { // Vector to store half of the divisors 3343434 for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) // check if divisors are equal if (i % 2 != 0) { v.push_back(i); } else { if (i % 2 != 0) { v.push_back(i); } // push the second divisor in the vector if ((n / i) % 2 != 0) { v.push_back(n / i); } } } } // The vector will be printed in reverse } int sum = 0; long long int knapsack(int a[], int w[], int n, int W) { long long int dp[n + 1][sum + 1]; for (int i = 1; i <= sum; i++) { dp[0][i] = INT_MAX; } for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (a[i - 1] > j) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = min(dp[i - 1][j], w[i - 1] + dp[i - 1][j - a[i - 1]]); } } } int m = -1; for (int i = n; i >= 1; i--) { for (int j = sum; j >= 0; j--) { if (dp[i][j] <= W) { if (m < j) { m = j; } } } } return m; } void solve() { int n, W; cin >> n >> W; int a[n], w[n]; for (int i = 0; i < n; i++) { cin >> w[i]; cin >> a[i]; sum += a[i]; } cout << knapsack(a, w, n, W) << endl; } int main() { int t; // cin>>t; t = 1; while (t--) { solve(); } }
[ "expression.operation.binary.remove", "assignment.change" ]
969,520
969,519
u102044886
cpp
p03164
// ABHISHEK AGRAWAL// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define mcc map<char, char> #define msl map<string, ll> #define mss map<string, string> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (ll i = 0; i < n; i++) #define loop1(i, n) for (ll i = 1; i <= n; i++) #define rloop(n, i) for (ll i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (ll i = a; i <= b; i += c) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; #define pv(v) loop(i, v.size()) cout << v[i] << " "; // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) ll n, q; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } ll extendedEuclid(ll A, ll B, ll &x, ll &y) { if (B == 0) { x = 1; y = 0; return A; } else { ll x1, y1; ll gcd = extendedEuclid(B, A % B, x1, y1); y = x1 - (A / B) * y1; x = y1; return gcd; } } ll mi(ll A, ll M) { ll x, y; extendedEuclid(A, M, x, y); if (x < 0) { x += mod; } return x; } template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, typename T1, typename T2> void read(T &x, T0 &y, T1 &z, T2 &w) { cin >> x >> y >> z >> w; } // pair// // read pair// template <typename T, typename T0> void read(pair<T, T0> &p) { cin >> p.f >> p.s; } // write pair// template <typename T, typename T0> void write(pair<T, T0> &p) { write(p.f); write(p.s); } // vector// // read vector// template <typename T> void read(vector<T> &oneD, ll n) { loop(i, n) { ll x; read(x); oneD.pb(x); } } // array// // read array// template <typename T> void read(T oneD[], ll n) { loop(i, n) { read(oneD[i]); } } // write array// template <typename T> void write(T oneD[], int n) { loop(i, n) { write(oneD[i]); } cout << endl; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf; void Sieve_spf() { const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i, n) sieve_spf[i] = i; sieve_spf[0] = -1; sieve_spf[1] = 1; loopab(i, 2, n, 2) sieve_spf[i] = 2; loopab(i, 3, n, 2) if (sieve_spf[i] == i) loopab(j, i * i, n, i) if (sieve_spf[j] == j) sieve_spf[j] = i; } bool oppositeSigns(ll x, ll y) { return ((x ^ y) < 0); } int mpt(ll n) { ll c = 0; ll n1 = pow(2, c); while (n1 < n) { c++; n1 = pow(2, c); } return c; } void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } const int N = 400023; ll wt[N], val[N], dp[100001]; /*ll knapsack(ll wt[],ll val[],ll vl,ll n){ if(dp[n][vl]!=-1) return dp[n][vl]; dp[n][vl]=max(wt[n-1]+knapsack(wt,val,vl-val[n-1],n-1),knapsack(wt,val,vl,n-1)); return dp[n][vl]; }*/ /*void solve(){ ll w;read(n,w);ll dp[n+1][w+1]; loop(i,n) read(wt[i],val[i]); loop(i,n+1) loop(j,w+1) if(i==0||j==0) dp[i][j]=0; loop1(i,n) { loop1(j,w){ if(wt[i-1]<=j) dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][w]<<"\n"; return; }*/ int main() { the_happiest_place_on_earth(); // Today's thought: Push yourself, because no one else is going to do it for // you. Things arenโ€™t always #000000 and #FFFFFF START OF PROGRAM LOGIC ll w; read(n, w); ll vl = 0; loop(i, n) { read(wt[i], val[i]); vl += val[i]; } loop1(i, vl) dp[i] = INT64_MAX; loop(i, n) for (int j = vl; j >= val[i]; j--) dp[j] = min(dp[j], dp[j - val[i]] + wt[i]); ll ma = 0; for (ll i = vl; i > 0; i--) if (dp[i] <= w) { ma = i; break; } cout << ma << "\n"; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; }
// ABHISHEK AGRAWAL// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define mcc map<char, char> #define msl map<string, ll> #define mss map<string, string> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (ll i = 0; i < n; i++) #define loop1(i, n) for (ll i = 1; i <= n; i++) #define rloop(n, i) for (ll i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (ll i = a; i <= b; i += c) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; #define pv(v) loop(i, v.size()) cout << v[i] << " "; // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) ll n, q; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } ll extendedEuclid(ll A, ll B, ll &x, ll &y) { if (B == 0) { x = 1; y = 0; return A; } else { ll x1, y1; ll gcd = extendedEuclid(B, A % B, x1, y1); y = x1 - (A / B) * y1; x = y1; return gcd; } } ll mi(ll A, ll M) { ll x, y; extendedEuclid(A, M, x, y); if (x < 0) { x += mod; } return x; } template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, typename T1, typename T2> void read(T &x, T0 &y, T1 &z, T2 &w) { cin >> x >> y >> z >> w; } // pair// // read pair// template <typename T, typename T0> void read(pair<T, T0> &p) { cin >> p.f >> p.s; } // write pair// template <typename T, typename T0> void write(pair<T, T0> &p) { write(p.f); write(p.s); } // vector// // read vector// template <typename T> void read(vector<T> &oneD, ll n) { loop(i, n) { ll x; read(x); oneD.pb(x); } } // array// // read array// template <typename T> void read(T oneD[], ll n) { loop(i, n) { read(oneD[i]); } } // write array// template <typename T> void write(T oneD[], int n) { loop(i, n) { write(oneD[i]); } cout << endl; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf; void Sieve_spf() { const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i, n) sieve_spf[i] = i; sieve_spf[0] = -1; sieve_spf[1] = 1; loopab(i, 2, n, 2) sieve_spf[i] = 2; loopab(i, 3, n, 2) if (sieve_spf[i] == i) loopab(j, i * i, n, i) if (sieve_spf[j] == j) sieve_spf[j] = i; } bool oppositeSigns(ll x, ll y) { return ((x ^ y) < 0); } int mpt(ll n) { ll c = 0; ll n1 = pow(2, c); while (n1 < n) { c++; n1 = pow(2, c); } return c; } void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } const int N = 400023; ll wt[N], val[N], dp[100001]; /*ll knapsack(ll wt[],ll val[],ll vl,ll n){ if(dp[n][vl]!=-1) return dp[n][vl]; dp[n][vl]=max(wt[n-1]+knapsack(wt,val,vl-val[n-1],n-1),knapsack(wt,val,vl,n-1)); return dp[n][vl]; }*/ /*void solve(){ ll w;read(n,w);ll dp[n+1][w+1]; loop(i,n) read(wt[i],val[i]); loop(i,n+1) loop(j,w+1) if(i==0||j==0) dp[i][j]=0; loop1(i,n) { loop1(j,w){ if(wt[i-1]<=j) dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][w]<<"\n"; return; }*/ int main() { the_happiest_place_on_earth(); // Today's thought: Push yourself, because no one else is going to do it for // you. Things arenโ€™t always #000000 and #FFFFFF START OF PROGRAM LOGIC ll w; read(n, w); ll vl = 0; loop(i, n) { read(wt[i], val[i]); vl += val[i]; } loop1(i, vl) dp[i] = INT_MAX; loop(i, n) for (int j = vl; j >= val[i]; j--) dp[j] = min(dp[j], dp[j - val[i]] + wt[i]); ll ma = 0; for (ll i = vl; i > 0; i--) if (dp[i] <= w) { ma = i; break; } cout << ma << "\n"; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; }
[ "assignment.value.change", "identifier.change" ]
969,526
969,527
u625460396
cpp
p03164
// ABHISHEK AGRAWAL// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define mcc map<char, char> #define msl map<string, ll> #define mss map<string, string> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (ll i = 0; i < n; i++) #define loop1(i, n) for (ll i = 1; i <= n; i++) #define rloop(n, i) for (ll i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (ll i = a; i <= b; i += c) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; #define pv(v) loop(i, v.size()) cout << v[i] << " "; // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) ll n, q; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } ll extendedEuclid(ll A, ll B, ll &x, ll &y) { if (B == 0) { x = 1; y = 0; return A; } else { ll x1, y1; ll gcd = extendedEuclid(B, A % B, x1, y1); y = x1 - (A / B) * y1; x = y1; return gcd; } } ll mi(ll A, ll M) { ll x, y; extendedEuclid(A, M, x, y); if (x < 0) { x += mod; } return x; } template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, typename T1, typename T2> void read(T &x, T0 &y, T1 &z, T2 &w) { cin >> x >> y >> z >> w; } // pair// // read pair// template <typename T, typename T0> void read(pair<T, T0> &p) { cin >> p.f >> p.s; } // write pair// template <typename T, typename T0> void write(pair<T, T0> &p) { write(p.f); write(p.s); } // vector// // read vector// template <typename T> void read(vector<T> &oneD, ll n) { loop(i, n) { ll x; read(x); oneD.pb(x); } } // array// // read array// template <typename T> void read(T oneD[], ll n) { loop(i, n) { read(oneD[i]); } } // write array// template <typename T> void write(T oneD[], int n) { loop(i, n) { write(oneD[i]); } cout << endl; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf; void Sieve_spf() { const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i, n) sieve_spf[i] = i; sieve_spf[0] = -1; sieve_spf[1] = 1; loopab(i, 2, n, 2) sieve_spf[i] = 2; loopab(i, 3, n, 2) if (sieve_spf[i] == i) loopab(j, i * i, n, i) if (sieve_spf[j] == j) sieve_spf[j] = i; } bool oppositeSigns(ll x, ll y) { return ((x ^ y) < 0); } int mpt(ll n) { ll c = 0; ll n1 = pow(2, c); while (n1 < n) { c++; n1 = pow(2, c); } return c; } void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } const int N = 400023; ll wt[N], val[N], dp[100001]; /*ll knapsack(ll wt[],ll val[],ll vl,ll n){ if(dp[n][vl]!=-1) return dp[n][vl]; dp[n][vl]=max(wt[n-1]+knapsack(wt,val,vl-val[n-1],n-1),knapsack(wt,val,vl,n-1)); return dp[n][vl]; }*/ /*void solve(){ ll w;read(n,w);ll dp[n+1][w+1]; loop(i,n) read(wt[i],val[i]); loop(i,n+1) loop(j,w+1) if(i==0||j==0) dp[i][j]=0; loop1(i,n) { loop1(j,w){ if(wt[i-1]<=j) dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][w]<<"\n"; return; }*/ int main() { the_happiest_place_on_earth(); // Today's thought: Push yourself, because no one else is going to do it for // you. Things arenโ€™t always #000000 and #FFFFFF START OF PROGRAM LOGIC ll w; read(n, w); ll vl = 0; loop(i, n) { read(wt[i], val[i]); vl += val[i]; } loop1(i, vl) dp[i] = INT64_MAX; loop(i, n) for (ll j = vl; j >= val[i]; j--) dp[j] = min(dp[j], dp[j - val[i]] + wt[i]); ll ma = 0; for (ll i = vl; i > 0; i--) if (dp[i] <= w) { ma = i; break; } cout << ma << "\n"; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; }
// ABHISHEK AGRAWAL// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define mcc map<char, char> #define msl map<string, ll> #define mss map<string, string> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (ll i = 0; i < n; i++) #define loop1(i, n) for (ll i = 1; i <= n; i++) #define rloop(n, i) for (ll i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (ll i = a; i <= b; i += c) #define max3(a, b, c) max(max(a, b), c) #define min3(a, b, c) min(min(a, b), c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; #define pv(v) loop(i, v.size()) cout << v[i] << " "; // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) ll n, q; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } ll extendedEuclid(ll A, ll B, ll &x, ll &y) { if (B == 0) { x = 1; y = 0; return A; } else { ll x1, y1; ll gcd = extendedEuclid(B, A % B, x1, y1); y = x1 - (A / B) * y1; x = y1; return gcd; } } ll mi(ll A, ll M) { ll x, y; extendedEuclid(A, M, x, y); if (x < 0) { x += mod; } return x; } template <typename T> void read(T &x) { cin >> x; } template <typename T, typename T0> void read(T &x, T0 &y) { cin >> x >> y; } template <typename T, typename T0, typename T1> void read(T &x, T0 &y, T1 &z) { cin >> x >> y >> z; } template <typename T, typename T0, typename T1, typename T2> void read(T &x, T0 &y, T1 &z, T2 &w) { cin >> x >> y >> z >> w; } // pair// // read pair// template <typename T, typename T0> void read(pair<T, T0> &p) { cin >> p.f >> p.s; } // write pair// template <typename T, typename T0> void write(pair<T, T0> &p) { write(p.f); write(p.s); } // vector// // read vector// template <typename T> void read(vector<T> &oneD, ll n) { loop(i, n) { ll x; read(x); oneD.pb(x); } } // array// // read array// template <typename T> void read(T oneD[], ll n) { loop(i, n) { read(oneD[i]); } } // write array// template <typename T> void write(T oneD[], int n) { loop(i, n) { write(oneD[i]); } cout << endl; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf; void Sieve_spf() { const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i, n) sieve_spf[i] = i; sieve_spf[0] = -1; sieve_spf[1] = 1; loopab(i, 2, n, 2) sieve_spf[i] = 2; loopab(i, 3, n, 2) if (sieve_spf[i] == i) loopab(j, i * i, n, i) if (sieve_spf[j] == j) sieve_spf[j] = i; } bool oppositeSigns(ll x, ll y) { return ((x ^ y) < 0); } int mpt(ll n) { ll c = 0; ll n1 = pow(2, c); while (n1 < n) { c++; n1 = pow(2, c); } return c; } void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } const int N = 400023; ll wt[N], val[N], dp[100001]; /*ll knapsack(ll wt[],ll val[],ll vl,ll n){ if(dp[n][vl]!=-1) return dp[n][vl]; dp[n][vl]=max(wt[n-1]+knapsack(wt,val,vl-val[n-1],n-1),knapsack(wt,val,vl,n-1)); return dp[n][vl]; }*/ /*void solve(){ ll w;read(n,w);ll dp[n+1][w+1]; loop(i,n) read(wt[i],val[i]); loop(i,n+1) loop(j,w+1) if(i==0||j==0) dp[i][j]=0; loop1(i,n) { loop1(j,w){ if(wt[i-1]<=j) dp[i][j]=max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]); else dp[i][j]=dp[i-1][j]; } } cout<<dp[n][w]<<"\n"; return; }*/ int main() { the_happiest_place_on_earth(); // Today's thought: Push yourself, because no one else is going to do it for // you. Things arenโ€™t always #000000 and #FFFFFF START OF PROGRAM LOGIC ll w; read(n, w); ll vl = 0; loop(i, n) { read(wt[i], val[i]); vl += val[i]; } loop1(i, vl) dp[i] = INT_MAX; loop(i, n) for (int j = vl; j >= val[i]; j--) dp[j] = min(dp[j], dp[j - val[i]] + wt[i]); ll ma = 0; for (ll i = vl; i > 0; i--) if (dp[i] <= w) { ma = i; break; } cout << ma << "\n"; cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; }
[ "assignment.value.change", "identifier.change", "control_flow.loop.for.initializer.change", "variable_declaration.type.change" ]
969,528
969,527
u625460396
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> DP(1e5 + 1, 1e9); DP.at(0) = 0; for (int i = 0, w, v; i < N && cin >> w >> v; i++) for (int j = 1e5; j >= v; j--) DP.at(j) = min(DP.at(j), DP.at(j - v) + w); for (int i = 1e5; i >= 0; i--) if (DP.at(i) <= W) { cout << i << "\n"; break; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> DP(1e5 + 1, 1e9 + 1); DP.at(0) = 0; for (int i = 0, w, v; i < N && cin >> w >> v; i++) for (int j = 1e5; j >= v; j--) DP.at(j) = min(DP.at(j), DP.at(j - v) + w); for (int i = 1e5; i >= 0; i--) if (DP.at(i) <= W) { cout << i << "\n"; break; } }
[ "assignment.change" ]
969,534
969,535
u045289115
cpp
p03164
#include <bits/stdc++.h> using intl = long long; using itnl = long long; // typo็”จ using uintl = unsigned long long; using itn = int; // typo็”จ using ld = long double; using namespace std; #define rep(i, n) for (intl i = 0; i < (intl)(n); i++) #define rrep(i, n) for (intl i = (intl)(n)-1; i >= 0; i--) #define repi(i, a, b) for (intl i = (intl)(a); i < (intl)(b); i++) #define rrepi(i, a, b) for (intl i = (intl)(a)-1; i >= (intl)(b); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define m0(x) memset(x, 0, sizeof(x)) #define m1(x) memset(x, 1, sizeof(x)) #define fill(x, y) memset(x, y, sizeof(x)) #define alength(a) (sizeof(a) / sizeof(a[0])) #define debug(x) cout << #x << ":" << x << endl #define rdebug(i, x) \ rep(i, alength(x)) cout << #x << "[" << i << "]:" << x[i] \ << endl // 1ๆฌกๅ…ƒ้…ๅˆ—ใฎๅ‡บๅŠ› #define rrdebug(i, j, x) \ rep(i, alength(x)) rep(j, alength(x[i])) cout << #x << "[" << i << "][" << j \ << "]:" << x[i][j] \ << endl //ไบŒๆฌกๅ…ƒ้…ๅˆ—ใฎๅ‡บๅŠ› #define pb push_back #define mp make_pair #define pii pair<intl, intl> const intl INF = 1e9; // 1e9 const intl MOD = 1e9 + 7; const ld EPS = 1.0e-14; //-9 const ld PI = acos(-1); void fp(bool f) { cout << (f ? "Yes" : "No") << endl; } void fp(bool f, string s, string t) { cout << (f ? s : t) << endl; } 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; } intl gcd(intl a, intl b) { if (!b) return a; return gcd(b, a % b); } intl lcm(intl a, intl b) { return a / gcd(a, b) * b; } intl kai(intl k) { // k!ใ‚’ๆฑ‚ใ‚ใ‚‹้–ขๆ•ฐ intl a = 1; for (int i = 2; i <= k; i++) { a *= i; } return a; } intl digit10(intl a) { // aใ‚’10้€ฒๆ•ฐใง่กจใ—ใŸใจใใฎๆกๆ•ฐใ‚’ๆฑ‚ใ‚ใ‚‹้–ขๆ•ฐ intl b = 0; do { a /= 10; b++; } while (a); return b; } signed main() { cout << fixed << setprecision(10); intl n, W; cin >> n >> W; intl w[n], v[n]; rep(i, n) cin >> w[i] >> v[i]; intl sum = 0; rep(i, n) sum += v[i]; intl dp[n + 1][sum + 1]; rep(i, n + 1) rep(j, sum + 1) dp[i][j] = INF; dp[0][0] = 0; rep(i, n) { rep(j, sum) { if (j - v[i] >= 0) chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]); chmin(dp[i + 1][j], dp[i][j]); } } intl ans = 0; /* rep(i,n + 1){ rep(j, sum + 1)cout << dp[i][j] << " "; cout << endl; }*/ rep(i, sum + 1) { if (dp[n][i] <= W) { ans = i; // debug(ans); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using intl = long long; using itnl = long long; // typo็”จ using uintl = unsigned long long; using itn = int; // typo็”จ using ld = long double; using namespace std; #define rep(i, n) for (intl i = 0; i < (intl)(n); i++) #define rrep(i, n) for (intl i = (intl)(n)-1; i >= 0; i--) #define repi(i, a, b) for (intl i = (intl)(a); i < (intl)(b); i++) #define rrepi(i, a, b) for (intl i = (intl)(a)-1; i >= (intl)(b); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define m0(x) memset(x, 0, sizeof(x)) #define m1(x) memset(x, 1, sizeof(x)) #define fill(x, y) memset(x, y, sizeof(x)) #define alength(a) (sizeof(a) / sizeof(a[0])) #define debug(x) cout << #x << ":" << x << endl #define rdebug(i, x) \ rep(i, alength(x)) cout << #x << "[" << i << "]:" << x[i] \ << endl // 1ๆฌกๅ…ƒ้…ๅˆ—ใฎๅ‡บๅŠ› #define rrdebug(i, j, x) \ rep(i, alength(x)) rep(j, alength(x[i])) cout << #x << "[" << i << "][" << j \ << "]:" << x[i][j] \ << endl //ไบŒๆฌกๅ…ƒ้…ๅˆ—ใฎๅ‡บๅŠ› #define pb push_back #define mp make_pair #define pii pair<intl, intl> const intl INF = 1e9; // 1e9 const intl MOD = 1e9 + 7; const ld EPS = 1.0e-14; //-9 const ld PI = acos(-1); void fp(bool f) { cout << (f ? "Yes" : "No") << endl; } void fp(bool f, string s, string t) { cout << (f ? s : t) << endl; } 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; } intl gcd(intl a, intl b) { if (!b) return a; return gcd(b, a % b); } intl lcm(intl a, intl b) { return a / gcd(a, b) * b; } intl kai(intl k) { // k!ใ‚’ๆฑ‚ใ‚ใ‚‹้–ขๆ•ฐ intl a = 1; for (int i = 2; i <= k; i++) { a *= i; } return a; } intl digit10(intl a) { // aใ‚’10้€ฒๆ•ฐใง่กจใ—ใŸใจใใฎๆกๆ•ฐใ‚’ๆฑ‚ใ‚ใ‚‹้–ขๆ•ฐ intl b = 0; do { a /= 10; b++; } while (a); return b; } signed main() { cout << fixed << setprecision(10); intl n, W; cin >> n >> W; intl w[n], v[n]; rep(i, n) cin >> w[i] >> v[i]; intl sum = 0; rep(i, n) sum += v[i]; intl dp[n + 1][sum + 1]; rep(i, n + 1) rep(j, sum + 1) dp[i][j] = INF; dp[0][0] = 0; rep(i, n) { rep(j, sum + 1) { if (j - v[i] >= 0) chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]); chmin(dp[i + 1][j], dp[i][j]); } } intl ans = 0; /* rep(i,n + 1){ rep(j, sum + 1)cout << dp[i][j] << " "; cout << endl; }*/ rep(i, sum + 1) { if (dp[n][i] <= W) { ans = i; // debug(ans); } } cout << ans << endl; return 0; }
[ "expression.operation.binary.add" ]
969,538
969,539
u344119694
cpp
p03164
// INCLUDE //------------------------------------------ #include <bits/stdc++.h> // DEFINE //------------------------------------------ #define ll long long #define ld long double #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> #define dcml(n) fixed << setprecision(n) // CONST //------------------------------------------ const ll INF = 1010000000000000017LL; const ll MOD = 1000000007LL; const ld EPS = 1e-12; const ld PI = 3.14159265358979323846; // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define FORS(i, m, n) for (ll(i) = (m); (i) <= (n); (i)++) #define RFOR(i, m, n) for (ll(i) = (n)-1; (i) >= (n); (i)--) #define RFORS(i, m, n) for (ll(i) = (n); (i) > (n); (i)--) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) #define WREPS(i, in, j, jn) REPS(i, in) REPS(j, jn) //----------------------------------------- // namespace using namespace std; //ใƒฉใ‚คใƒ–ใƒฉใƒชใฏใ“ใ“ใซ //โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“ //----------------------------------------- int main(void) { ll N, W; cin >> N >> W; ll w[110], v[110]; vector<vi> dp(110, vi(110000, INF)); dp[0][0] = 0; REP(i, N) cin >> w[i] >> v[i]; REP(i, N) { REPS(j, 100000) { if (j >= v[i]) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ll ans = 0; REPS(j, 100000) { if (dp[N][j] <= W) ans = j; } cout << ans << "\n"; }
// INCLUDE //------------------------------------------ #include <bits/stdc++.h> // DEFINE //------------------------------------------ #define ll long long #define ld long double #define ALLv(a) (a).begin(), (a).end() #define ALL(a, n) (a), (a) + n #define vi vector<long long> #define vd vector<long double> #define vs vector<string> #define dcml(n) fixed << setprecision(n) // CONST //------------------------------------------ const ll INF = 1010000000000000017LL; const ll MOD = 1000000007LL; const ld EPS = 1e-12; const ld PI = 3.14159265358979323846; // REPEAT //------------------------------------------ #define FOR(i, m, n) for (ll(i) = (m); (i) < (n); (i)++) #define FORS(i, m, n) for (ll(i) = (m); (i) <= (n); (i)++) #define RFOR(i, m, n) for (ll(i) = (n)-1; (i) >= (n); (i)--) #define RFORS(i, m, n) for (ll(i) = (n); (i) > (n); (i)--) #define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define REPS(i, x) for (ll(i) = 1; (i) <= (x); (i)++) #define RREP(i, x) for (ll(i) = (x)-1; (i) >= 0; (i)--) #define RREPS(i, x) for (ll(i) = (x); (i) > 0; (i)--) #define WREP(i, in, j, jn) REP(i, in) REP(j, jn) #define WREPS(i, in, j, jn) REPS(i, in) REPS(j, jn) //----------------------------------------- // namespace using namespace std; //ใƒฉใ‚คใƒ–ใƒฉใƒชใฏใ“ใ“ใซ //โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“โ†“ //----------------------------------------- int main(void) { ll N, W; cin >> N >> W; ll w[110], v[110]; vector<vi> dp(110, vi(110000, INF)); dp[0][0] = 0; REP(i, N) cin >> w[i] >> v[i]; REP(i, N) { FORS(j, 0, 100000) { if (j >= v[i]) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ll ans = 0; REPS(j, 100000) { if (dp[N][j] <= W) ans = j; } cout << ans << "\n"; }
[ "identifier.change", "call.function.change", "call.arguments.add" ]
969,552
969,551
u334644046
cpp
p03164
/* */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define mp make_pair #define pb push_back #define fi first #define si second #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define F(a, n) \ for (int i = 0; i < n; i++) { \ cin >> a[i]; \ } #define F1(a, n) \ for (int i = 1; i <= n; i++) { \ cin >> a[i]; \ } #define P(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << ' '; \ } \ cout << endl; #define P1(a, n) \ for (int i = 1; i <= n; i++) { \ cout << a[i] << ' '; \ } \ cout << endl; #define NF(a, n, m) \ for (int i = 0; i < n; i++) { \ for (int j = 0; j < m; j++) { \ cin >> a[i][j]; \ } \ } #define NF1(a, n, m) \ for (int i = 1; i <= n; i++) { \ for (int j = 1; j <= m; j++) { \ cin >> a[i][j]; \ } \ } #define PNF(a, n, m) \ for (int i = 0; i < n; i++) { \ for (int j = 0; j < m; j++) { \ cout << a[i][j] << ' '; \ } \ cout << endl; \ } \ cout << endl; #define PNF1(a, n, m) \ for (int i = 1; i <= n; i++) { \ for (int j = 1; j <= m; j++) { \ cout << a[i][j] << ' '; \ } \ cout << endl; \ } \ cout << endl; const int nax = 1e5 + 1; const int mod = 1e11 + 7; int main() { fastIO ll n, capacity; cin >> n >> capacity; ll *weight = new ll[n + 1]; ll *cost = new ll[n + 1]; ll max_cost = 0; for (ll i = 1; i <= n; i++) { cin >> weight[i] >> cost[i]; max_cost += cost[i]; } ll dp[101][max_cost + 1]; memset(dp, mod, sizeof(dp)); for (ll i = 0; i <= n; i++) { dp[i][0] = 0; } for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= max_cost; j++) { ll op1 = dp[i - 1][j]; ll op2 = (cost[i] <= j) ? (weight[i] + dp[i - 1][j - cost[i]]) : mod; dp[i][j] = min(op1, op2); } } ll ans = 0; for (ll i = 0; i <= max_cost; i++) { if (dp[n][i] <= capacity) { ans = i; } } cout << ans; }
/* */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define mp make_pair #define pb push_back #define fi first #define si second #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define F(a, n) \ for (int i = 0; i < n; i++) { \ cin >> a[i]; \ } #define F1(a, n) \ for (int i = 1; i <= n; i++) { \ cin >> a[i]; \ } #define P(a, n) \ for (int i = 0; i < n; i++) { \ cout << a[i] << ' '; \ } \ cout << endl; #define P1(a, n) \ for (int i = 1; i <= n; i++) { \ cout << a[i] << ' '; \ } \ cout << endl; #define NF(a, n, m) \ for (int i = 0; i < n; i++) { \ for (int j = 0; j < m; j++) { \ cin >> a[i][j]; \ } \ } #define NF1(a, n, m) \ for (int i = 1; i <= n; i++) { \ for (int j = 1; j <= m; j++) { \ cin >> a[i][j]; \ } \ } #define PNF(a, n, m) \ for (int i = 0; i < n; i++) { \ for (int j = 0; j < m; j++) { \ cout << a[i][j] << ' '; \ } \ cout << endl; \ } \ cout << endl; #define PNF1(a, n, m) \ for (int i = 1; i <= n; i++) { \ for (int j = 1; j <= m; j++) { \ cout << a[i][j] << ' '; \ } \ cout << endl; \ } \ cout << endl; const int nax = 1e5 + 1; const ll mod = 1e11 + 7; int main() { fastIO ll n, capacity; cin >> n >> capacity; ll *weight = new ll[n + 1]; ll *cost = new ll[n + 1]; ll max_cost = 0; for (ll i = 1; i <= n; i++) { cin >> weight[i] >> cost[i]; max_cost += cost[i]; } ll dp[101][max_cost + 2]; memset(dp, mod, sizeof(dp)); for (ll i = 0; i <= n; i++) { dp[i][0] = 0; } for (ll i = 1; i <= n; i++) { for (ll j = 0; j <= max_cost; j++) { ll op1 = dp[i - 1][j]; ll op2 = (cost[i] <= j) ? (weight[i] + dp[i - 1][j - cost[i]]) : mod; dp[i][j] = min(op1, op2); } } ll ans = 0; for (ll i = 0; i <= max_cost; i++) { if (dp[n][i] <= capacity) { ans = i; } } cout << ans; }
[ "variable_declaration.type.change", "literal.number.change", "expression.operation.binary.change" ]
969,561
969,562
u340251061
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define MAX_V 100001 const int INF = 2147483647; int dp[101][MAX_V]; int main() { int N, W, w[101], v[101], ans = 0; cin >> N >> W; REP(i, N) cin >> w[i] >> v[i]; REP(i, MAX_V) dp[0][i] = (i ? INF : 0); REP(i, N) REP(j, MAX_V) { if ((j - v[i] >= 0) && (dp[i][j - v[i]] != INF)) dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } REP(i, N) REP(j, MAX_V) if (dp[i][j] <= W) ans = max(ans, j); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define MAX_V 100001 const int INF = 1001001001; int dp[101][MAX_V]; int main() { int N, W, w[101], v[101], ans = 0; cin >> N >> W; REP(i, N) cin >> w[i] >> v[i]; REP(i, MAX_V) dp[0][i] = (i ? INF : 0); REP(i, N) REP(j, MAX_V) { if ((j - v[i] >= 0) && (dp[i][j - v[i]] != INF)) dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } REP(i, N + 1) REP(j, MAX_V) if (dp[i][j] <= W) ans = max(ans, j); cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
969,572
969,571
u082801599
cpp
p03164
#include <bits/stdc++.h> using namespace std; // A utility function that returns maximum of two integers int max(int a, int b) { return (a > b) ? a : b; } // Returns the maximum value that can be put in a knapsack of capacity W long long knapSack1(int W, int weight[], int val[], int n) { int k, w; long long **F = new long long *[n + 1]; for (int i = 0; i < n + 1; i++) F[i] = new long long[W + 1]; // Build table K[][] in bottom up manner for (k = 0; k <= n; k++) { for (w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; // cout<<std::setw(2)<<F[k][w]<<" "; } // cout<<endl; } long long result = F[n][W]; for (int i = 0; i < n + 1; i++) delete[] F[i]; delete[] F; return result; } long long knapSack2(int W, int weight[], int val[], int n) { long long F[n + 1][W + 1]; // Build table K[][] in bottom up manner for (int k = 0; k <= n; k++) { for (int w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; } } return F[n][W]; } long long knapSack3(int W, int weight[], int val[], int n) { long long vsum = 0; for (int i = 0; i < n; i++) { vsum += val[i]; } long long *dp = new long long[vsum + 1]; for (long long i = 0; i < vsum + 1; i++) dp[i] = pow(10, 18) + 5; dp[0] = 0; for (int i = 0; i < n; i++) { for (long long j = vsum; j >= val[i]; j--) { dp[j] = min(dp[j], dp[j - val[i]] + weight[i]); } } long long i; for (i = vsum; i >= 0; i--) { if (dp[i] <= W) { // cout << i; break; } } delete[] dp; return i; } int main() { std::ios::sync_with_stdio(false); int n, W; std::cin >> n >> W; int *val = new int[n]; int *wt = new int[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } std::cout << knapSack2(W, wt, val, n) << endl; delete[] val; delete[] wt; return 0; }
#include <bits/stdc++.h> using namespace std; // A utility function that returns maximum of two integers int max(int a, int b) { return (a > b) ? a : b; } // Returns the maximum value that can be put in a knapsack of capacity W long long knapSack1(int W, int weight[], int val[], int n) { int k, w; long long **F = new long long *[n + 1]; for (int i = 0; i < n + 1; i++) F[i] = new long long[W + 1]; // Build table K[][] in bottom up manner for (k = 0; k <= n; k++) { for (w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; // cout<<std::setw(2)<<F[k][w]<<" "; } // cout<<endl; } long long result = F[n][W]; for (int i = 0; i < n + 1; i++) delete[] F[i]; delete[] F; return result; } long long knapSack2(int W, int weight[], int val[], int n) { long long F[n + 1][W + 1]; // Build table K[][] in bottom up manner for (int k = 0; k <= n; k++) { for (int w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; } } return F[n][W]; } long long knapSack3(int W, int weight[], int val[], int n) { long long vsum = 0; for (int i = 0; i < n; i++) { vsum += val[i]; } long long *dp = new long long[vsum + 1]; for (long long i = 0; i < vsum + 1; i++) dp[i] = pow(10, 18) + 5; dp[0] = 0; for (int i = 0; i < n; i++) { for (long long j = vsum; j >= val[i]; j--) { dp[j] = min(dp[j], dp[j - val[i]] + weight[i]); } } long long i; for (i = vsum; i >= 0; i--) { if (dp[i] <= W) { // cout << i; break; } } delete[] dp; return i; } int main() { std::ios::sync_with_stdio(false); int n, W; std::cin >> n >> W; int *val = new int[n]; int *wt = new int[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } std::cout << knapSack3(W, wt, val, n) << endl; delete[] val; delete[] wt; return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
969,580
969,581
u930153819
cpp
p03164
#include <bits/stdc++.h> using namespace std; // A utility function that returns maximum of two integers int max(int a, int b) { return (a > b) ? a : b; } // Returns the maximum value that can be put in a knapsack of capacity W long long knapSack1(int W, int weight[], int val[], int n) { int k, w; long long **F = new long long *[n + 1]; for (int i = 0; i < n + 1; i++) F[i] = new long long[W + 1]; // Build table K[][] in bottom up manner for (k = 0; k <= n; k++) { for (w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; // cout<<std::setw(2)<<F[k][w]<<" "; } // cout<<endl; } long long result = F[n][W]; for (int i = 0; i < n + 1; i++) delete[] F[i]; delete[] F; return result; } long long knapSack2(int W, int weight[], int val[], int n) { long long F[n + 1][W + 1]; // Build table K[][] in bottom up manner for (int k = 0; k <= n; k++) { for (int w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; } } return F[n][W]; } long long knapSack3(int W, int weight[], int val[], int n) { long long vsum = 0; for (int i = 0; i < n; i++) { vsum += val[i]; } long long *dp = new long long[vsum + 1]; for (long long i = 0; i < vsum + 1; i++) dp[i] = pow(10, 18) + 5; dp[0] = 0; for (int i = 0; i < n; i++) { for (long long j = vsum; j >= val[i]; j--) { dp[j] = min(dp[j], dp[j - val[i]] + weight[i]); } } long long i; for (i = vsum; i >= 0; i--) { if (dp[i] <= W) { // cout << i; break; } } delete[] dp; return i; } int main() { std::ios::sync_with_stdio(false); int n, W; std::cin >> n >> W; int *val = new int[n]; int *wt = new int[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } std::cout << knapSack1(W, wt, val, n) << endl; delete[] val; delete[] wt; return 0; }
#include <bits/stdc++.h> using namespace std; // A utility function that returns maximum of two integers int max(int a, int b) { return (a > b) ? a : b; } // Returns the maximum value that can be put in a knapsack of capacity W long long knapSack1(int W, int weight[], int val[], int n) { int k, w; long long **F = new long long *[n + 1]; for (int i = 0; i < n + 1; i++) F[i] = new long long[W + 1]; // Build table K[][] in bottom up manner for (k = 0; k <= n; k++) { for (w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; // cout<<std::setw(2)<<F[k][w]<<" "; } // cout<<endl; } long long result = F[n][W]; for (int i = 0; i < n + 1; i++) delete[] F[i]; delete[] F; return result; } long long knapSack2(int W, int weight[], int val[], int n) { long long F[n + 1][W + 1]; // Build table K[][] in bottom up manner for (int k = 0; k <= n; k++) { for (int w = 0; w <= W; w++) { if (k == 0 || w == 0) F[k][w] = 0; else if (weight[k - 1] <= w) F[k][w] = max(F[k - 1][w], F[k - 1][w - weight[k - 1]] + val[k - 1]); else F[k][w] = F[k - 1][w]; } } return F[n][W]; } long long knapSack3(int W, int weight[], int val[], int n) { long long vsum = 0; for (int i = 0; i < n; i++) { vsum += val[i]; } long long *dp = new long long[vsum + 1]; for (long long i = 0; i < vsum + 1; i++) dp[i] = pow(10, 18) + 5; dp[0] = 0; for (int i = 0; i < n; i++) { for (long long j = vsum; j >= val[i]; j--) { dp[j] = min(dp[j], dp[j - val[i]] + weight[i]); } } long long i; for (i = vsum; i >= 0; i--) { if (dp[i] <= W) { // cout << i; break; } } delete[] dp; return i; } int main() { std::ios::sync_with_stdio(false); int n, W; std::cin >> n >> W; int *val = new int[n]; int *wt = new int[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } std::cout << knapSack3(W, wt, val, n) << endl; delete[] val; delete[] wt; return 0; }
[ "identifier.change", "call.function.change", "expression.operation.binary.change" ]
969,582
969,581
u930153819
cpp
p03164
/* ******************** Author : Sahil Kundu ******************** */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define mod 1000000007 #define pb(i) push_back(i) #define f first #define s second #define mk(l, r) make_pair(l, r) #define vi vector<int> #define vl vector<ll> #define vch vector<char> #define all(vc) vc.begin(), vc.end() #define pii pair<int, int> #define pll pair<ll, ll> #define ms(i, j) memset(i, j, sizeof i) #define w(t) while (t--) #define len(s) s.length() #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repa(i, n) for (ll i = n; i >= 0; i--) #define yes cout << "Yes\n" #define no cout << "No\n" #define PI 3.14159265358979323846 #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) const ll MAX = 1e5 + 5; const ll INF = 2e18; #define INPUT_OUTPUT \ { \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); \ } // logical code of program starts here. void solve() { int n, w; cin >> n >> w; ll mx = 1010 * n + 2; ll dp[mx]; ll val[n + 1], wt[n + 1]; rep(i, mx) dp[i] = INF; rep(i, n + 1) cin >> wt[i + 1] >> val[i + 1]; dp[0] = 0; rep(i, n + 1) { if (i == 0) continue; repa(x, mx - 1) { if (val[i] > x) break; dp[x] = min(dp[x], dp[x - val[i]] + wt[i]); } } repa(i, mx - 1) if (dp[i] <= w) { cout << i << endl; break; } } // mian function int main() { INPUT_OUTPUT; // file handling fastIO; // fast input output clock_t start, end; start = clock(); int t; t = 1; // cin>>t; w(t) solve(); end = clock(); double time_taken = double(end - start) / double(CLOCKS_PER_SEC); clog << "Time taken by program is : " << fixed << time_taken << setprecision(5); clog << " sec " << endl; return 0; }
/* ******************** Author : Sahil Kundu ******************** */ #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define mod 1000000007 #define pb(i) push_back(i) #define f first #define s second #define mk(l, r) make_pair(l, r) #define vi vector<int> #define vl vector<ll> #define vch vector<char> #define all(vc) vc.begin(), vc.end() #define pii pair<int, int> #define pll pair<ll, ll> #define ms(i, j) memset(i, j, sizeof i) #define w(t) while (t--) #define len(s) s.length() #define rep(i, n) for (ll i = 0; i < (n); ++i) #define repa(i, n) for (ll i = n; i >= 0; i--) #define yes cout << "Yes\n" #define no cout << "No\n" #define PI 3.14159265358979323846 #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) const ll MAX = 1e5 + 5; const ll INF = 2e18; #define INPUT_OUTPUT \ { \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); \ } // logical code of program starts here. void solve() { int n, w; cin >> n >> w; ll mx = 1010 * n + 2; ll dp[mx]; ll val[n + 1], wt[n + 1]; rep(i, mx) dp[i] = INF; rep(i, n + 1) cin >> wt[i + 1] >> val[i + 1]; dp[0] = 0; rep(i, n + 1) { if (i == 0) continue; repa(x, mx - 1) { if (val[i] > x) break; dp[x] = min(dp[x], dp[x - val[i]] + wt[i]); } } repa(i, mx - 1) if (dp[i] <= w) { cout << i << endl; break; } } // mian function int main() { // INPUT_OUTPUT;//file handling fastIO; // fast input output clock_t start, end; start = clock(); int t; t = 1; // cin>>t; w(t) solve(); end = clock(); double time_taken = double(end - start) / double(CLOCKS_PER_SEC); clog << "Time taken by program is : " << fixed << time_taken << setprecision(5); clog << " sec " << endl; return 0; }
[]
969,602
969,603
u398239969
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define int long long int const int N = 1e3 + 1; #define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl; const int inf = 1e15 + 7; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, w; cin >> n >> w; int wt[n + 1], val[n + 1]; int V(0); wt[0] = val[0] = 0; for (int i = 1; i <= n; i++) { cin >> wt[i] >> val[i]; V += val[i]; } std::vector<std::vector<int>> dp(n + 1, std::vector<int>(V + 2, inf)); // dp(i , j) --> represents minimum weight required to get value j if i items // are availiable dp[0][0] = 0; for (int item = 1; item <= n; item++) { dp[item][0] = 0; } for (int item = 1; item <= n; item++) { for (int value = 0; value <= V; value++) { if (value == 0) dp[item][value] = 0; else if (value >= val[item - 1]) { dp[item][value] = min(wt[item] + dp[item - 1][value - val[item]], dp[item - 1][value]); } else dp[item][value] = dp[item - 1][value]; } } for (int i = V; i >= 0; i--) { if (dp[n][i] <= w) { cout << i << ' '; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int const int N = 1e3 + 1; #define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl; const int inf = 1e15 + 7; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, w; cin >> n >> w; int wt[n + 1], val[n + 1]; int V(0); wt[0] = val[0] = 0; for (int i = 1; i <= n; i++) { cin >> wt[i] >> val[i]; V += val[i]; } std::vector<std::vector<int>> dp(n + 1, std::vector<int>(V + 2, inf)); // dp(i , j) --> represents minimum weight required to get value j if i items // are availiable dp[0][0] = 0; for (int item = 1; item <= n; item++) { dp[item][0] = 0; } for (int item = 1; item <= n; item++) { for (int value = 0; value <= V; value++) { if (value == 0) dp[item][value] = 0; else if (value >= val[item]) { dp[item][value] = min(wt[item] + dp[item - 1][value - val[item]], dp[item - 1][value]); } else dp[item][value] = dp[item - 1][value]; } } for (int i = V; i >= 0; i--) { if (dp[n][i] <= w) { cout << i << ' '; return 0; } } return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
969,604
969,605
u383071293
cpp
p03164
/// Journey to the End of earth /// /// Gunjan Kumar /// #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <functional> // for less // using namespace __gnu_pbds; using namespace std; #define ll long long #define s(n) scanf("%d", &n) #define ls(n) scanf("%lld", &n) #define p(n) printf("%d", n) // #define ln() printf("\n") #define pln(n) printf("%d\n", n) #define lpln(n) printf("%lld\n", n) #define rep(i, a, n) for (int i = a; i < n; i++) #define rev(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define tc \ ll t1; \ cin >> t1; \ while (t1--) #define inp \ ll n; \ cin >> n; \ ll arr[n]; \ rep(i, 0, n) cin >> arr[i]; #define vect vector<ll> #define sortv(v) sort(v.begin(), v.end()) #define lower(v, n) lower_bound(v.begin(), v.end(), n) - v.begin() #define upper(v, n) upper_bound(v.begin(), v.end(), n) - v.begin() #define bitcount(n) __builtin_popcount(n) #define ln << endl #define inf LONG_MAX #define ninf LONG_MIN #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const ll mod = 1e9 + 7; const ll N = 1e5 + 5; int main() { ll n, W; cin >> n >> W; vector<ll> v(n + 1); vector<ll> w(n + 1); for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; ll maxval = 3 * n; ll dp[n + 1][maxval + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= maxval; j++) { dp[i][j] = inf; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= maxval; j++) { dp[i][j] = dp[i - 1][j]; if (j >= v[i]) { if (dp[i - 1][j - v[i]] != inf) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } } int ans = 0; for (int i = 1; i <= maxval; i++) { if (dp[n][i] <= W) { // cout<<dp[n][i]<<endl; ans = i; } } cout << ans; return 0; }
/// Journey to the End of earth /// /// Gunjan Kumar /// #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // #include <functional> // for less // using namespace __gnu_pbds; using namespace std; #define ll long long #define s(n) scanf("%d", &n) #define ls(n) scanf("%lld", &n) #define p(n) printf("%d", n) // #define ln() printf("\n") #define pln(n) printf("%d\n", n) #define lpln(n) printf("%lld\n", n) #define rep(i, a, n) for (int i = a; i < n; i++) #define rev(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define tc \ ll t1; \ cin >> t1; \ while (t1--) #define inp \ ll n; \ cin >> n; \ ll arr[n]; \ rep(i, 0, n) cin >> arr[i]; #define vect vector<ll> #define sortv(v) sort(v.begin(), v.end()) #define lower(v, n) lower_bound(v.begin(), v.end(), n) - v.begin() #define upper(v, n) upper_bound(v.begin(), v.end(), n) - v.begin() #define bitcount(n) __builtin_popcount(n) #define ln << endl #define inf LONG_MAX #define ninf LONG_MIN #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); const ll mod = 1e9 + 7; const ll N = 1e5 + 5; int main() { ll n, W; cin >> n >> W; vector<ll> v(n + 1); vector<ll> w(n + 1); for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; ll maxval = 1000 * n; ll dp[n + 1][maxval + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= maxval; j++) { dp[i][j] = inf; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= maxval; j++) { dp[i][j] = dp[i - 1][j]; if (j >= v[i]) { if (dp[i - 1][j - v[i]] != inf) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } } } int ans = 0; for (int i = 1; i <= maxval; i++) { if (dp[n][i] <= W) { // cout<<dp[n][i]<<endl; ans = i; } } cout << ans; return 0; }
[ "literal.number.change", "expression.operation.binary.change" ]
969,606
969,607
u464439644
cpp
p03164
#include <bits/stdc++.h> #define int long long int #define float long double #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define set_pre(x, y) fixed << setprecision(y) << x #define w(t) \ int t; \ cin >> t; \ while (t--) using namespace std; int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int modi(int a, int m) { return power(a, m - 2, m); } int32_t main() { int n; cin >> n; int w; cin >> w; vector<int> wt(n, 0); vector<int> v(n, 0); int val = 0; for (int i = 0; i < n; i++) { cin >> wt[i] >> v[i]; val = max(val, v[i]); } vector<vector<int>> dp(n + 1, vector<int>(val * n + 1, INT_MAX)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= val * n; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + wt[i - 1]); } } int ans = 0; for (int i = 0; i <= val * n + 1; i++) { if (dp[n][i] <= w) { ans = i; } } cout << ans << endl; }
#include <bits/stdc++.h> #define int long long int #define float long double #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define set_pre(x, y) fixed << setprecision(y) << x #define w(t) \ int t; \ cin >> t; \ while (t--) using namespace std; int power(int x, int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int modi(int a, int m) { return power(a, m - 2, m); } int32_t main() { int n; cin >> n; int w; cin >> w; vector<int> wt(n, 0); vector<int> v(n, 0); int val = 0; for (int i = 0; i < n; i++) { cin >> wt[i] >> v[i]; val = max(val, v[i]); } vector<vector<int>> dp(n + 1, vector<int>(val * n + 1, INT_MAX)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= val * n; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + wt[i - 1]); } } int ans = 0; for (int i = 0; i <= val * n; i++) { if (dp[n][i] <= w) { ans = i; } } cout << ans << endl; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
969,615
969,616
u398139668
cpp
p03164
#include <cmath> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1LL << 60; const int MAX_V = pow(10, 3) * 100 + 1; int main() { int N; long long W; cin >> N >> W; int MAX_N = N; vector<long long> weight(MAX_N), value(MAX_N); for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_V, INF)); dp[0][0] = 0; // DPใƒซใƒผใƒ— for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใถๅ ดๅˆ if (sum_v - value[i] >= 0) chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]); // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใฐใชใ„ๅ ดๅˆ chmin(dp[i + 1][sum_v], dp[i][sum_v]); } } // ๆœ€้ฉๅ€คใฎๅ‡บๅŠ› long long res = 0; for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
#include <cmath> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1LL << 60; const int MAX_V = pow(10, 3) * 100 + 1; int main() { int N; long long W; cin >> N >> W; int MAX_N = N + 1; vector<long long> weight(MAX_N), value(MAX_N); for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_V, INF)); dp[0][0] = 0; // DPใƒซใƒผใƒ— for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใถๅ ดๅˆ if (sum_v - value[i] >= 0) chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]); // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใฐใชใ„ๅ ดๅˆ chmin(dp[i + 1][sum_v], dp[i][sum_v]); } } // ๆœ€้ฉๅ€คใฎๅ‡บๅŠ› long long res = 0; for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
[ "assignment.change" ]
969,617
969,618
u662420765
cpp
p03164
#include <climits> #include <iostream> #include <vector> using namespace std; #define ll long long int main() { ll N = 0; cin >> N; ll VAL = 0; cin >> VAL; ll V = 0; vector<vector<ll>> inp(N, vector<ll>(2)); for (ll i = 0; i < N; i++) { cin >> inp[i][0] >> inp[i][1]; V += inp[i][1]; } vector<ll> dp(V + 1, INT_MAX); dp[0] = 0; for (ll i = 0; i < N; i++) { for (ll j = V - inp[i][1]; j >= 0; j--) { dp[j + inp[i][1]] = min(dp[j + inp[i][1]], dp[j] + inp[i][0]); } } // for(ll i=0;i<N;i++){for(ll j=0;j<=VAL;j++)cout<<dp[i][j]<<" ";cout<<endl;} for (ll i = V; i >= 0; i--) { if (dp[i] <= VAL) { cout << dp[i] << endl; break; } } return 0; }
#include <climits> #include <iostream> #include <vector> using namespace std; #define ll long long int main() { ll N = 0; cin >> N; ll VAL = 0; cin >> VAL; ll V = 0; vector<vector<ll>> inp(N, vector<ll>(2)); for (ll i = 0; i < N; i++) { cin >> inp[i][0] >> inp[i][1]; V += inp[i][1]; } vector<ll> dp(V + 1, INT_MAX); dp[0] = 0; for (ll i = 0; i < N; i++) { for (ll j = V - inp[i][1]; j >= 0; j--) { dp[j + inp[i][1]] = min(dp[j + inp[i][1]], dp[j] + inp[i][0]); } } // for(ll i=0;i<N;i++){for(ll j=0;j<=VAL;j++)cout<<dp[i][j]<<" ";cout<<endl;} // for(int i=0;i<V;i++) cout<<dp[i]<<" "; // cout<<endl; for (ll i = V; i >= 0; i--) { if (dp[i] <= VAL) { cout << i << endl; break; } } return 0; }
[]
969,626
969,627
u309984532
cpp
p03164
#include "bits/stdc++.h" using namespace std; #define pb push_back #define F first #define S second //#define biGinf 9e+18 #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define inpv(v) \ for (auto &x : v) \ cin >> x #define otpv(v) \ for (auto &x : v) \ cout << x << nwl #define otpv2(v) \ for (auto &x : v) \ cout << x << " " #define CASES \ int tt; \ cin >> tt; \ while (tt--) #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define sz(v) (int)(v).size() using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vpii = vector<pii>; using int64 = long long; // const int64 biGinf = 9e+18; // const string yo = "YES", no = "NO"; const int inf = 2e9 + 7; const char nwl = '\n'; int64 calc(vpii &inp, int w, int n, int64 s) { vector<int64> res(s + 1, inf); res[0] = 0; for (auto t : inp) { for (int64 i = s; i >= t.F; i--) { res[i] = min(res[i], res[i - t.S] + (int64)t.F); } } // otpv2(res); // cout << nwl; int x = 0; for (int64 i = 0; i <= s; i++) { if (res[i] <= w) { x = i; } } return x; } int main() { // #ifndef ONLINE_JUDGE // if (fopen("input.txt", "r")) { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // } // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); // ur code int n, w; cin >> n >> w; vpii inp; int64 s = 0; for0(i, n) { int w, v; cin >> w >> v; s += (int64)v; inp.pb({w, v}); } sort(all(inp)); int64 ans = calc(inp, w, n, s); cout << ans; return 0; }
#include "bits/stdc++.h" using namespace std; #define pb push_back #define F first #define S second //#define biGinf 9e+18 #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define inpv(v) \ for (auto &x : v) \ cin >> x #define otpv(v) \ for (auto &x : v) \ cout << x << nwl #define otpv2(v) \ for (auto &x : v) \ cout << x << " " #define CASES \ int tt; \ cin >> tt; \ while (tt--) #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define sz(v) (int)(v).size() using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using vpii = vector<pii>; using int64 = long long; // const int64 biGinf = 9e+18; // const string yo = "YES", no = "NO"; const int inf = 2e9 + 7; const char nwl = '\n'; int64 calc(vpii &inp, int w, int n, int64 s) { vector<int64> res(s + 1, inf); res[0] = 0; for (auto t : inp) { for (int64 i = s; i >= t.S; i--) { res[i] = min(res[i], res[i - t.S] + (int64)t.F); } } // otpv2(res); // cout << nwl; int x = 0; for (int64 i = 0; i <= s; i++) { if (res[i] <= w) { x = i; } } return x; } int main() { // #ifndef ONLINE_JUDGE // if (fopen("input.txt", "r")) { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // } // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); // ur code int n, w; cin >> n >> w; vpii inp; int64 s = 0; for0(i, n) { int w, v; cin >> w >> v; s += (int64)v; inp.pb({w, v}); } sort(all(inp)); int64 ans = calc(inp, w, n, s); cout << ans; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
969,632
969,633
u814094996
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define FASTIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ll long long int #define ld long double #define vll vector<ll> #define pll pair<ll, ll> #define vl(p) vector<p> #define W while #define For(i, s, x) for (i = s; i < x; i++) #define Fore(i, s, x) For(i, s, x + 1) #define FoR(i, s, x) for (i = s - 1; i >= x; i--) #define ForE(i, s, x) FoR(i, s + 1, x) #define fi(i, s, x) for (int i = s; i < x; i++) #define all(v) v.begin(), v.end() #define pb push_back #define in insert #define sz size() #define F first #define S second #define nl cout << "\n" #define pr(a) cout << a << " " #define pr2(a, b) cout << a << " " << b << "\n" #define prA(a, m, n) \ fi(z, m, n + 1) pr(a[i]); \ nl #define trace2(x, y) \ cout << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define mod 1000000007 #define MAX 100005 int main() { FASTIO; ll t = 1, i, j, k, l; // cin>>t; W(t--) { ll n, M; cin >> n >> M; vll dp(MAX, MAX); dp[0] = 0; ll w, v, ans = 0; For(i, 0, n) { cin >> w >> v; FoR(j, MAX, v) if (dp[j - v] != -1 && dp[j - v] + w <= M) dp[j] = min(dp[j], dp[j - v] + w); } FoR(i, MAX, 0) { if (dp[i] != MAX) { ans = i; break; } } cout << ans; nl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FASTIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ll long long int #define ld long double #define vll vector<ll> #define pll pair<ll, ll> #define vl(p) vector<p> #define W while #define For(i, s, x) for (i = s; i < x; i++) #define Fore(i, s, x) For(i, s, x + 1) #define FoR(i, s, x) for (i = s - 1; i >= x; i--) #define ForE(i, s, x) FoR(i, s + 1, x) #define fi(i, s, x) for (int i = s; i < x; i++) #define all(v) v.begin(), v.end() #define pb push_back #define in insert #define sz size() #define F first #define S second #define nl cout << "\n" #define pr(a) cout << a << " " #define pr2(a, b) cout << a << " " << b << "\n" #define prA(a, m, n) \ fi(z, m, n + 1) pr(a[i]); \ nl #define trace2(x, y) \ cout << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define mod 1000000007 #define MAX 100005 int main() { FASTIO; ll t = 1, i, j, k, l; // cin>>t; W(t--) { ll n, M; cin >> n >> M; vll dp(MAX, 1000000000000); dp[0] = 0; ll w, v, ans = 0; For(i, 0, n) { cin >> w >> v; FoR(j, MAX, v) if (dp[j - v] != MAX && dp[j - v] + w <= M) dp[j] = min(dp[j], dp[j - v] + w); } FoR(i, MAX, 0) { if (dp[i] != 1000000000000) { ans = i; break; } } cout << ans; nl; } return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.branch.if.condition.change", "identifier.replace.remove", "literal.replace.add" ]
969,638
969,639
u356974909
cpp
p03164
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(obj) (obj).begin(), (obj).end() #define debug(var) \ do { \ std::cout << __LINE__ << "> " << #var << ": "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; void Main() { int N, W; cin >> N >> W; vl w(N); vi v(N); REP(i, N) cin >> w[i] >> v[i]; // int v_max = 100001; int v_max = 200; ll w_max = numeric_limits<ll>::max(); vvl dp(N + 1, vl(v_max, w_max)); dp[0][0] = 0; REP(i, N) { REP(j, v_max) { if (v[i] <= j && dp[i][j - v[i]] != w_max) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } int res = 0; REP(i, v_max) { if (dp[N][i] <= W) res = i; } cout << res << endl; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(obj) (obj).begin(), (obj).end() #define debug(var) \ do { \ std::cout << __LINE__ << "> " << #var << ": "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; void Main() { int N, W; cin >> N >> W; vl w(N); vi v(N); REP(i, N) cin >> w[i] >> v[i]; int v_max = 100001; ll w_max = numeric_limits<ll>::max(); vvl dp(N + 1, vl(v_max, w_max)); dp[0][0] = 0; REP(i, N) { REP(j, v_max) { if (v[i] <= j && dp[i][j - v[i]] != w_max) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } int res = 0; REP(i, v_max) { if (dp[N][i] <= W) res = i; } cout << res << endl; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }
[ "literal.number.change", "variable_declaration.value.change" ]
969,687
969,688
u215692812
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { int n, W; cin >> n >> W; vector<int> w(n), v(n); int val = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; val += v[i]; } vector<vector<int>> dp(n + 1, vector<int>(val + 1, 0)); dp[0][0] = 0; for (int i = 1; i <= val; i++) { dp[0][i] = 1e18; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= val; j++) { dp[i + 1][j] = dp[i][j]; if (j >= v[i]) { dp[i + 1][j] = min(dp[i][j], w[i] + dp[i][j - v[i]]); } if (dp[i + 1][j] <= W) { ans = max(ans, j); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, W; cin >> n >> W; vector<int> w(n), v(n); int val = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; val += v[i]; } vector<vector<long long int>> dp(n + 1, vector<long long int>(val + 1, 0)); dp[0][0] = 0; for (int i = 1; i <= val; i++) { dp[0][i] = 1e18; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= val; j++) { dp[i + 1][j] = dp[i][j]; if (j >= v[i]) { dp[i + 1][j] = min(dp[i][j], w[i] + dp[i][j - v[i]]); } if (dp[i + 1][j] <= W) { ans = max(ans, j); } } } cout << ans << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
969,689
969,690
u558282734
cpp
p03164
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define repk(i, k, n) for (int i = k; i < n; i++) #define MOD 1000000007 #define INF 1e9 #define PIE 3.14159265358979323 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; } template <class T> T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); } template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } #define int long long signed main() { int n, weight; cin >> n >> weight; vector<int> w(n); vector<int> v(n); rep(i, n) cin >> w[i] >> v[i]; vector<vector<int>> dp(n + 1, vector<int>(100100, MOD)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int sum_v = 0; sum_v <= 100100; sum_v++) { if (sum_v - v[i - 1] >= 0) chmin(dp[i][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); chmin(dp[i][sum_v], dp[i - 1][sum_v]); } } int ans = 0; for (int i = 0; i <= 100100; i++) { if (dp[n][i] <= weight) chmax(ans, i); } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define repk(i, k, n) for (int i = k; i < n; i++) #define MOD 1000000007 #define INF 1e9 #define PIE 3.14159265358979323 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; } template <class T> T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); } template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } #define int long long signed main() { int n, weight; cin >> n >> weight; vector<int> w(n); vector<int> v(n); rep(i, n) cin >> w[i] >> v[i]; vector<vector<int>> dp(n + 1, vector<int>(100101, MOD)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int sum_v = 0; sum_v <= 100100; sum_v++) { if (sum_v - v[i - 1] >= 0) chmin(dp[i][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); chmin(dp[i][sum_v], dp[i - 1][sum_v]); } } int ans = 0; for (int i = 0; i <= 100100; i++) { if (dp[n][i] <= weight) chmax(ans, i); } cout << ans << endl; return 0; }
[ "literal.number.change", "call.arguments.change" ]
969,707
969,708
u296160120
cpp
p03164
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define repk(i, k, n) for (int i = k; i < n; i++) #define MOD 1000000007 #define INF 1e9 #define PIE 3.14159265358979323 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; } template <class T> T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); } template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } #define int long long signed main() { int n, weight; cin >> n >> weight; vector<int> w(n); vector<int> v(n); rep(i, n) cin >> w[i] >> v[i]; vector<vector<int>> dp(n + 1, vector<int>(10010, MOD)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int sum_v = 0; sum_v <= 10010; sum_v++) { if (sum_v - v[i - 1] >= 0) chmin(dp[i][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); chmin(dp[i][sum_v], dp[i - 1][sum_v]); } } int ans = 0; for (int i = 0; i <= 10010; i++) { if (dp[n][i] <= weight) chmax(ans, i); } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) #define repk(i, k, n) for (int i = k; i < n; i++) #define MOD 1000000007 #define INF 1e9 #define PIE 3.14159265358979323 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; } template <class T> T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); } template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } #define int long long signed main() { int n, weight; cin >> n >> weight; vector<int> w(n); vector<int> v(n); rep(i, n) cin >> w[i] >> v[i]; vector<vector<int>> dp(n + 1, vector<int>(100101, MOD)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int sum_v = 0; sum_v <= 100100; sum_v++) { if (sum_v - v[i - 1] >= 0) chmin(dp[i][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); chmin(dp[i][sum_v], dp[i - 1][sum_v]); } } int ans = 0; for (int i = 0; i <= 100100; i++) { if (dp[n][i] <= weight) chmax(ans, i); } cout << ans << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
969,709
969,708
u296160120
cpp
p03164
#include <bits/stdc++.h> #define vll vector<ll> #define vi vector<int> #define vvi vector<vector<int>> #define vpll vector<pair<ll, ll>> #define pii pair<int, int> #define REP(i, a) for (int(i) = 0; (i) < (a); (i)++) #define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--) #define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define MOD 1000000007 #define INF 0x7FFFFFFF #define ALL(v) v.begin(), v.end() #define m0(x) memset(x, 0, sizeof(x)) typedef long long ll; using namespace std; ll N, W, w[105], v[105], dp[105][100005], ans; // dp[i][j] i็•ช็›ฎใฎ่ท็‰ฉใพใงใงไพกๅ€คjใ‚’้”ๆˆใ™ใ‚‹่ฉฐใ‚ๆ–นใงๆœ€ๅฐใฎ้‡ใฟ int main() { cin >> N >> W; REP(i, N) cin >> w[i] >> v[i]; REP(i, 105) REP(j, 100005) dp[i][j] = INF; dp[0][0] = 0; REP2(i, 1, N + 1) REP(j, 100001) { if (j - v[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); else dp[i][j] = dp[i - 1][j]; } ans = 100000; while (dp[N][ans] > W) ans--; cout << ans; return 0; }
#include <bits/stdc++.h> #define vll vector<ll> #define vi vector<int> #define vvi vector<vector<int>> #define vpll vector<pair<ll, ll>> #define pii pair<int, int> #define REP(i, a) for (int(i) = 0; (i) < (a); (i)++) #define RREP(i, a) for (int(i) = a - 1; (i) >= (0); (i)--) #define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define MOD 1000000007 #define INF 0x7FFFFFFF #define ALL(v) v.begin(), v.end() #define m0(x) memset(x, 0, sizeof(x)) typedef long long ll; using namespace std; ll N, W, w[105], v[105], dp[105][100005], ans; // dp[i][j] i็•ช็›ฎใฎ่ท็‰ฉใพใงใงไพกๅ€คjใ‚’้”ๆˆใ™ใ‚‹่ฉฐใ‚ๆ–นใงๆœ€ๅฐใฎ้‡ใฟ int main() { cin >> N >> W; REP(i, N) cin >> w[i + 1] >> v[i + 1]; REP(i, 105) REP(j, 100005) dp[i][j] = INF; dp[0][0] = 0; REP2(i, 1, N + 1) REP(j, 100001) { if (j - v[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); else dp[i][j] = dp[i - 1][j]; } ans = 100000; while (dp[N][ans] > W) ans--; cout << ans; return 0; }
[ "expression.operation.binary.add" ]
969,715
969,716
u997020010
cpp
p03164
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> typedef long long ll; #define rep(i, n) for (ll(i) = 0; i < (ll)(n); ++(i)) #define INF 10e12 #define MOD 1000000000 + 7 #define MX 51000 #define all(x) (x).begin(), (x).end() #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) using namespace std; struct nap { ll w; ll v; }; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll N, W; cin >> N >> W; ll takadaka = 1000 * N + 1; vector<ll> w(N); vector<ll> v(N); for (ll i = 0; i < N; ++i) cin >> w[i] >> v[i]; vector<vector<ll>> dp(N + 1, vector<ll>(takadaka + 1, INF)); dp[0][0] = 0; for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < takadaka; ++sum_v) { // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใถๅ ดๅˆ if (sum_v > v[i]) dp[i + 1][sum_v] = min(dp[i][sum_v], dp[i][sum_v - v[i]] + w[i]); // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใฐใชใ„ๅ ดๅˆ else dp[i + 1][sum_v] = dp[i][sum_v]; } } // ๆœ€้ฉๅ€คใฎๅ‡บๅŠ› long long res = 0; for (int sum_v = 0; sum_v < takadaka; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> typedef long long ll; #define rep(i, n) for (ll(i) = 0; i < (ll)(n); ++(i)) #define INF 10e12 #define MOD 1000000000 + 7 #define MX 51000 #define all(x) (x).begin(), (x).end() #define MAX(x) *max_element(all(x)) #define MIN(x) *min_element(all(x)) using namespace std; struct nap { ll w; ll v; }; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll N, W; cin >> N >> W; ll takadaka = 1000 * N + 1; vector<ll> w(N); vector<ll> v(N); for (ll i = 0; i < N; ++i) cin >> w[i] >> v[i]; vector<vector<ll>> dp(N + 1, vector<ll>(takadaka + 1, INF)); dp[0][0] = 0; for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < takadaka; ++sum_v) { // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใถๅ ดๅˆ if (sum_v >= v[i]) dp[i + 1][sum_v] = min(dp[i][sum_v], dp[i][sum_v - v[i]] + w[i]); // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใฐใชใ„ๅ ดๅˆ else dp[i + 1][sum_v] = dp[i][sum_v]; } } // ๆœ€้ฉๅ€คใฎๅ‡บๅŠ› long long res = 0; for (int sum_v = 0; sum_v < takadaka; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
969,722
969,723
u110044127
cpp
p03164
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int n; long long W; const long long INF = 110; const int MAX_N = 110; const int MAX_V = 100100; long long dp[110][100100]; int main() { cin >> n >> W; vector<long long> w(n, 0); vector<int> v(n, 0); for (int i = 0; i < n; ++i) { cin >> w.at(i) >> v.at(i); } for (int i = 0; i < MAX_N; ++i) { for (int j = 0; j < MAX_V; ++j) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < MAX_V; ++j) { if (j - v.at(i) >= 0) { chmin(dp[i + 1][j], dp[i][j - v.at(i)] + w.at(i)); } chmin(dp[i + 1][j], dp[i][j]); } } long long ans = 0; for (int i = 0; i < MAX_V; ++i) { if (dp[n][i] <= W) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int n; long long W; const long long INF = 1e12; const int MAX_N = 110; const int MAX_V = 100100; long long dp[110][100100]; int main() { cin >> n >> W; vector<long long> w(n, 0); vector<int> v(n, 0); for (int i = 0; i < n; ++i) { cin >> w.at(i) >> v.at(i); } for (int i = 0; i < MAX_N; ++i) { for (int j = 0; j < MAX_V; ++j) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < MAX_V; ++j) { if (j - v.at(i) >= 0) { chmin(dp[i + 1][j], dp[i][j - v.at(i)] + w.at(i)); } chmin(dp[i + 1][j], dp[i][j]); } } long long ans = 0; for (int i = 0; i < MAX_V; ++i) { if (dp[n][i] <= W) ans = i; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
969,730
969,731
u971089878
cpp
p03164
#define _USE_MATH_DEFINES #include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdint> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <new> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define lrep(i, n, m) for (int i = n; i < m; i++) using ll = long long; using Vii = vector<vector<int>>; using Gjudge = vector<vector<bool>>; using Vi = vector<int>; using Vl = vector<ll>; using Vll = vector<vector<ll>>; using Vs = vector<string>; using Vb = vector<bool>; using the = pair<int, int>; using lthe = pair<ll, ll>; 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; } const int Mod = static_cast<int>(1e9 + 7); const int INF = INT_MAX; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, w; cin >> n >> w; Vl W(n), V(n); rep(i, n) cin >> W[i] >> V[i]; ll MAXV = (1e3 + 1) * n; Vll dp(n + 1, Vl(MAXV, 1LL << 60)); //ๅˆๆœŸๆกไปถ dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= MAXV; j++) { if (j - V[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - V[i]] + W[i]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (ll j = 0; j <= MAXV; j++) { if (dp[n][j] <= w) ans = j; // cout << dp[n][j] << endl; } cout << ans << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdint> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <new> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define lrep(i, n, m) for (int i = n; i < m; i++) using ll = long long; using Vii = vector<vector<int>>; using Gjudge = vector<vector<bool>>; using Vi = vector<int>; using Vl = vector<ll>; using Vll = vector<vector<ll>>; using Vs = vector<string>; using Vb = vector<bool>; using the = pair<int, int>; using lthe = pair<ll, ll>; 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; } const int Mod = static_cast<int>(1e9 + 7); const int INF = INT_MAX; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, w; cin >> n >> w; Vl W(n), V(n); rep(i, n) cin >> W[i] >> V[i]; ll MAXV = (1e3 + 1) * n; Vll dp(n + 1, Vl(MAXV, 1LL << 60)); //ๅˆๆœŸๆกไปถ dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < MAXV; j++) { if (j - V[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - V[i]] + W[i]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (ll j = 0; j < MAXV; j++) { if (dp[n][j] <= w) ans = j; // cout << dp[n][j] << endl; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
969,740
969,741
u121734488
cpp
p03164
#define _USE_MATH_DEFINES #include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdint> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <new> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define lrep(i, n, m) for (int i = n; i < m; i++) using ll = long long; using Vii = vector<vector<int>>; using Gjudge = vector<vector<bool>>; using Vi = vector<int>; using Vl = vector<ll>; using Vll = vector<vector<ll>>; using Vs = vector<string>; using Vb = vector<bool>; using the = pair<int, int>; using lthe = pair<ll, ll>; 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; } const int Mod = static_cast<int>(1e9 + 7); const int INF = INT_MAX; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, w; cin >> n >> w; Vl W(n), V(n); rep(i, n) cin >> W[i] >> V[i]; ll MAXV = (1e3 + 1) * n; Vll dp(n + 1, Vl(MAXV, 1LL << 60)); //ๅˆๆœŸๆกไปถ dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= 1e3; j++) { if (j - V[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - V[i]] + W[i]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (ll j = 0; j <= MAXV; j++) { if (dp[n][j] <= w) ans = j; // cout << dp[n][j] << endl; } cout << ans << endl; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <cstdint> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <new> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define lrep(i, n, m) for (int i = n; i < m; i++) using ll = long long; using Vii = vector<vector<int>>; using Gjudge = vector<vector<bool>>; using Vi = vector<int>; using Vl = vector<ll>; using Vll = vector<vector<ll>>; using Vs = vector<string>; using Vb = vector<bool>; using the = pair<int, int>; using lthe = pair<ll, ll>; 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; } const int Mod = static_cast<int>(1e9 + 7); const int INF = INT_MAX; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, w; cin >> n >> w; Vl W(n), V(n); rep(i, n) cin >> W[i] >> V[i]; ll MAXV = (1e3 + 1) * n; Vll dp(n + 1, Vl(MAXV, 1LL << 60)); //ๅˆๆœŸๆกไปถ dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < MAXV; j++) { if (j - V[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - V[i]] + W[i]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (ll j = 0; j < MAXV; j++) { if (dp[n][j] <= w) ans = j; // cout << dp[n][j] << endl; } cout << ans << endl; }
[ "control_flow.loop.for.condition.change", "expression.operator.compare.change", "expression.off_by_one", "expression.operation.binary.change" ]
969,742
969,741
u121734488
cpp
p03164
#include <bits/stdc++.h> #define inf 1e18 #define N 1e5 + 5 #define ll long long int using namespace std; int main(void) { int n, W, i, j, s = 0; cin >> n >> W; int w[n], v[n]; for (i = 0; i < n; i++) { cin >> w[i] >> v[i]; s += v[i]; } ll dp[s]; for (i = 0; i < s; i++) dp[i] = inf; dp[0] = 0; for (i = 0; i < n; i++) { for (j = s - v[i]; j >= 0; j--) dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]); } ll ans = 0; for (i = 1; i < s; i++) { if (dp[i] < W) ans = i; } cout << ans; }
#include <bits/stdc++.h> #define inf 1e18 #define N 1e5 + 5 #define ll long long int using namespace std; int main(void) { // en("output.txt","w",stdout); //#endif int n, W, i, j, s = 0; cin >> n >> W; int w[n], v[n]; for (i = 0; i < n; i++) { cin >> w[i] >> v[i]; s += v[i]; } ll dp[s + 1]; for (i = 0; i <= s; i++) dp[i] = inf; dp[0] = 0; for (i = 0; i < n; i++) { for (j = s - v[i]; j >= 0; j--) dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]); } ll ans = 0; for (i = 0; i <= s; i++) { if (dp[i] <= W) ans = i; } cout << ans; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "literal.number.change", "assignment.value.change", "control_flow.loop.for.initializer.change", "control_flow.branch.if.condition.change" ]
969,776
969,777
u416759946
cpp
p03164
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; typedef pair<int, int> P; const int INF = 1001001001; const long double PI = (acos(-1)); const int mod = 1e9 + 7; const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, W; cin >> N >> W; vector<ll> v(N); vector<ll> w(N); ll sum = 0; rep(i, N) { cin >> w[i] >> v[i]; sum += v[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, INF)); dp[0][0] = 0; rep(i, N) { rep(j, sum + 1) { if (dp[i][j - v[i]] >= 0) dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; rep(j, sum + 1) { if (dp[N][j] <= W) ans = max(ans, j); } cout << ans << endl; cout << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < n; ++i) #define all(v) v.begin(), v.end() using namespace std; using ll = long long; typedef pair<int, int> P; const int INF = 1001001001; const long double PI = (acos(-1)); const int mod = 1e9 + 7; const int vx[4] = {0, 1, 0, -1}; const int vy[4] = {1, 0, -1, 0}; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, W; cin >> N >> W; vector<ll> v(N); vector<ll> w(N); ll sum = 0; rep(i, N) { cin >> w[i] >> v[i]; sum += v[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, INF)); dp[0][0] = 0; rep(i, N) { rep(j, sum + 1) { if (j - v[i] >= 0) dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; rep(j, sum + 1) { if (dp[N][j] <= W) ans = max(ans, j); } cout << ans << endl; cout << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
969,791
969,792
u154148649
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define prior priority_queue #define MOD 1000000007 #define INF64 (long long int)1e18 #define INF (int)1e9 #define PI 3.1415926535897932384626433832795 #define ll long long int #define ld long double #define ret return #define NUM 1000001 const int SIZE = 2e5 + 4; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void input() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int p[20000]; ll dp[200005]; int main() { fastio(); input(); ll N; ll W; cin >> N >> W; ll w[N + 1]; ll v[N + 1]; ll total_val = 0; for (ll i = 1; i <= N; i++) { cin >> w[i] >> v[i]; total_val += v[i]; } ll dp[N + 1][total_val + 1]; for (ll i = 0; i <= N; i++) { for (ll j = 0; j <= total_val; j++) { if (j == 0) { dp[i][j] = (ll)0; } else { dp[i][j] = INF64; } } } /* for(int i=0;i<=N;i++){ for(int j=0;j<=total_val;j++){ cout<<dp[i][j]<<" "; } cout<<endl; }*/ for (ll i = 1; i <= N; i++) { for (ll j = 1; j <= total_val; j++) { if (v[i] <= j) dp[i][j] = min(w[i] + dp[i - 1][j - v[i]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } ll ans = 0; for (ll i = 1; i <= total_val; i++) { if (dp[N][i] <= W) { ans = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define prior priority_queue #define MOD 1000000007 #define INF64 (long long int)1e18 #define INF (int)1e9 #define PI 3.1415926535897932384626433832795 #define ll long long int #define ld long double #define ret return #define NUM 1000001 const int SIZE = 2e5 + 4; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void input() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int p[20000]; ll dp[200005]; int main() { fastio(); // input(); ll N; ll W; cin >> N >> W; ll w[N + 1]; ll v[N + 1]; ll total_val = 0; for (ll i = 1; i <= N; i++) { cin >> w[i] >> v[i]; total_val += v[i]; } ll dp[N + 1][total_val + 1]; for (ll i = 0; i <= N; i++) { for (ll j = 0; j <= total_val; j++) { if (j == 0) { dp[i][j] = (ll)0; } else { dp[i][j] = INF64; } } } /* for(int i=0;i<=N;i++){ for(int j=0;j<=total_val;j++){ cout<<dp[i][j]<<" "; } cout<<endl; }*/ for (ll i = 1; i <= N; i++) { for (ll j = 1; j <= total_val; j++) { if (v[i] <= j) dp[i][j] = min(w[i] + dp[i - 1][j - v[i]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } ll ans = 0; for (ll i = 1; i <= total_val; i++) { if (dp[N][i] <= W) { ans = i; } } cout << ans << endl; return 0; }
[ "call.remove" ]
969,803
969,804
u168216888
cpp
p03164
/* auth - @sportykush */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //#define mp make_pair #define bug(v) cerr << #v << " = " << (v) << endl; #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define pb emplace_back #define vii vector<int> #define vll vector<ll> #define vpll vector<pair<ll, ll>> #define pll pair<ll, ll> #define pii pair<int, int> #define pq priority_queue<int> #define khtm "\n" #define F first #define S second #define fr(i, a, n) for (i = a; i < n; i++) #define mem(arr, l) memset(arr, l, sizeof arr) #define ALL(x) x.begin(), x.end() #define frr(i, a, n) for (i = n - 1; i >= a; i--) #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define testcase \ ll T; \ cin >> T; \ while (T--) const double pi = 3.14159265359; const int MAX = 1e6 + 2; const ll inf = 1e18; const int N = 1010; // const ll mod = 998244353 ; const ll mod = 1e9 + 7; inline ll add(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; } inline ll mul(ll a, ll b) { return ((a % mod) * 1ll * b) % mod; } inline ll power(ll a, ll b) { ll rt = 1; while (b > 0) { if (b & 1) rt = mul(rt, a); a = mul(a, a); b >>= 1; } return rt; } /* important builtin functions __gcd(value1, value2) __builtin_ffs(x) Number of leading zeroes: __builtin_clz(x) Number of trailing zeroes : __builtin_ctz(x) Number of set bits: __builtin_popcount(x) */ ll i, j, k, l, m, r, n; ll a[MAX], b[MAX]; ll dp[MAX]; int main() { // cout << setprecision(15) << fixed; fast ll val = 0; cin >> n >> k; fr(i, 1, 1 + n) { cin >> a[i] >> b[i]; val += b[i]; } fr(i, 0, val) dp[i] = inf; dp[0] = 0; for (int item = 1; item <= N; item++) { int w = a[item], v = b[item]; for (int i = val; i >= v; i--) { dp[i] = min(dp[i], dp[i - v] + w); } } ll ans = val; for (int i = val; i >= 0; i--) { if (dp[i] <= k) { ans = i; break; } } cout << ans; return 0; }
/* auth - @sportykush */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //#define mp make_pair #define bug(v) cerr << #v << " = " << (v) << endl; #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define pb emplace_back #define vii vector<int> #define vll vector<ll> #define vpll vector<pair<ll, ll>> #define pll pair<ll, ll> #define pii pair<int, int> #define pq priority_queue<int> #define khtm "\n" #define F first #define S second #define fr(i, a, n) for (i = a; i < n; i++) #define mem(arr, l) memset(arr, l, sizeof arr) #define ALL(x) x.begin(), x.end() #define frr(i, a, n) for (i = n - 1; i >= a; i--) #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define testcase \ ll T; \ cin >> T; \ while (T--) const double pi = 3.14159265359; const int MAX = 1e6 + 2; const ll inf = 1e18; const int N = 1010; // const ll mod = 998244353 ; const ll mod = 1e9 + 7; inline ll add(ll a, ll b) { a += b; if (a >= mod) a -= mod; return a; } inline ll mul(ll a, ll b) { return ((a % mod) * 1ll * b) % mod; } inline ll power(ll a, ll b) { ll rt = 1; while (b > 0) { if (b & 1) rt = mul(rt, a); a = mul(a, a); b >>= 1; } return rt; } /* important builtin functions __gcd(value1, value2) __builtin_ffs(x) Number of leading zeroes: __builtin_clz(x) Number of trailing zeroes : __builtin_ctz(x) Number of set bits: __builtin_popcount(x) */ ll i, j, k, l, m, r, n; ll a[MAX], b[MAX]; ll dp[MAX]; int main() { // cout << setprecision(15) << fixed; fast ll val = 0; cin >> n >> k; fr(i, 1, 1 + n) { cin >> a[i] >> b[i]; val += b[i]; } fr(i, 0, val + 1) dp[i] = inf; dp[0] = 0; for (int item = 1; item <= N; item++) { int w = a[item], v = b[item]; for (int i = val; i >= v; i--) { dp[i] = min(dp[i], dp[i - v] + w); } } ll ans = val; for (int i = val; i >= 0; i--) { if (dp[i] <= k) { ans = i; break; } } cout << ans; return 0; }
[ "assignment.change" ]
969,827
969,828
u897990209
cpp
p03164
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>((1000 * 100) + 1, 1000000000)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; ll weight, value; cin >> weight >> value; for (int j = 1; j <= 100000; j++) { dp[i][j] = min(dp[i - 1][j], j - value >= 0 ? dp[i - 1][j - value] + weight : 1000000000); } } int ans = 0; for (int i = 100000; i >= 0; i--) { if (dp[n][i] <= w) { ans = i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>((1000 * 100) + 1, 1000000001)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; ll weight, value; cin >> weight >> value; for (int j = 1; j <= 100000; j++) { dp[i][j] = min(dp[i - 1][j], (j - value >= 0) ? dp[i - 1][j - value] + weight : 1000000001); } } int ans = 0; for (int i = 100000; i >= 0; i--) { if (dp[n][i] <= w) { ans = i; break; } } cout << ans << endl; }
[ "literal.number.change", "call.arguments.change", "assignment.value.change" ]
969,831
969,832
u972556261
cpp
p03164
#include "bits/stdc++.h" using namespace std; #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define int long long #define mp make_pair #define ff first #define ss second #define pii pair<int, int> #define INF LLONG_MAX #define EPS 1e-9 #define all(v) (v).begin(), (v).end() #define sq(x) ((x) * (x)) #define foreach(it, v) for (auto it = (v).begin(); it != (v).end(); ++it) #define tr(...) \ cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \ trace(#__VA_ARGS__, __VA_ARGS__) #define tr(...) \ cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \ trace(#__VA_ARGS__, __VA_ARGS__) template <typename T> void trace(const char *name, T &&arg1) { cout << name << " : " << arg1 << endl; } template <typename T, typename... Args> void trace(const char *names, T &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; trace(comma + 1, args...); } typedef long double dbl; bool codejam = 0; const int MOD = 1000 * 1000 * 1000 + 7; const int NMAX = 1000 * 100 + 11; int n, m, p, q, k, a, b, c, ans; string s, str; char ch; int dp[NMAX][101]; int w[NMAX], v[NMAX]; void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } // memset(dp,1e12,sizeof(dp)); dp[0][0] = 0; int ans = 0; for (int i = 0; i <= 100; i++) { for (int j = 0; j <= n; j++) { if (i == 0) { dp[i][j] = 0; continue; } if (j == 0) { dp[i][j] = 1e13; continue; } dp[i][j] = dp[i][j - 1]; if (v[j] <= i) { dp[i][j] = min(dp[i][j], w[j] + dp[i - v[j]][j - 1]); // tr(i,j,dp[i][j]); } if (dp[i][j] <= m) { // tr(i,m); ans = max(ans, i); } } } cout << ans; } int32_t main() { fio; int t = 1; int cs = 1; // cin>>t; while (t--) { if (codejam) { cout << "Case #" << cs << ": "; } cs++; solve(); cout << "\n"; } }
#include "bits/stdc++.h" using namespace std; #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define int long long #define mp make_pair #define ff first #define ss second #define pii pair<int, int> #define INF LLONG_MAX #define EPS 1e-9 #define all(v) (v).begin(), (v).end() #define sq(x) ((x) * (x)) #define foreach(it, v) for (auto it = (v).begin(); it != (v).end(); ++it) #define tr(...) \ cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \ trace(#__VA_ARGS__, __VA_ARGS__) #define tr(...) \ cout << __FUNCTION__ << ' ' << __LINE__ << " = "; \ trace(#__VA_ARGS__, __VA_ARGS__) template <typename T> void trace(const char *name, T &&arg1) { cout << name << " : " << arg1 << endl; } template <typename T, typename... Args> void trace(const char *names, T &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; trace(comma + 1, args...); } typedef long double dbl; bool codejam = 0; const int MOD = 1000 * 1000 * 1000 + 7; const int NMAX = 1000 * 100 + 11; int n, m, p, q, k, a, b, c, ans; string s, str; char ch; int dp[NMAX][101]; int w[NMAX], v[NMAX]; void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } // memset(dp,1e12,sizeof(dp)); dp[0][0] = 0; int ans = 0; for (int i = 0; i <= 100000; i++) { for (int j = 0; j <= n; j++) { if (i == 0) { dp[i][j] = 0; continue; } if (j == 0) { dp[i][j] = 1e13; continue; } dp[i][j] = dp[i][j - 1]; if (v[j] <= i) { dp[i][j] = min(dp[i][j], w[j] + dp[i - v[j]][j - 1]); // tr(i,j,dp[i][j]); } if (dp[i][j] <= m) { // tr(i,m); ans = max(ans, i); } } } cout << ans; } int32_t main() { fio; int t = 1; int cs = 1; // cin>>t; while (t--) { if (codejam) { cout << "Case #" << cs << ": "; } cs++; solve(); cout << "\n"; } }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
969,839
969,840
u111764401
cpp
p03164
#include "bits/stdc++.h" using namespace std; #define F first #define S second #define show(x) cout << #x << " " << x << " "; #define f(i, j, k) for (int i = j; i <= k; i++) #define fr(i, j, k) for (int i = j; i >= k; i--) #define ll long long #define all(A) A.begin(), A.end() #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const int MSIZE = 1e2 + 5; const int MOD = 1e9 + 7; int wts[MSIZE]; int vals[MSIZE]; ll dp[MSIZE][(int)1e5 + 5]; const ll inf = 1e18 + 7; int main() { FIO int N, W; cin >> N >> W; f(i, 1, N) cin >> wts[i] >> vals[i]; // Bottom Up int vmax = N * 1e3; // Base Case f(i, 0, N) dp[i][0] = 0; f(i, 1, vmax) dp[0][i] = inf; f(i, 1, N) f(j, 1, vmax) { dp[i][j] = min((j >= vals[i]) ? (wts[i] + dp[i - 1][j - vals[i]]) : (ll)inf, dp[i - 1][j]); } int ans = 0; f(i, 1, vmax) { if (dp[N][i] < inf) { // cout<<i<<" "<<dp[N][i]<<endl; if (dp[N][i] <= W) ans = i; else break; } } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define F first #define S second #define show(x) cout << #x << " " << x << " "; #define f(i, j, k) for (int i = j; i <= k; i++) #define fr(i, j, k) for (int i = j; i >= k; i--) #define ll long long #define all(A) A.begin(), A.end() #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); const int MSIZE = 1e2 + 5; const int MOD = 1e9 + 7; int wts[MSIZE]; int vals[MSIZE]; ll dp[MSIZE][(int)1e5 + 5]; const ll inf = 1e18 + 7; int main() { FIO int N, W; cin >> N >> W; f(i, 1, N) cin >> wts[i] >> vals[i]; // Bottom Up int vmax = N * 1e3; // Base Case f(i, 0, N) dp[i][0] = 0; f(i, 1, vmax) dp[0][i] = inf; f(i, 1, N) f(j, 1, vmax) { dp[i][j] = min((j >= vals[i]) ? (wts[i] + dp[i - 1][j - vals[i]]) : (ll)inf, dp[i - 1][j]); } int ans = 0; f(i, 1, vmax) { if (dp[N][i] < inf) { // cout<<i<<" "<<dp[N][i]<<endl; if (dp[N][i] <= W) ans = i; // else break; } } cout << ans << endl; return 0; }
[ "control_flow.branch.else.remove" ]
969,845
969,846
u850655153
cpp
p03164
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <stdio.h> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) typedef long long ll; using namespace std; const ll MAX = 1000000; const ll MOD = 1000000007; ll fac[MAX]; // ใƒ†ใƒผใƒ–ใƒซใ‚’ไฝœใ‚‹ๅ‰ๅ‡ฆ็† /* void COMinit() { fac[0] = fac[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; } } */ ll pow_kai(ll a, ll n) { // aใฎnไน—ใ‚’่จˆ็ฎ—ใ—ใพใ™ใ€‚ ll x = 1; while (n > 0) { //ๅ…จใฆใฎbitใŒๆจใฆใ‚‰ใ‚Œใ‚‹ใพใงใ€‚ if (n & 1) { // 1็•ชๅณใฎbitใŒ1ใฎใจใใ€‚ x = x * a % MOD; } a = a * a % MOD; n >>= 1; // bitๅ…จไฝ“ใ‚’ๅณใซ1ใคใ‚ทใƒ•ใƒˆใ—ใฆไธ€็•ชๅณใ‚’ๆจใฆใ‚‹ใ€‚ } return x; } // ไบŒ้ …ไฟ‚ๆ•ฐ่จˆ็ฎ— ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; ll tmp = 1; for (ll i = n; i >= n - k + 1; i--) tmp = (tmp * i) % MOD; return (tmp * pow_kai(fac[k], MOD - 2)) % MOD; } void chmax(ll &a, const ll &b) { if (a < b) a = b; } void chmin(ll &a, const ll &b) { if (a > b) a = b; } int main() { ll N, W; cin >> N >> W; ll w[N], v[N], dp[100000 + 1]; rep(i, N) cin >> w[i] >> v[i]; rep(i, 100000 + 1) dp[i] = 10000000000000000; dp[0] = 0; rep(i, N) { for (int j = 100000; j >= 1; j--) { if (j - w[i] >= 0) { chmin(dp[j], dp[j - v[i]] + w[i]); } else { chmin(dp[j], w[i]); } } } ll ans = 0; rep(i, 100001) { if (dp[i] <= W) { ans = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <stdio.h> #include <vector> #define rep(i, n) for (ll i = 0; i < n; i++) typedef long long ll; using namespace std; const ll MAX = 1000000; const ll MOD = 1000000007; ll fac[MAX]; // ใƒ†ใƒผใƒ–ใƒซใ‚’ไฝœใ‚‹ๅ‰ๅ‡ฆ็† /* void COMinit() { fac[0] = fac[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; } } */ ll pow_kai(ll a, ll n) { // aใฎnไน—ใ‚’่จˆ็ฎ—ใ—ใพใ™ใ€‚ ll x = 1; while (n > 0) { //ๅ…จใฆใฎbitใŒๆจใฆใ‚‰ใ‚Œใ‚‹ใพใงใ€‚ if (n & 1) { // 1็•ชๅณใฎbitใŒ1ใฎใจใใ€‚ x = x * a % MOD; } a = a * a % MOD; n >>= 1; // bitๅ…จไฝ“ใ‚’ๅณใซ1ใคใ‚ทใƒ•ใƒˆใ—ใฆไธ€็•ชๅณใ‚’ๆจใฆใ‚‹ใ€‚ } return x; } // ไบŒ้ …ไฟ‚ๆ•ฐ่จˆ็ฎ— ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; ll tmp = 1; for (ll i = n; i >= n - k + 1; i--) tmp = (tmp * i) % MOD; return (tmp * pow_kai(fac[k], MOD - 2)) % MOD; } void chmax(ll &a, const ll &b) { if (a < b) a = b; } void chmin(ll &a, const ll &b) { if (a > b) a = b; } int main() { ll N, W; cin >> N >> W; ll w[N], v[N], dp[100000 + 1]; rep(i, N) cin >> w[i] >> v[i]; rep(i, 100000 + 1) dp[i] = 10000000000; dp[0] = 0; rep(i, N) { for (ll j = 100000; j >= 1; j--) { if (j - v[i] >= 0) { chmin(dp[j], dp[j - v[i]] + w[i]); } else { chmin(dp[j], w[i]); } } } ll ans = 0; rep(i, 100001) { if (dp[i] <= W) { ans = i; } } cout << ans << endl; return 0; }
[ "literal.number.change", "assignment.value.change", "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "identifier.change", "control_flow.branch.if.condition.change" ]
969,849
969,850
u722245896
cpp
p03164
#include <bits/stdc++.h> typedef long long int ll; #define pb push_back #define pp pair<ll, ll> #define vi vector<ll> #define vvi vector<vi> #define vb vector<bool> #define vvb vector<vb> using namespace std; int kp2(vi &profit, vi &wt, ll maxwt, ll maxv) { int n = profit.size(); vvi dp(n + 1, vi(maxv + 1, INT_MAX)); int ans = 0; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= maxv; j++) { if (j >= profit[i - 1]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - profit[i - 1]] + wt[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } if (dp[i][j] <= maxwt) { ans = max(ans, j); } } } return ans; } int main() { ll n, W; cin >> n >> W; ll tsum = 0; vector<ll> p(n); vector<ll> w(n); for (int i = 0; i < n; i++) { cin >> w[i] >> p[i]; tsum += p[i]; } cout << kp2(p, w, W, tsum); }
#include <bits/stdc++.h> typedef long long int ll; #define pb push_back #define pp pair<ll, ll> #define vi vector<ll> #define vvi vector<vi> #define vb vector<bool> #define vvb vector<vb> using namespace std; ll kp2(vi &profit, vi &wt, ll maxwt, ll maxv) { int n = profit.size(); vvi dp(n + 1, vi(maxv + 1, INT_MAX)); ll ans = 0; dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (ll j = 0; j <= maxv; j++) { if (j >= profit[i - 1]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - profit[i - 1]] + wt[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } if (dp[i][j] <= maxwt) { ans = max(ans, j); } } } return ans; } int main() { ll n, W; cin >> n >> W; ll tsum = 0; vector<ll> p(n); vector<ll> w(n); for (int i = 0; i < n; i++) { cin >> w[i] >> p[i]; tsum += p[i]; } cout << kp2(p, w, W, tsum); }
[ "variable_declaration.type.change", "control_flow.loop.for.initializer.change", "literal.number.change", "variable_declaration.value.change", "expression.off_by_one" ]
969,855
969,856
u704524932
cpp
p03164
#include <bits/stdc++.h> using namespace std; const int N = 110; const int L = N * 1e3 + 10; int w[N], v[N]; long long dp[N][L]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, W; cin >> n >> W; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 1; i < L; i++) dp[0][i] = 1e10; int Max = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < L; j++) { dp[i][j] = dp[i - 1][j]; if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); if (Max < j && dp[i][j] <= W) Max = j; } } cout << Max; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 110; const int L = N * 1e3 + 10; int w[N], v[N]; long long dp[N][L]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, W; cin >> n >> W; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 1; i < L; i++) dp[0][i] = 1e10; int Max = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < L; j++) { dp[i][j] = dp[i - 1][j]; if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); if (Max < j && dp[i][j] <= W) Max = j; } } cout << Max; 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" ]
969,863
969,864
u872069739
cpp
p03164
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long int lint; typedef long long int llint; #define INF 2147000000 #define LINF 9223372036000000000 int n, w; llint dp[110][110000], we[110], v[110]; int main() { cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> we[i] >> v[i]; } for (int i = 1; i < 110000; i++) { dp[0][i] = LINF; } for (int i = 1; i <= n; i++) { for (int j = 1; j < 110000; j++) { dp[i][j] = dp[i - 1][j]; if (j - v[i] >= 0) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + we[i]); } } } int ans = 0; for (int i = 0; i < 110000; i++) { if (dp[n][i] <= w) { ans = max(ans, i); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long int lint; typedef long long int llint; #define INF 1073741824 #define LINF 4611686018000000000 int n, w; llint dp[110][110000], we[110], v[110]; int main() { cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> we[i] >> v[i]; } for (int i = 1; i < 110000; i++) { dp[0][i] = LINF; } for (int i = 1; i <= n; i++) { for (int j = 1; j < 110000; j++) { dp[i][j] = dp[i - 1][j]; if (j - v[i] >= 0) { dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + we[i]); } } } int ans = 0; for (int i = 0; i < 110000; i++) { if (dp[n][i] <= w) { ans = max(ans, i); } } cout << ans << endl; return 0; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
969,874
969,875
u104889348
cpp
p03164
// secreterror #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; i++) #define rev(i, n) for (ll i = n - 1; i >= 0; i--) #define forr(i, x, y) for (ll i = x; i < y; i++) #define f first #define s second #define vll vector<ll> #define vvll vector<vector<ll>> #define vpii vector<pair<int, int>> int main() { ll n, w; cin >> n >> w; vector<ll> weigh(n); vector<ll> val(n); rep(i, n) { cin >> weigh[i] >> val[i]; } ll sum = 0; rep(i, n) { sum += val[i]; } vector<ll> dp(sum + 1, 10000000000); // mini w for any val dp[0] = 0; for (ll i = 0; i < n; i++) { for (ll alr = sum - val[i]; alr >= 0; alr--) { dp[alr + val[i]] = min(dp[alr + val[i]], dp[alr] + weigh[i]); } } ll ans = 0; for (ll i = 0; i < sum; i++) { if (dp[i] <= w) { ans = max(ans, (ll)i); } } cout << ans << endl; }
// secreterror #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; i++) #define rev(i, n) for (ll i = n - 1; i >= 0; i--) #define forr(i, x, y) for (ll i = x; i < y; i++) #define f first #define s second #define vll vector<ll> #define vvll vector<vector<ll>> #define vpii vector<pair<int, int>> int main() { ll n, w; cin >> n >> w; vector<ll> weigh(n); vector<ll> val(n); rep(i, n) { cin >> weigh[i] >> val[i]; } ll sum = 0; rep(i, n) { sum += val[i]; } vector<ll> dp(sum + 1, 10000000000); // mini w for any val dp[0] = 0; for (ll i = 0; i < n; i++) { for (ll alr = sum - val[i]; alr >= 0; alr--) { dp[alr + val[i]] = min(dp[alr + val[i]], dp[alr] + weigh[i]); } } ll ans = 0; for (ll i = 0; i <= sum; i++) { if (dp[i] <= w) { ans = max(ans, (ll)i); } } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
969,881
969,882
u878396672
cpp
p03164
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int INF = 1e9 + 1; int main() { int N, W; cin >> N >> W; vector<ll> value(N), weight(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(N * 1001, INF)); dp[0][0] = 0; for (int n = 0; n < N; n++) { for (ll v = 0; v <= N * 1001; v++) { if (v >= value[n]) { dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]); } else { dp[n + 1][v] = dp[n][v]; } } } ll best_score = 0; for (ll j = 0; j <= N * 1001; j++) { if (dp[N][j] <= W) { // cout<<dp[N][j]<<" "; best_score = max(best_score, j); } } cout << best_score << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int INF = 1e9 + 1; int main() { int N, W; cin >> N >> W; vector<ll> value(N), weight(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(N * 1010 + 1, INF)); dp[0][0] = 0; for (int n = 0; n < N; n++) { for (ll v = 0; v <= N * 1010; v++) { if (v >= value[n]) { dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]); } else { dp[n + 1][v] = dp[n][v]; } } } ll best_score = 0; for (ll j = 0; j <= N * 1010; j++) { if (dp[N][j] <= W) { // cout<<dp[N][j]<<" "; best_score = max(best_score, j); } } cout << best_score << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change", "control_flow.loop.for.condition.change" ]
969,897
969,898
u440276250
cpp
p03164
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int INF = 1e9 + 1; int main() { int N, W; cin >> N >> W; vector<ll> value(N), weight(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(N * 1010, INF)); dp[0][0] = 0; for (int n = 0; n < N; n++) { for (ll v = 0; v <= N * 1010; v++) { if (v >= value[n]) { dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]); } else { dp[n + 1][v] = dp[n][v]; } } } ll best_score = 0; for (ll j = 0; j <= N * 1010; j++) { if (dp[N][j] <= W) { // cout<<dp[N][j]<<" "; best_score = max(best_score, j); } } cout << best_score << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int INF = 1e9 + 1; int main() { int N, W; cin >> N >> W; vector<ll> value(N), weight(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(N * 1010 + 1, INF)); dp[0][0] = 0; for (int n = 0; n < N; n++) { for (ll v = 0; v <= N * 1010; v++) { if (v >= value[n]) { dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]); } else { dp[n + 1][v] = dp[n][v]; } } } ll best_score = 0; for (ll j = 0; j <= N * 1010; j++) { if (dp[N][j] <= W) { // cout<<dp[N][j]<<" "; best_score = max(best_score, j); } } cout << best_score << endl; return 0; }
[ "assignment.change" ]
969,899
969,898
u440276250
cpp
p03164
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int INF = 1e9 + 1; int main() { int N, W; cin >> N >> W; vector<ll> value(N), weight(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(N * 1001, INF)); dp[0][0] = 0; for (int n = 0; n < N; n++) { for (ll v = 0; v <= N * 1010; v++) { if (v >= value[n]) { dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]); } else { dp[n + 1][v] = dp[n][v]; } } } ll best_score = 0; for (ll j = 0; j <= N * 1010; j++) { if (dp[N][j] <= W) { // cout<<dp[N][j]<<" "; best_score = max(best_score, j); } } cout << best_score << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int INF = 1e9 + 1; int main() { int N, W; cin >> N >> W; vector<ll> value(N), weight(N); for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(N * 1010 + 1, INF)); dp[0][0] = 0; for (int n = 0; n < N; n++) { for (ll v = 0; v <= N * 1010; v++) { if (v >= value[n]) { dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]); } else { dp[n + 1][v] = dp[n][v]; } } } ll best_score = 0; for (ll j = 0; j <= N * 1010; j++) { if (dp[N][j] <= W) { // cout<<dp[N][j]<<" "; best_score = max(best_score, j); } } cout << best_score << endl; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change" ]
969,902
969,898
u440276250
cpp
p03164
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; using ll = long long; using _TYPE = int; typedef tree<_TYPE, null_type, less<_TYPE>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int inp[100005][3]; ll dp[105][100005]; int n, w; ll solve(int i, int remPrice) { if (i == n) { if (remPrice == 0) return 0; return (ll)1e9; } ll &rt = dp[i][remPrice]; if (rt != -1) return rt; rt = solve(i + 1, remPrice); rt = min(rt, solve(i + 1, remPrice - inp[i][1]) + inp[i][0]); return rt; } int main() { IO; cin >> n >> w; for (int i = 0; i < n; i++) cin >> inp[i][0] >> inp[i][1]; memset(dp, -1, sizeof dp); for (int i = 100000; i >= 0; i--) { ll rt = solve(0, i); if (rt <= w) { cout << i; return 0; } } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; using ll = long long; using _TYPE = int; typedef tree<_TYPE, null_type, less<_TYPE>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define IO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int inp[100005][3]; ll dp[105][100005]; int n, w; ll solve(int i, int remPrice) { if (i == n) { if (remPrice == 0) return 0; return (ll)1e17; } ll &rt = dp[i][remPrice]; if (rt != -1) return rt; rt = solve(i + 1, remPrice); rt = min(rt, solve(i + 1, remPrice - inp[i][1]) + inp[i][0]); return rt; } int main() { IO; cin >> n >> w; for (int i = 0; i < n; i++) cin >> inp[i][0] >> inp[i][1]; memset(dp, -1, sizeof dp); for (int i = 100000; i >= 0; i--) { ll rt = solve(0, i); if (rt <= w) { cout << i; return 0; } } return 0; }
[ "literal.number.change", "function.return_value.change" ]
969,914
969,915
u933476247
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) const int maxn = 1e5 + 3; long long n, maxWeight; long long dp[105][maxn], price[105], weight[105]; long long solve(int indx, long long remPrice) { if (indx >= n) { if (remPrice == 0) return 0; return 1e17; } if (dp[indx][remPrice] != -1) return dp[indx][remPrice]; long long ans = 1e17; if (remPrice - price[indx] >= 0) ans = min(ans, weight[indx] + solve(indx + 1, remPrice - price[indx])); ans = min(ans, solve(indx + 1, remPrice)); return dp[indx][remPrice] = ans; } int main() { IO; cin >> n >> maxWeight; for (int i = 0; i < n; i++) cin >> weight[i] >> price[i]; memset(dp, -1, sizeof dp); for (int currPrice = 1e5; currPrice >= 0; currPrice--) { long long ans = solve(0, currPrice); if (maxWeight >= ans) { break; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) const int maxn = 1e5 + 3; long long n, maxWeight; long long dp[105][maxn], price[105], weight[105]; long long solve(int indx, long long remPrice) { if (indx >= n) { if (remPrice == 0) return 0; return 1e17; } if (dp[indx][remPrice] != -1) return dp[indx][remPrice]; long long ans = 1e17; if (remPrice - price[indx] >= 0) ans = min(ans, weight[indx] + solve(indx + 1, remPrice - price[indx])); ans = min(ans, solve(indx + 1, remPrice)); return dp[indx][remPrice] = ans; } int main() { IO; cin >> n >> maxWeight; for (int i = 0; i < n; i++) cin >> weight[i] >> price[i]; memset(dp, -1, sizeof dp); for (int currPrice = 1e5; currPrice >= 0; currPrice--) { long long ans = solve(0, currPrice); if (maxWeight >= ans) { cout << currPrice; break; } } return 0; }
[]
969,916
969,917
u933476247
cpp
p03164
#include <algorithm> #include <assert.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <tuple> #include <vector> //#include <bits/stdc++.h> #define maxs(x, y) x = max(x, y) #define mins(x, y) x = min(x, y) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repr(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, i0, n) for (int(i) = (i0); (i) < (n); (i)++) #define FORR(i, i0, n) for (int(i) = (n)-1; (i) >= (i0); (i)--) #define SORT(x) sort(x.begin(), x.end()) #define SORTR(x) sort(x.begin(), x.end(), greater<>()) #define rn return #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; typedef std::pair<ll, ll> P; //#include <boost/multiprecision/cpp_int.hpp> // using bint = boost::multiprecision::cpp_int; int main() { int n, W; cin >> n >> W; vector<ll> w(n); vector<int> v(n); rep(i, n) cin >> w[i] >> v[i]; int vMax = 1e7; ll wMAX = 1e12 * 1LL; vector<vector<ll>> dp(n, vector<ll>(vMax, wMAX)); rep(i, v[0] + 1) { dp[0][i] = w[0]; } dp[0][0] = 0LL; rep(i, n - 1) { rep(oldV, 1e6 + 1) { int newV = oldV + v[i + 1]; dp[i + 1][oldV] = min(dp[i + 1][oldV], dp[i][oldV]); dp[i + 1][newV] = min(dp[i + 1][newV], dp[i][oldV] + w[i + 1]); } } int ans = 0; rep(i, 1e6 + 1) { if (dp[n - 1][i] <= W) ans = i; } cout << ans; }
#include <algorithm> #include <assert.h> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <tuple> #include <vector> //#include <bits/stdc++.h> #define maxs(x, y) x = max(x, y) #define mins(x, y) x = min(x, y) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repr(i, n) for (int i = (n)-1; i >= 0; i--) #define FOR(i, i0, n) for (int(i) = (i0); (i) < (n); (i)++) #define FORR(i, i0, n) for (int(i) = (n)-1; (i) >= (i0); (i)--) #define SORT(x) sort(x.begin(), x.end()) #define SORTR(x) sort(x.begin(), x.end(), greater<>()) #define rn return #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; typedef std::pair<ll, ll> P; //#include <boost/multiprecision/cpp_int.hpp> // using bint = boost::multiprecision::cpp_int; int main() { int n, W; cin >> n >> W; vector<ll> w(n); vector<int> v(n); rep(i, n) cin >> w[i] >> v[i]; int vMax = 1e6; ll wMAX = 1e12 * 1LL; vector<vector<ll>> dp(n, vector<ll>(vMax, wMAX)); rep(i, v[0] + 1) { dp[0][i] = w[0]; } dp[0][0] = 0LL; rep(i, n - 1) { rep(oldV, 1e5 + 1) { int newV = oldV + v[i + 1]; dp[i + 1][oldV] = min(dp[i + 1][oldV], dp[i][oldV]); dp[i + 1][newV] = min(dp[i + 1][newV], dp[i][oldV] + w[i + 1]); } } int ans = 0; rep(i, 1e5 + 1) { if (dp[n - 1][i] <= W) ans = i; } cout << ans; }
[ "literal.number.change", "variable_declaration.value.change", "call.arguments.change", "expression.operation.binary.change" ]
969,920
969,921
u358748139
cpp
p03164
#include <bits/stdc++.h> using namespace std; #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 sz(v) (int)v.size() #define pii pair<int, int> #define fi first #define se second #define forn(i, a, b) for (int i = a; i < b; i++) #define deb(x) cout << #x << ' ' << x << endl #define clock \ cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int n, w; pii p[105]; int cache[105][100005]; int dp(int idx, int val) { if (val == 0) return 0; if (val < 0 || idx == n) return 1e15; int &ans = cache[idx][val]; if (ans != -1) return ans; ans = min(dp(idx + 1, val), p[idx].fi + dp(idx + 1, val - p[idx].se)); return ans; } int32_t main() { IOS INPUT(); cin >> n >> w; forn(i, 0, n) cin >> p[i].fi >> p[i].se; memset(cache, -1, sizeof(cache)); int ans = 0; forn(i, 1, 1e5 + 1) { int mwt = dp(0, i); if (mwt <= w) ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #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 sz(v) (int)v.size() #define pii pair<int, int> #define fi first #define se second #define forn(i, a, b) for (int i = a; i < b; i++) #define deb(x) cout << #x << ' ' << x << endl #define clock \ cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int n, w; pii p[105]; int cache[105][100005]; int dp(int idx, int val) { if (val == 0) return 0; if (val < 0 || idx == n) return 1e15; int &ans = cache[idx][val]; if (ans != -1) return ans; ans = min(dp(idx + 1, val), p[idx].fi + dp(idx + 1, val - p[idx].se)); return ans; } int32_t main() { IOS // INPUT(); cin >> n >> w; forn(i, 0, n) cin >> p[i].fi >> p[i].se; memset(cache, -1, sizeof(cache)); int ans = 0; forn(i, 1, 1e5 + 1) { int mwt = dp(0, i); if (mwt <= w) ans = i; } cout << ans << endl; return 0; }
[ "variable_declaration.remove" ]
969,934
969,935
u041396154
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { long long n, w; cin >> n >> w; vector<long long> weight(n), value(n); for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } int sum = 0; for (auto j : value) { sum += j; } vector<long long> dp(sum + 1, 1000000001); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = sum; j >= 0; j--) { if (j - value[i] >= 0) { dp[j] = min(dp[j], dp[j - value[i]] + weight[i]); } // cout<<dp[j]<<" "; } } long long ans = 1000000001; for (int i = 0; i <= dp.size(); i++) { if (dp[i] <= w) ans = i; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, w; cin >> n >> w; vector<long long> weight(n), value(n); for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } int sum = 0; for (auto j : value) { sum += j; } vector<long long> dp(sum + 1, 1000000001); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = sum; j >= 0; j--) { if (j - value[i] >= 0) { dp[j] = min(dp[j], dp[j - value[i]] + weight[i]); } // cout<<dp[j]<<" "; } } long long ans = 1000000001; for (int i = 0; i < dp.size(); i++) { if (dp[i] <= w) ans = i; } cout << ans; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
969,946
969,947
u754735988
cpp
p03164
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, W; cin >> n >> W; ll w[n + 1], v[n + 1]; ll profit = 0; for (ll i = 1; i <= n; i++) { cin >> w[i] >> v[i]; profit += v[i]; } ll a[n + 1][profit + 1]; for (ll i = 0; i <= n; i++) { for (ll j = 0; j <= profit; j++) { if (i == 0 && j == 0) { a[i][j] = 0; continue; } if (i == 0) { a[i][j] = 1e11; continue; } if (j - w[i] < 0) { a[i][j] = a[i - 1][j]; } else { a[i][j] = min(a[i - 1][j], w[i] + a[i - 1][j - v[i]]); } } } ll ans = 0; for (ll i = 0; i <= profit; i++) { if (a[n][i] <= W) { ans = i; } } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, W; cin >> n >> W; ll w[n + 1], v[n + 1]; ll profit = 0; for (ll i = 1; i <= n; i++) { cin >> w[i] >> v[i]; profit += v[i]; } ll a[n + 1][profit + 1]; for (ll i = 0; i <= n; i++) { for (ll j = 0; j <= profit; j++) { if (i == 0 && j == 0) { a[i][j] = 0; continue; } if (i == 0) { a[i][j] = 1e11; continue; } if (j - v[i] < 0) { a[i][j] = a[i - 1][j]; } else { a[i][j] = min(a[i - 1][j], w[i] + a[i - 1][j - v[i]]); } } } ll ans = 0; for (ll i = 0; i <= profit; i++) { if (a[n][i] <= W) { ans = i; } } cout << ans; return 0; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
969,948
969,949
u948379857
cpp
p03164
// recurive code hai 0/1 knapsack ka #include <bits/stdc++.h> #include <cstdlib> using namespace std; #define int long long #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ip(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define op(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; #define MAX 100001 void start() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int dp[101][MAX]; int *wt, *val; int solve(int capacity, int n, int profit) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= profit; j++) { if (i == 0 && j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = 1e11; else if (j >= val[i - 1]) { dp[i][j] = min(wt[i - 1] + dp[i - 1][j - val[i - 1]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } int ans = 0; for (int i = 0; i <= profit; i++) { if (dp[n][i] <= capacity) ans = i; } return ans; } int32_t main() { start(); fastIO int n, capacity; cin >> n >> capacity; wt = new int[n]; val = new int[n]; int profit = 0; for (int i = 0; i < n; i++) { cin >> wt[i]; cin >> val[i]; profit += val[i]; } // memset(dp,-1,sizeof(dp)); // cout<<knapsack(wt,val,capacity,n)<<endl; // cout<<memoization(wt,val,capacity,n)<<endl; memset(dp, 0, sizeof(dp)); cout << solve(capacity, n, profit) << endl; }
// recurive code hai 0/1 knapsack ka #include <bits/stdc++.h> #include <cstdlib> using namespace std; #define int long long #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ip(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define op(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; #define MAX 100001 void start() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int dp[101][MAX]; int *wt, *val; int solve(int capacity, int n, int profit) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= profit; j++) { if (i == 0 && j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = 1e11; else if (j >= val[i - 1]) { dp[i][j] = min(wt[i - 1] + dp[i - 1][j - val[i - 1]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } int ans = 0; for (int i = 0; i <= profit; i++) { if (dp[n][i] <= capacity) ans = i; } return ans; } int32_t main() { // start(); fastIO int n, capacity; cin >> n >> capacity; wt = new int[n]; val = new int[n]; int profit = 0; for (int i = 0; i < n; i++) { cin >> wt[i]; cin >> val[i]; profit += val[i]; } // memset(dp,-1,sizeof(dp)); // cout<<knapsack(wt,val,capacity,n)<<endl; // cout<<memoization(wt,val,capacity,n)<<endl; memset(dp, 0, sizeof(dp)); cout << solve(capacity, n, profit) << endl; }
[ "call.remove" ]
969,950
969,951
u948429045
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll N, W, TS = 0; cin >> N >> W; ll w[N + 1], v[N + 1]; for (ll i = 1; i <= N; i++) { cin >> w[i] >> v[i]; TS += v[i]; } // dp[i]=min weight required to reach value i vector<ll> V(TS + 1, INT_MAX); V[0] = 0; for (ll i = 1; i <= N; i++) { for (ll j = TS - v[i]; j >= 0; j--) { V[j + v[i]] = min(V[j + v[i]], V[j] + w[i]); } } int K = 0; for (int i = 0; i <= TS; i++) { if (V[i] <= W) { K = V[i]; } } cout << K; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll N, W, TS = 0; cin >> N >> W; ll w[N + 1], v[N + 1]; for (ll i = 1; i <= N; i++) { cin >> w[i] >> v[i]; TS += v[i]; } // dp[i]=min weight required to reach value i vector<ll> V(TS + 1, INT_MAX); V[0] = 0; for (ll i = 1; i <= N; i++) { for (ll j = TS - v[i]; j >= 0; j--) { V[j + v[i]] = min(V[j + v[i]], V[j] + w[i]); } } int K = 0; for (int i = 0; i <= TS; i++) { if (V[i] <= W) { K = i; } } cout << K; return 0; }
[]
969,952
969,953
u608574730
cpp
p03164
#include <bits/stdc++.h> using namespace std; static const int INF = 1000000000; int main() { int N; int64_t W; cin >> N >> W; vector<int64_t> w(N); vector<int> v(N); for (int i = 0; i < N; i++) { cin >> w.at(i); cin >> v.at(i); } vector<vector<int64_t>> dp(1 + N, vector<int64_t>(100001, 0)); for (int j = 1; j <= 100000; j++) dp[0][j] = INF; for (int i = 1; i <= N; i++) { for (int j = 1; j <= 100000; j++) { if (v[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); else dp[i][j] = min(dp[i - 1][j], w[i - 1]); } } auto itr = upper_bound(dp[N].begin(), dp[N].end(), W); int ans = distance(dp[N].begin(), itr) - 1; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; static const int INF = 100000000000; int main() { int N; int64_t W; cin >> N >> W; vector<int64_t> w(N); vector<int> v(N); for (int i = 0; i < N; i++) { cin >> w.at(i); cin >> v.at(i); } vector<vector<int64_t>> dp(1 + N, vector<int64_t>(100001, 0)); for (int j = 1; j <= 100000; j++) dp[0][j] = INF; for (int i = 1; i <= N; i++) { for (int j = 1; j <= 100000; j++) { if (v[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); else dp[i][j] = min(dp[i - 1][j], w[i - 1]); } } auto itr = upper_bound(dp[N].begin(), dp[N].end(), W); int ans = distance(dp[N].begin(), itr) - 1; cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
969,963
969,964
u101018317
cpp
p03164
#include <bits/stdc++.h> using namespace std; static const int INF = 1000000000; int main() { int N; int64_t W; cin >> N >> W; vector<int64_t> w(N); vector<int> v(N); for (int i = 0; i < N; i++) { cin >> w.at(i); cin >> v.at(i); } vector<vector<int64_t>> dp(1 + N, vector<int64_t>(100001, 0)); for (int j = 1; j <= 100000; j++) dp[0][j] = INF; for (int i = 1; i <= N; i++) { for (int j = 1; j <= 100000; j++) { if (v[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); else dp[i][j] = min(dp[i - 1][j], w[i - 1]); } } auto itr = upper_bound(dp[N].begin(), dp[N].end(), W); int ans = distance(dp[N].begin(), itr); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; static const int INF = 100000000000; int main() { int N; int64_t W; cin >> N >> W; vector<int64_t> w(N); vector<int> v(N); for (int i = 0; i < N; i++) { cin >> w.at(i); cin >> v.at(i); } vector<vector<int64_t>> dp(1 + N, vector<int64_t>(100001, 0)); for (int j = 1; j <= 100000; j++) dp[0][j] = INF; for (int i = 1; i <= N; i++) { for (int j = 1; j <= 100000; j++) { if (v[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); else dp[i][j] = min(dp[i - 1][j], w[i - 1]); } } auto itr = upper_bound(dp[N].begin(), dp[N].end(), W); int ans = distance(dp[N].begin(), itr) - 1; cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
969,965
969,964
u101018317
cpp
p03164
// #define _CRT_SECURE_NO_WARNINGS // #define _USE_MATH_DEFINES // M_PI=3.1415... #include <algorithm> #include <bitset> // bitset<8> bs1(131uL); // 10000011 bs1[0]ใฏ1 01stringใ‹ใ‚‰ใƒ“ใƒƒใƒˆ้›†ๅˆ็”Ÿๆˆๅฏ #include <cctype> #include <climits> // A/Bใ‚’่จˆ็ฎ—ใ™ใ‚‹ใจใA==LLONG_MIN && B==-1ใฎใฟ(1ull<<63)ใงไปฃ็”จ #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> // 20ๆกๅ‡บๅŠ› cout << setprecision(20) << double; #include <iostream> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; // VVL v(100,VL(100,0)); typedef pair<LL, LL> P; typedef vector<P> VP; typedef vector<VP> VVP; typedef vector<string> VS; typedef map<LL, LL> MLL; typedef pair<LL, pair<P, P>> PP; #define INF 999999999999999997 // ๅฐ‘ใ—ๅŠ ็ฎ—ใ—ใŸใ‚‰ใ‚ชใƒผใƒใƒผใƒ•ใƒญใƒผใ™ใ‚‹ #define MP make_pair #define FAST_IO \ cin.tie(0); \ ios::sync_with_stdio(false); #define FOR(i, a, b) for (LL i = (a); i < (b); i++) #define FOR_REV(i, a, b) for (int i = (a); i >= (b); i--) #define FOR_ITR(d) \ for (auto itr = d.begin(), d_end = d.end(); itr != d_end; ++itr) #define O(s) cout << s << endl; #define DUMP_VVI(b) \ if (dbgF) { \ FOR(i, 0, b.size()) { \ FOR(j, 0, b[i].size()) printf("%d ", b[i][j]); \ puts(""); \ } \ } #define D_OUT(str, value) \ if (dbgF) { \ cout << str << " : " << value << endl; \ } template <class T> T IN() { T d; cin >> d; return d; } // vector<T>ใ‚’ใ‚ฝใƒผใƒˆใ™ใ‚‹ TใฏVLใชใ‚‰LL VPใชใ‚‰P template <class T> void SORT(vector<T> &v) { sort(v.begin(), v.end()); } template <class T> void SORTGL(vector<T> &v) { sort(v.begin(), v.end(), greater<T>()); } // vectorใฎ็ทๅ’Œ ็ฌฌ3ๅผ•ๆ•ฐใ‚’LLใซใ—ใชใ„ใจๅคงใใ„ๆ•ฐใงใ‚ชใƒผใƒใƒผใƒ•ใƒญใƒผใ™ใ‚‹ LL Sum(VL v) { return accumulate(v.begin(), v.end(), 0LL); } // ๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐ๏ผˆGreatest Common Divisor๏ผ‰ LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // ๆœ€ๅฐๅ…ฌๅ€ๆ•ฐ๏ผˆLeast Common Multiple๏ผ‰ LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // ใ†ใ‚‹ใ†ๅนดๅˆคๅฎš bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // ๆ–‡ๅญ—ๅˆ—Sใ‹ใ‚‰fromใ‚’ๆคœ็ดขใ—ใฆใ™ในใฆtoใซ็ฝฎใๆ›ใˆใ‚‹ // from,toใŒcharใฎๅ ดๅˆใฏstring(1,c)ใ—ใฆใŠใใ“ใจใ€to_string()ใฏไฝฟใˆใชใ„ string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); } return S; } // ๆกๅ’Œ LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length()) a += s[i] - '0'; return a; } // ๆœซๅฐพๆ•ฐๅญ—ใงๅˆ‡ใ‚ŠไธŠใ’ LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; } // (x,y)ใŒใใ‚Œใžใ‚Œ0ไปฅไธŠใง้ซ˜ใ•h,ๅน…wใซๅŽใพใ‚‹ใ‹ x,yใฏ0-indexedใ€h,wใฏ1-indexed bool InMap(LL x, LL y, LL h, LL w) { if (x >= 0 && x < h && y >= 0 && y < w) return true; return false; } bool InMap(P p, LL h, LL w) { return InMap(p.first, p.second, h, w); } // ไบŒ้ …ไฟ‚ๆ•ฐ nCk mod pใ‚’ๆฑ‚ใ‚ใ‚‹ 1<=k<=n<=10^7, p>n const LL MAX = 510000, p = 1000000007 /*998244353*/; LL fac[MAX], finv[MAX], inv[MAX]; /* ๅ‰ๅ‡ฆ็† */ void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } } /* ไธปๅ‡ฆ็† */ LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int dxx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int dyy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; // ------------------------------------------------------------------------------- int main() { FAST_IO; bool dbgF = true; // for D_OUT(str, value) ... cout<< str <<" : "<< value <<endl; // special thanks // https://qiita.com/drken/items/dc53c683d6de8aeacf5a LL N, W; cin >> N >> W; VL w, v; FOR(i, 0, N) { LL w1, v1; cin >> w1 >> v1; w.push_back(w1); v.push_back(v1); } // dp[i][j] // ๅ“็‰ฉi(1-indexed)ใพใงใƒใ‚งใƒƒใ‚ฏใ—ใŸใจใใฎไพกๅ€คjไปฅไธŠใฎใจใใฎ็ท้‡้‡ใฎๆœ€ๅฐๅ€ค // jใฎๆœ€ๅคงใฏ10^3 * 100 = 10^5 VVL dp(N + 1, VL(100 + 1, INF)); dp[0][0] = 0; FOR(i, 0, N) { FOR(j, 0, 100 + 1) { if (j - v[i] >= 0) { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } else { dp[i + 1][j] = dp[i][j]; } } } LL ans = -1; FOR(i, 0, dp[N].size()) { if (dp[N][i] <= W) { ans = max(ans, i); } } O(ans); return 0; }
// #define _CRT_SECURE_NO_WARNINGS // #define _USE_MATH_DEFINES // M_PI=3.1415... #include <algorithm> #include <bitset> // bitset<8> bs1(131uL); // 10000011 bs1[0]ใฏ1 01stringใ‹ใ‚‰ใƒ“ใƒƒใƒˆ้›†ๅˆ็”Ÿๆˆๅฏ #include <cctype> #include <climits> // A/Bใ‚’่จˆ็ฎ—ใ™ใ‚‹ใจใA==LLONG_MIN && B==-1ใฎใฟ(1ull<<63)ใงไปฃ็”จ #include <cmath> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> // 20ๆกๅ‡บๅŠ› cout << setprecision(20) << double; #include <iostream> #include <locale> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; // VVL v(100,VL(100,0)); typedef pair<LL, LL> P; typedef vector<P> VP; typedef vector<VP> VVP; typedef vector<string> VS; typedef map<LL, LL> MLL; typedef pair<LL, pair<P, P>> PP; #define INF 999999999999999997 // ๅฐ‘ใ—ๅŠ ็ฎ—ใ—ใŸใ‚‰ใ‚ชใƒผใƒใƒผใƒ•ใƒญใƒผใ™ใ‚‹ #define MP make_pair #define FAST_IO \ cin.tie(0); \ ios::sync_with_stdio(false); #define FOR(i, a, b) for (LL i = (a); i < (b); i++) #define FOR_REV(i, a, b) for (int i = (a); i >= (b); i--) #define FOR_ITR(d) \ for (auto itr = d.begin(), d_end = d.end(); itr != d_end; ++itr) #define O(s) cout << s << endl; #define DUMP_VVI(b) \ if (dbgF) { \ FOR(i, 0, b.size()) { \ FOR(j, 0, b[i].size()) printf("%d ", b[i][j]); \ puts(""); \ } \ } #define D_OUT(str, value) \ if (dbgF) { \ cout << str << " : " << value << endl; \ } template <class T> T IN() { T d; cin >> d; return d; } // vector<T>ใ‚’ใ‚ฝใƒผใƒˆใ™ใ‚‹ TใฏVLใชใ‚‰LL VPใชใ‚‰P template <class T> void SORT(vector<T> &v) { sort(v.begin(), v.end()); } template <class T> void SORTGL(vector<T> &v) { sort(v.begin(), v.end(), greater<T>()); } // vectorใฎ็ทๅ’Œ ็ฌฌ3ๅผ•ๆ•ฐใ‚’LLใซใ—ใชใ„ใจๅคงใใ„ๆ•ฐใงใ‚ชใƒผใƒใƒผใƒ•ใƒญใƒผใ™ใ‚‹ LL Sum(VL v) { return accumulate(v.begin(), v.end(), 0LL); } // ๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐ๏ผˆGreatest Common Divisor๏ผ‰ LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // ๆœ€ๅฐๅ…ฌๅ€ๆ•ฐ๏ผˆLeast Common Multiple๏ผ‰ LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // ใ†ใ‚‹ใ†ๅนดๅˆคๅฎš bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // ๆ–‡ๅญ—ๅˆ—Sใ‹ใ‚‰fromใ‚’ๆคœ็ดขใ—ใฆใ™ในใฆtoใซ็ฝฎใๆ›ใˆใ‚‹ // from,toใŒcharใฎๅ ดๅˆใฏstring(1,c)ใ—ใฆใŠใใ“ใจใ€to_string()ใฏไฝฟใˆใชใ„ string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); } return S; } // ๆกๅ’Œ LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length()) a += s[i] - '0'; return a; } // ๆœซๅฐพๆ•ฐๅญ—ใงๅˆ‡ใ‚ŠไธŠใ’ LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; } // (x,y)ใŒใใ‚Œใžใ‚Œ0ไปฅไธŠใง้ซ˜ใ•h,ๅน…wใซๅŽใพใ‚‹ใ‹ x,yใฏ0-indexedใ€h,wใฏ1-indexed bool InMap(LL x, LL y, LL h, LL w) { if (x >= 0 && x < h && y >= 0 && y < w) return true; return false; } bool InMap(P p, LL h, LL w) { return InMap(p.first, p.second, h, w); } // ไบŒ้ …ไฟ‚ๆ•ฐ nCk mod pใ‚’ๆฑ‚ใ‚ใ‚‹ 1<=k<=n<=10^7, p>n const LL MAX = 510000, p = 1000000007 /*998244353*/; LL fac[MAX], finv[MAX], inv[MAX]; /* ๅ‰ๅ‡ฆ็† */ void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } } /* ไธปๅ‡ฆ็† */ LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int dxx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; int dyy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; // ------------------------------------------------------------------------------- int main() { FAST_IO; bool dbgF = true; // for D_OUT(str, value) ... cout<< str <<" : "<< value <<endl; // special thanks // https://qiita.com/drken/items/dc53c683d6de8aeacf5a LL N, W; cin >> N >> W; VL w, v; FOR(i, 0, N) { LL w1, v1; cin >> w1 >> v1; w.push_back(w1); v.push_back(v1); } // dp[i][j] // ๅ“็‰ฉi(1-indexed)ใพใงใƒใ‚งใƒƒใ‚ฏใ—ใŸใจใใฎไพกๅ€คjไปฅไธŠใฎใจใใฎ็ท้‡้‡ใฎๆœ€ๅฐๅ€ค // jใฎๆœ€ๅคงใฏ10^3 * 100 = 10^5 VVL dp(N + 1, VL(100000 + 1, INF)); dp[0][0] = 0; FOR(i, 0, N) { FOR(j, 0, 100000 + 1) { if (j - v[i] >= 0) { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } else { dp[i + 1][j] = dp[i][j]; } } } LL ans = 0; FOR(i, 0, dp[N].size()) { if (dp[N][i] <= W) { ans = max(ans, i); } } O(ans); return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change", "variable_declaration.value.change" ]
969,973
969,974
u211964883
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { int n, W; cin >> n >> W; vector<int> w(n), v(n); int value = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; value += v[i]; } vector<long long int> dp(value + 1, (LONG_MAX)); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = value; j >= 0; j--) { if (j >= v[i]) dp[j] = min(dp[j], w[i] + dp[j - v[i]]); } } int ans = 0; for (int i = 0; i <= value; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, W; cin >> n >> W; vector<int> w(n), v(n); int value = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; value += v[i]; } vector<long long int> dp(value + 1, (1e18L + 5)); dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = value; j >= 0; j--) { if (j >= v[i]) dp[j] = min(dp[j], w[i] + dp[j - v[i]]); } } int ans = 0; for (int i = 0; i <= value; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change" ]
969,983
969,984
u310097508
cpp
p03164
#include <iomanip> #include <iostream> #include <limits> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { int n, W; cin >> n >> W; const int maxV = 100; vector<vector<int>> dp(n + 1, vector<int>(maxV + 1, int(1e9 + 10))); dp[0][0] = 0; for (int i = 0; i < n; i++) { int w, v; cin >> w >> v; for (int j = 0; j <= maxV; j++) { if (j < v) { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = min(dp[i][j - v] + w, dp[i][j]); } } } int ans = 0; for (int i = 0; i <= maxV; i++) { if (dp[n][i] <= W) { ans = i; } } cout << ans << endl; return 0; }
#include <iomanip> #include <iostream> #include <limits> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { int n, W; cin >> n >> W; const int maxV = 100001; vector<vector<int>> dp(n + 1, vector<int>(maxV + 1, int(1e9 + 10))); dp[0][0] = 0; for (int i = 0; i < n; i++) { int w, v; cin >> w >> v; for (int j = 0; j <= maxV; j++) { if (j < v) { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = min(dp[i][j - v] + w, dp[i][j]); } } } int ans = 0; for (int i = 0; i <= maxV; i++) { if (dp[n][i] <= W) { ans = i; } } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
969,989
969,990
u530350853
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define SUM_MAX 100000 #define N_MAX 100 #define W_MAX 1000000000 int dp[SUM_MAX + 1][N_MAX]; bool v[SUM_MAX + 1][N_MAX]; int solveDp(int r, int i, int *w, int *val, int n) { if (r <= 0) return 0; if (i == n) return W_MAX; if (v[r][i]) return dp[r][i]; v[r][i] = 1; dp[r][i] = min(solveDp(r, i + 1, w, val, n), w[i] + solveDp(r - val[i], i + 1, w, val, n)); return dp[r][i]; } int maxW(int *w, int *val, int n, int c) { for (int i = SUM_MAX; i >= 0; i--) { if (solveDp(i, 0, w, val, n) <= c) { return i; } } return 0; } int main() { int w[N_MAX], val[N_MAX]; int n, C; cin >> n >> C; for (int i = 0; i < n; i++) cin >> w[i] >> val[i]; cout << maxW(w, val, n, C); return 0; }
#include <bits/stdc++.h> using namespace std; #define SUM_MAX 100000 #define N_MAX 105 #define W_MAX 1000000005 int dp[SUM_MAX + 1][N_MAX]; bool v[SUM_MAX + 1][N_MAX]; int solveDp(int r, int i, int *w, int *val, int n) { if (r <= 0) return 0; if (i == n) return W_MAX; if (v[r][i]) return dp[r][i]; v[r][i] = 1; dp[r][i] = min(solveDp(r, i + 1, w, val, n), w[i] + solveDp(r - val[i], i + 1, w, val, n)); return dp[r][i]; } int maxW(int *w, int *val, int n, int c) { for (int i = SUM_MAX; i >= 0; i--) { if (solveDp(i, 0, w, val, n) <= c) { return i; } } return 0; } int main() { int w[N_MAX], val[N_MAX]; int n, C; cin >> n >> C; for (int i = 0; i < n; i++) cin >> w[i] >> val[i]; cout << maxW(w, val, n, C); return 0; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
969,993
969,994
u977832306
cpp
p03164
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; #define int long long int #define MOD 1000000007 #define pb push_back #define mp make_pair #define vi vector<int> #define mi map<int, int> #define umi unordered_map<int, int> #define pii pair<int, int> #define ff first #define ss second #define inf 1e12 #define case \ int t; \ cin >> t; \ while (t--) // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pbds; void pre() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int dp[104][100010]; int32_t main() { pre(); // case { int n, W; cin >> n >> W; int v[n], wt[n], s = 0; for (int i = 0; i < n; i++) { cin >> wt[i] >> v[i]; s += v[i]; } for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= 100001; j++) dp[i][j] = inf; for (int i = 0; i <= n + 1; i++) dp[i][0] = 0; int as = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= s + 1; j++) { if (v[i - 1] <= j) dp[i][j] = min(dp[i - 1][j - v[i - 1]] + wt[i - 1], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; // cout << dp[i][j] << " "; } // cout << endl; } // cout << s << endl; for (int i = 0; i <= s; i++) if (dp[n][i] <= W) as = i; cout << as << endl; } return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; #define int long long int #define MOD 1000000007 #define pb push_back #define mp make_pair #define vi vector<int> #define mi map<int, int> #define umi unordered_map<int, int> #define pii pair<int, int> #define ff first #define ss second #define inf 1e12 #define case \ int t; \ cin >> t; \ while (t--) // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pbds; void pre() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int dp[104][100010]; int32_t main() { // pre(); // case { int n, W; cin >> n >> W; int v[n], wt[n], s = 0; for (int i = 0; i < n; i++) { cin >> wt[i] >> v[i]; s += v[i]; } for (int i = 0; i <= n + 1; i++) for (int j = 0; j <= 100001; j++) dp[i][j] = inf; for (int i = 0; i <= n + 1; i++) dp[i][0] = 0; int as = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= s; j++) { if (v[i - 1] <= j) dp[i][j] = min(dp[i - 1][j - v[i - 1]] + wt[i - 1], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; // cout << dp[i][j] << " "; } // cout << endl; } for (int i = 0; i <= s; i++) if (dp[n][i] <= W) as = i; cout << as << endl; } return 0; }
[ "call.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
969,995
969,996
u959464076
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll dp[110][100100]; int main() { ll n, w; cin >> n >> w; vector<ll> weight(n), value(n); for (ll i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (ll i = 0; i < n; i++) { for (ll j = 0; j < 100100; j++) { dp[i][j] = 1LL << 60; } } dp[0][0] = 0; for (ll i = 0; i < n; i++) { for (ll j = 0; j < 100100; j++) { if (j - value[i] >= 0) chmin(dp[i + 1][j], dp[i][j - value[i]] + weight[i]); chmin(dp[i + 1][j], dp[i][j]); } } ll res = 0; for (ll j = 0; j < 100100; j++) { if (dp[n][j] <= w) res = j; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } ll dp[110][100100]; int main() { ll n, w; cin >> n >> w; vector<ll> weight(n), value(n); for (ll i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (ll i = 0; i < 110; i++) { for (ll j = 0; j < 100100; j++) { dp[i][j] = 1LL << 60; } } dp[0][0] = 0; for (ll i = 0; i < n; i++) { for (ll j = 0; j < 100100; j++) { if (j - value[i] >= 0) chmin(dp[i + 1][j], dp[i][j - value[i]] + weight[i]); chmin(dp[i + 1][j], dp[i][j]); } } ll res = 0; for (ll j = 0; j < 100100; j++) { if (dp[n][j] <= w) res = j; } cout << res << endl; }
[ "identifier.replace.remove", "literal.replace.add", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
970,011
970,012
u962609087
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define int long long #define change(a, b) \ if (a < b) \ a = b int dp[110][100100]; int weight[110], value[110]; signed main() { int n, w; cin >> n >> w; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (int i = 0; i < 110; i++) { for (int j = 0; j < 100100; j++) { dp[i][j] = 1ll << 60; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int sumv = 0; sumv < 100100; sumv++) { if (sumv - value[i] >= 0) { change(dp[i + 1][sumv], dp[i][sumv - value[i]] + weight[i]); } change(dp[i + 1][sumv], dp[i][sumv]); } } int res = 0; for (int sumv = 0; sumv < 100100; sumv++) { if (dp[n][sumv] <= w) res = sumv; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define change(a, b) \ if (a > b) \ a = b int dp[110][100100]; int weight[110], value[110]; signed main() { int n, w; cin >> n >> w; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (int i = 0; i < 110; i++) { for (int j = 0; j < 100100; j++) { dp[i][j] = 1ll << 60; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int sumv = 0; sumv < 100100; sumv++) { if (sumv - value[i] >= 0) { change(dp[i + 1][sumv], dp[i][sumv - value[i]] + weight[i]); } change(dp[i + 1][sumv], dp[i][sumv]); } } int res = 0; for (int sumv = 0; sumv < 100100; sumv++) { if (dp[n][sumv] <= w) res = sumv; } cout << res << endl; }
[ "misc.opposites", "expression.operator.compare.change", "preprocessor.define.value.change" ]
970,013
970,014
u962609087
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define int long long #define change(a, b) \ if (a < b) \ a = b int dp[110][100100]; int weight[110], value[110]; signed main() { int n, w; cin >> n >> w; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (int i = 0; i < 110; i++) { for (int j = 0; j < 100100; j++) { dp[i][j] = 1ll << 60; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int sumv = 0; sumv <= 100100; sumv++) { if (sumv - value[i] >= 0) { change(dp[i + 1][sumv], dp[i][sumv - value[i]] + weight[i]); } change(dp[i + 1][sumv], dp[i][sumv]); } } int res = 0; for (int sumv = 0; sumv < 100100; sumv++) { if (dp[n][sumv] <= w) res = sumv; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define change(a, b) \ if (a > b) \ a = b int dp[110][100100]; int weight[110], value[110]; signed main() { int n, w; cin >> n >> w; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (int i = 0; i < 110; i++) { for (int j = 0; j < 100100; j++) { dp[i][j] = 1ll << 60; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int sumv = 0; sumv < 100100; sumv++) { if (sumv - value[i] >= 0) { change(dp[i + 1][sumv], dp[i][sumv - value[i]] + weight[i]); } change(dp[i + 1][sumv], dp[i][sumv]); } } int res = 0; for (int sumv = 0; sumv < 100100; sumv++) { if (dp[n][sumv] <= w) res = sumv; } cout << res << endl; }
[ "misc.opposites", "expression.operator.compare.change", "preprocessor.define.value.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
970,015
970,014
u962609087
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(NULL); if (fopen("input.in", "r")) { freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); } ll N, W; cin >> N >> W; vector<ll> w(N + 1), v(N + 1); for (ll i = 1; i <= N; i++) { cin >> w[i] >> v[i]; } // dp[i] = min weight for subjset of sum of value exactly i vector<ll> dp(1e5 + 1, 1e9); dp[0] = 0; for (int k = 1; k <= N; k++) { for (int i = 1e5; i >= v[k]; i--) { dp[i] = min(dp[i - v[k]] + w[k], dp[i]); } } for (int i = 1e5 + 1; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(NULL); if (fopen("input.in", "r")) { freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); } ll N, W; cin >> N >> W; vector<ll> w(N + 1), v(N + 1); for (ll i = 1; i <= N; i++) { cin >> w[i] >> v[i]; } // dp[i] = min weight for subjset of sum of value exactly i vector<ll> dp(1e5 + 1, 1e10); dp[0] = 0; for (int k = 1; k <= N; k++) { for (int i = 1e5; i >= v[k]; i--) { dp[i] = min(dp[i - v[k]] + w[k], dp[i]); } } for (int i = 1e5; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; break; } } return 0; }
[ "literal.number.change", "call.arguments.change", "control_flow.loop.for.initializer.change", "expression.operation.binary.remove" ]
970,029
970,030
u142188850
cpp
p03164
#include <bits/stdc++.h> #define int long long #define MAX 10 using namespace std; // KnapSack int max_value(int N, int W, int *w, int *v) { int dp[N + 1][MAX]; for (int i = 0; i <= N; ++i) { for (int j = 0; j < MAX; ++j) { if (j == 0) { dp[i][j] = 0; continue; } if (i == 0) { dp[i][j] = INT_MAX; continue; } dp[i][j] = dp[i - 1][j]; if (j >= v[i - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); } } for (int j = MAX - 1; j >= 0; --j) { if (dp[N][j] <= W) return j; } } int32_t main() { int N, W; cin >> N >> W; int w[N], v[N]; for (int i = 0; i < N; ++i) cin >> w[i] >> v[i]; cout << max_value(N, W, w, v) << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define MAX 100001 using namespace std; // KnapSack int max_value(int N, int W, int *w, int *v) { int dp[N + 1][MAX]; for (int i = 0; i <= N; ++i) { for (int j = 0; j < MAX; ++j) { if (j == 0) { dp[i][j] = 0; continue; } if (i == 0) { dp[i][j] = INT_MAX; continue; } dp[i][j] = dp[i - 1][j]; if (j >= v[i - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); } } for (int j = MAX - 1; j >= 0; --j) { if (dp[N][j] <= W) return j; } } int32_t main() { int N, W; cin >> N >> W; int w[N], v[N]; for (int i = 0; i < N; ++i) cin >> w[i] >> v[i]; cout << max_value(N, W, w, v) << endl; return 0; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
970,039
970,040
u628489313
cpp
p03164
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (int i = 1; i < maxv; i++) { if (i == val[0]) knap[0][i] = wt[0]; } for (ll i = 1; i < n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i - 1]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i - 1]] + wt[i - 1], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n - 1][i] <= W) { cout << i; // max value break; } } }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (int i = 1; i < maxv; i++) { if (i == val[0]) knap[0][i] = wt[0]; } for (ll i = 1; i < n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i]] + wt[i], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n - 1][i] <= W) { cout << i; // max value break; } } }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
970,046
970,047
u910199116
cpp
p03164
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (ll i = 1; i < n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i - 1]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i - 1]] + wt[i - 1], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n - 1][i] <= W) { cout << i; // max value break; } } }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i - 1]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i - 1]] + wt[i - 1], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n][i] <= W) { cout << i; // max value break; } } }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "expression.operation.binary.remove" ]
970,048
970,049
u910199116
cpp
p03164
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (ll i = 1; i < n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i - 1]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i]] + wt[i - 1], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n - 1][i] <= W) { cout << i; // max value break; } } }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i - 1]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i - 1]] + wt[i - 1], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n][i] <= W) { cout << i; // max value break; } } }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "expression.operation.binary.remove" ]
970,050
970,049
u910199116
cpp
p03164
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i - 1]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i]] + wt[i - 1], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n - 1][i] <= W) { cout << i; // max value break; } } }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; knap[0][0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j < maxv; j++) { if (j < val[i - 1]) knap[i][j] = knap[i - 1][j]; else knap[i][j] = min(knap[i - 1][j - val[i - 1]] + wt[i - 1], knap[i - 1][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n][i] <= W) { cout << i; // max value break; } } }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
970,051
970,049
u910199116
cpp
p03164
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < maxv; j++) { if (i == 0 && j == 0) knap[i][j] = 0; else if (j < val[i]) knap[i + 1][j] = knap[i][j]; else knap[i + 1][j] = min(knap[i][j - val[i]] + wt[i], knap[i][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n][i] <= W) { cout << i; // max value break; } } }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define maxv 1e5 + 1 #define inf 4e18 using namespace std; int main() { ll n, W; cin >> n >> W; ll val[n + 1], wt[n + 1]; vector<vector<ll>> knap( n + 1, vector<ll>(maxv, inf)); // 2d vector with n+1 r and maxv col with value =inf // here the answer i.e maxvalue cant be >10^5 for (ll i = 0; i < n; i++) cin >> wt[i] >> val[i]; for (ll i = 0; i < n; i++) { for (ll j = 0; j < maxv; j++) { if (i == 0 && j == 0) knap[i][j] = 0; if (j < val[i]) knap[i + 1][j] = knap[i][j]; else knap[i + 1][j] = min(knap[i][j - val[i]] + wt[i], knap[i][j]); } } for (ll i = maxv - 1; i >= 0; i--) // max value cant be greater than maxv coz vi<=10^3 and n<=100 { if (knap[n][i] <= W) { cout << i; // max value break; } } }
[ "control_flow.branch.if.replace.add", "control_flow.branch.else_if.replace.remove" ]
970,052
970,053
u910199116
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using vl = vector<ll>; /* short */ #define pb push_back #define mp make_pair #define Fi first #define Se second #define ALL(v) begin(v), end(v) #define RALL(v) rbegin(v), rend(v) /* REPmacro */ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORR(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define FOREACH(x, a) for (auto x : a) /* exchange */ #define CHMIN(a, b) (a) = min((ll)(a), (ll)(b)) #define CHMAX(a, b) (a) = max((ll)(a), (ll)(b)) /* function */ #define IN(x) cin >> x #define DEBUG(x) cerr << (x) << " " #define LN() cerr << "\n" #define PRINT(x) cout << (x) << endl #define BR cout << endl /* const */ const int ARRAY = 100005; const int INF = 1001001001; // 10^9 const ll LINF = 1001001001001001001; // 10^18 const int MOD = 1e9 + 7; ll ret = 0; string s; ll w[101]; ll v[101]; ll dp[101][ARRAY]; ll knapsack(ll i, ll j) { if (i < 0 && j <= 0) return 0; if (i < 0 && j > 0) return INF; if (dp[i][j] != -1) return dp[i][j]; ll ans = min(knapsack(i - 1, j), w[i] + knapsack(i - 1, j - v[i])); dp[i][j] = ans; return ans; } int main(void) { ll N, W; IN(N); IN(W); REP(i, N) { IN(w[i]); IN(v[i]); } REP(i, 101) { REP(j, ARRAY) { dp[i][j] = -1; } } REP(i, ARRAY) { ll weight = knapsack(N - 1, i); // DEBUG(N-1); // DEBUG(i); // DEBUG("=>"); // DEBUG(weight); // LN(); if (weight > W) { ret = i - 1; break; } } PRINT(ret); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; using vl = vector<ll>; /* short */ #define pb push_back #define mp make_pair #define Fi first #define Se second #define ALL(v) begin(v), end(v) #define RALL(v) rbegin(v), rend(v) /* REPmacro */ #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORR(i, a, b) for (int i = (a); i >= (b); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define FOREACH(x, a) for (auto x : a) /* exchange */ #define CHMIN(a, b) (a) = min((ll)(a), (ll)(b)) #define CHMAX(a, b) (a) = max((ll)(a), (ll)(b)) /* function */ #define IN(x) cin >> x #define DEBUG(x) cerr << (x) << " " #define LN() cerr << "\n" #define PRINT(x) cout << (x) << endl #define BR cout << endl /* const */ const int ARRAY = 100005; const int INF = 1001001001; // 10^9 const ll LINF = 1001001001001001001; // 10^18 const int MOD = 1e9 + 7; ll ret = 0; string s; ll w[101]; ll v[101]; ll dp[101][ARRAY]; ll knapsack(ll i, ll j) { if (j <= 0) return 0; if (i < 0 && j > 0) return INF; if (dp[i][j] != -1) return dp[i][j]; ll ans = min(knapsack(i - 1, j), w[i] + knapsack(i - 1, j - v[i])); dp[i][j] = ans; return ans; } int main(void) { ll N, W; IN(N); IN(W); REP(i, N) { IN(w[i]); IN(v[i]); } REP(i, 101) { REP(j, ARRAY) { dp[i][j] = -1; } } REP(i, ARRAY) { ll weight = knapsack(N - 1, i); // DEBUG(N-1); // DEBUG(i); // DEBUG("=>"); // DEBUG(weight); // LN(); if (weight > W) { ret = i - 1; break; } } PRINT(ret); }
[ "expression.operation.binary.remove" ]
970,054
970,055
u790171360
cpp
p03164
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; constexpr long long INF = 1000000000LL; #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) 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; } const int MAX_N = 110; const int MAX_V = 100100; int N; long long W, weight[MAX_N], value[MAX_N]; // ๅ“็‰ฉใฎๅ€‹ๆ•ฐใฏ 100 ๅ€‹ใชใฎใงๅฐ‘ใ—ไฝ™่ฃ•ๆŒใŸใ›ใฆใ‚ตใ‚คใ‚บ 110 ใซ // DPใƒ†ใƒผใƒ–ใƒซ long long dp[MAX_N][MAX_V]; int main() { cin >> N >> W; rep(i, N) cin >> weight[i] >> value[i]; rep(i, MAX_N) rep(j, MAX_V) dp[i][j] = INF; dp[0][0] = 0; // DPใƒซใƒผใƒ— rep(i, N) { rep(sum_v, MAX_V) { // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใถๅ ดๅˆ chmin(dp[i + 1][sum_v + value[i]], dp[i][sum_v] + weight[i]); // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใฐใชใ„ๅ ดๅˆ chmin(dp[i + 1][sum_v], dp[i][sum_v]); } } // ๆœ€้ฉๅ€คใฎๅ‡บๅŠ› long long res = 0; for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007LL; constexpr long long INF = 1000000009LL; #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) 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; } const int MAX_N = 110; const int MAX_V = 100100; int N; long long W, weight[MAX_N], value[MAX_N]; // ๅ“็‰ฉใฎๅ€‹ๆ•ฐใฏ 100 ๅ€‹ใชใฎใงๅฐ‘ใ—ไฝ™่ฃ•ๆŒใŸใ›ใฆใ‚ตใ‚คใ‚บ 110 ใซ // DPใƒ†ใƒผใƒ–ใƒซ long long dp[MAX_N][MAX_V]; int main() { cin >> N >> W; rep(i, N) cin >> weight[i] >> value[i]; rep(i, MAX_N) rep(j, MAX_V) dp[i][j] = INF; dp[0][0] = 0; // DPใƒซใƒผใƒ— rep(i, N) { rep(sum_v, MAX_V) { // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใถๅ ดๅˆ chmin(dp[i + 1][sum_v + value[i]], dp[i][sum_v] + weight[i]); // i ็•ช็›ฎใฎๅ“็‰ฉใ‚’้ธใฐใชใ„ๅ ดๅˆ chmin(dp[i + 1][sum_v], dp[i][sum_v]); } } // ๆœ€้ฉๅ€คใฎๅ‡บๅŠ› long long res = 0; for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
[ "literal.number.change", "variable_declaration.value.change" ]
970,056
970,057
u062736195
cpp
p03164
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i <= (n); i++) using namespace std; const long long INF = 1LL << 60; const int MAX_N = 110; const int MAX_V = 100100; int N; long long W, w[MAX_N], v[MAX_N]; long long dp[MAX_N][MAX_V]; signed main(void) { cin >> N >> W; rep(i, N) cin >> w[i] >> v[i]; for (int i = 0; i < MAX_N; i++) for (int j = 0; j < MAX_V; j++) dp[i][j] = INF; dp[0][0] = 0; rep(i, N) { for (int j = 0; j < MAX_V; j++) { if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } int ans = 0; for (int j = 0; j < 150; j++) { if (W >= dp[N][j]) { ans = j; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i <= (n); i++) using namespace std; const long long INF = 1LL << 60; const int MAX_N = 110; const int MAX_V = 100100; int N; long long W, w[MAX_N], v[MAX_N]; long long dp[MAX_N][MAX_V]; signed main(void) { cin >> N >> W; rep(i, N) cin >> w[i] >> v[i]; for (int i = 0; i < MAX_N; i++) for (int j = 0; j < MAX_V; j++) dp[i][j] = INF; dp[0][0] = 0; rep(i, N) { for (int j = 0; j < MAX_V; j++) { if (j - v[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } int ans = 0; for (int j = 0; j < MAX_V; j++) { if (W >= dp[N][j]) { ans = j; } } cout << ans << endl; return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
970,058
970,059
u890331732
cpp
p03164
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; int main() { #define ll long long ll n, w; cin >> n >> w; vector<pair<ll, ll>> v(n); for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second; vector<ll> dp(100100, 1e18); // dp[i]=min weigth for value i dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = 100010; j >= 0; j--) { if (j + v[i].first < 100010) dp[j + v[i].first] = min(dp[j + v[i].first], dp[j] + v[i].second); } } int ans = 0; for (int i = 0; i < 100100; i++) if (dp[i] <= w) ans = i; cout << ans; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; int main() { #define ll long long ll n, w; cin >> n >> w; vector<pair<ll, ll>> v(n); for (int i = 0; i < n; i++) cin >> v[i].first >> v[i].second; vector<ll> dp(100100, 1e18); // dp[i]=min weigth for value i dp[0] = 0; for (int i = 0; i < n; i++) { for (int j = 100010; j >= 0; j--) { if (j + v[i].second < 100010) dp[j + v[i].second] = min(dp[j + v[i].second], dp[j] + v[i].first); } } int ans = 0; for (int i = 0; i < 100100; i++) if (dp[i] <= w) ans = i; cout << ans; }
[ "control_flow.branch.if.condition.change", "assignment.variable.change", "variable_access.subscript.index.change", "expression.operation.binary.change", "assignment.value.change", "call.arguments.change" ]
970,070
970,071
u454826990
cpp
p03164
#include <bits/stdc++.h> #define ll unsigned long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long n, c, t; cin >> n >> c; vector<long> w; vector<long> v; long total_value = 0; for (int i = 0; i < n; i++) { cin >> t; w.push_back(t); cin >> t; v.push_back(t); total_value += t; } vector<vector<long>> dp(n + 1, vector<long>(total_value + 1, c + 1)); for (int i = 0; i < n + 1; i++) { dp[i][0] = 0; } long ans = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < total_value + 1; j++) { dp[i][j] = dp[i - 1][j]; if (j >= v[i]) dp[i][j] = min(dp[i][j], w[i] + dp[i - 1][j - v[i]]); } } for (int j(0); j < total_value + 1; j++) if (dp[n][j] <= c) { ans = (long)j; } cout << ans << endl; }
#include <bits/stdc++.h> #define ll unsigned long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long n, c, t; cin >> n >> c; vector<long> w; vector<long> v; long total_value = 0; for (int i = 0; i < n; i++) { cin >> t; w.push_back(t); cin >> t; v.push_back(t); total_value += t; } vector<vector<long>> dp(n + 1, vector<long>(total_value + 1, c + 1)); for (int i = 0; i < n + 1; i++) { dp[i][0] = 0; } long ans = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < total_value + 1; j++) { dp[i][j] = dp[i - 1][j]; if (j >= v[i - 1]) dp[i][j] = min(dp[i][j], w[i - 1] + dp[i - 1][j - v[i - 1]]); } } for (int j(0); j < total_value + 1; j++) if (dp[n][j] <= c) { ans = (long)j; } cout << ans << endl; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one", "assignment.change" ]
970,072
970,073
u320023439
cpp
p03164
/* Just Constraints are different than the other version rest logic is similar Constraints: 1<=n<=100 1<=wt<=10^9 1<=w[i]<=wt 1<=v[i]<=10^3 */ #include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, w; cin >> n >> w; ll wei[n], val[n]; for (int i = 0; i < n; ++i) { cin >> wei[i] >> val[i]; } long long dp[n + 1][100005]; // n+1 weight and 1001 value for (int i = 0; i <= n; ++i) { for (int j = 0; j <= 100005; ++j) { if (j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = INT_MAX; else if (val[i - 1] > j) dp[i][j] = dp[i - 1][j]; else // note the difference of using min here and max in other version dp[i][j] = min(dp[i - 1][j], wei[i - 1] + dp[i - 1][j - val[i - 1]]); } } ll ans = 0; for (int i = 0; i <= 100005; ++i) { if (dp[n][i] <= w && dp[n][i] != INT_MAX) ans = i; } cout << ans << endl; }
/* Just Constraints are different than the other version rest logic is similar Constraints: 1<=n<=100 1<=wt<=10^9 1<=w[i]<=wt 1<=v[i]<=10^3 */ #include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, w; cin >> n >> w; ll wei[n], val[n]; for (int i = 0; i < n; ++i) { cin >> wei[i] >> val[i]; } long long dp[n + 1][100005]; // n+1 weight and 1001 value for (int i = 0; i <= n; ++i) { for (int j = 0; j <= 100004; ++j) { if (j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = INT_MAX; else if (val[i - 1] > j) dp[i][j] = dp[i - 1][j]; else // note the difference of using min here and max in other version dp[i][j] = min(dp[i - 1][j], wei[i - 1] + dp[i - 1][j - val[i - 1]]); } } ll ans = 0; for (int i = 0; i <= 100004; ++i) { if (dp[n][i] <= w && dp[n][i] != INT_MAX) ans = i; } cout << ans << endl; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
970,093
970,094
u822133553
cpp
p03164
/* Just Constraints are different than the other version rest logic is similar Constraints: 1<=n<=100 1<=wt<=10^9 1<=w[i]<=wt 1<=v[i]<=10^3 */ #include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, w; cin >> n >> w; ll wei[n], val[n]; for (int i = 0; i < n; ++i) { cin >> wei[i] >> val[i]; } long long dp[n + 1][100005]; // n+1 weight and 1001 value for (int i = 0; i <= n; ++i) { for (int j = 0; j <= 100005; ++j) { if (j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = INT_MAX; else if (val[i - 1] > j) dp[i][j] = dp[i - 1][j]; else // note the difference of using min here and max in other version dp[i][j] = min(dp[i - 1][j], wei[i - 1] + dp[i - 1][j - val[i - 1]]); } } ll ans = 0; for (int i = 0; i <= 100005; ++i) { if (dp[n][i] <= w && dp[n][i] != INT_MAX) ans = i; } cout << ans << endl; }
/* Just Constraints are different than the other version rest logic is similar Constraints: 1<=n<=100 1<=wt<=10^9 1<=w[i]<=wt 1<=v[i]<=10^3 */ #include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll n, w; cin >> n >> w; ll wei[n], val[n]; for (int i = 0; i < n; ++i) { cin >> wei[i] >> val[i]; } long long dp[n + 1][100005]; // n+1 weight and 1001 value for (int i = 0; i <= n; ++i) { for (int j = 0; j <= 100000; ++j) { if (j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = INT_MAX; else if (val[i - 1] > j) dp[i][j] = dp[i - 1][j]; else // note the difference of using min here and max in other version dp[i][j] = min(dp[i - 1][j], wei[i - 1] + dp[i - 1][j - val[i - 1]]); } } ll ans = 0; for (int i = 0; i <= 100000; ++i) { if (dp[n][i] <= w && dp[n][i] != INT_MAX) ans = i; } cout << ans << endl; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
970,093
970,098
u822133553
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) // cout<<fixed<<setprecision(10); 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; const int vm = 100100; const int NM = 110; ll dp[NM][vm]; // ไพกๅ€คใŒVใจใชใ‚‹ใ‚ˆใ†ใซ้ธใ‚“ใ ใจใใฎ้‡ใ•ใฎๆœ€ๅฐๅ€ค ll w[NM], v[NM]; int main() { int nn, ww; cin >> nn >> ww; rep(i, nn) { cin >> w[i] >> v[i]; } rep(i, NM) { rep(j, vm) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < nn; i++) { for (int value = 0; value < vm; value++) { // i็•ช็›ฎใ‚’ๅ–ๅพ—ใ™ใ‚‹ๆ™‚ if (value - v[i] > 0) { chmin(dp[i + 1][value], dp[i][value - v[i]] + w[i]); } chmin(dp[i + 1][value], dp[i][value]); } } ll ans = 0; for (int value = 0; value < vm; value++) { if (dp[nn][value] <= ww) { ans = value; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) // cout<<fixed<<setprecision(10); 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; const int vm = 100100; const int NM = 110; ll dp[NM][vm]; // ไพกๅ€คใŒVใจใชใ‚‹ใ‚ˆใ†ใซ้ธใ‚“ใ ใจใใฎ้‡ใ•ใฎๆœ€ๅฐๅ€ค ll w[NM], v[NM]; int main() { ll nn, ww; cin >> nn >> ww; rep(i, nn) { cin >> w[i] >> v[i]; } rep(i, NM) { rep(j, vm) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < nn; i++) { for (int value = 0; value < vm; value++) { // i็•ช็›ฎใ‚’ๅ–ๅพ—ใ™ใ‚‹ๆ™‚ if (value - v[i] >= 0) { chmin(dp[i + 1][value], dp[i][value - v[i]] + w[i]); } chmin(dp[i + 1][value], dp[i][value]); } } ll ans = 0; for (int value = 0; value < vm; value++) { if (dp[nn][value] <= ww) { ans = value; } } cout << ans << endl; }
[ "variable_declaration.type.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
970,112
970,113
u989306199
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define mod 1000000007 #define pi 3.141592653589793 typedef vector<ll> vcl; ll gcd(ll a, ll b) { if (b > a) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } ll rep_jijo(ll n, ll x) { if (x == 0) return 1; if (x % 2 == 0) { ll t = rep_jijo(n, x / 2); return t * t % mod; } return n * rep_jijo(n, x - 1) % mod; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; int main() { ll N, W; cin >> N >> W; ll w[N + 1]; ll v[N + 1]; ll sv = 0; for (ll i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (ll i = 1; i <= N; i++) sv += v[i]; ll dp[N + 1][sv + 1]; rep(i, N + 1) rep(j, sv + 1) dp[i][j] = INF; dp[0][0] = 0; for (ll i = 1; i <= N; i++) { for (ll j = 1; j <= sv; j++) { if (j >= v[i]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; rep(j, sv) if (dp[N][j] <= W) ans = j; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define mod 1000000007 #define pi 3.141592653589793 typedef vector<ll> vcl; ll gcd(ll a, ll b) { if (b > a) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } ll rep_jijo(ll n, ll x) { if (x == 0) return 1; if (x % 2 == 0) { ll t = rep_jijo(n, x / 2); return t * t % mod; } return n * rep_jijo(n, x - 1) % mod; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } const long long INF = 1LL << 60; int main() { ll N, W; cin >> N >> W; ll w[N + 1]; ll v[N + 1]; ll sv = 0; for (ll i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (ll i = 1; i <= N; i++) sv += v[i]; ll dp[N + 1][sv + 1]; rep(i, N + 1) rep(j, sv + 1) dp[i][j] = INF; dp[0][0] = 0; for (ll i = 1; i <= N; i++) { for (ll j = 0; j <= sv; j++) { if (j >= v[i]) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; rep(j, sv + 1) if (dp[N][j] <= W) ans = j; cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
970,117
970,118
u613945234
cpp
p03164
#include <bits/stdc++.h> using namespace std; // Type alias using ll = long long; using ld = double; using pi = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; using ti3 = tuple<int, int, int>; using vi = vector<int>; using vll = vector<ll>; using vld = vector<ld>; using vpi = vector<pi>; using vpll = vector<ll>; using vpld = vector<ld>; using vti3 = vector<ti3>; // Constants const double EPS = 1e-9; const int inf = numeric_limits<int>::max() / 2; const ll llinf = numeric_limits<ll>::max() / 2; const ll mod = 1e9 + 7; // Macro #define rep(i, n) for (int i = 0; i < int(n); ++i) #define rrep(i, n) for (int i = int(n - 1); i >= 0; --i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define RREP(i, a, b) for (int i = int(b - 1); i >= int(a); --i) #define SHOW(a) cout << #a << " = " << a << endl #define ARR(a, n) \ for (int i = 0; i < int(n); ++i) \ cout << #a << "[" << i << "]" \ << " = " << a[i] << endl #define ALL(a) a.begin(), a.end() // Funtcions ll pow(ll base, ll i, ll mod) { ll a = 1; while (i) { if (i & 1) { a *= base; a %= mod; } base *= base; base %= mod; i >>= 1; } return a; } ll gcd(ll a, ll b) { while (b) { ll c = a % b; a = b; b = c; } return a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) return a = b, true; else return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) return a = b, true; else return false; } ll dp[105][1005]; void solve() { ll N, W; cin >> N >> W; ll w[105], v[105]; rep(i, N) cin >> w[i] >> v[i]; dp[0][0] = 0; REP(j, 1, 100000 + 1) dp[0][j] = llinf; rep(i, N) { rep(j, 100000 + 1) { if (j - v[i] >= 0) { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } else { dp[i + 1][j] = dp[i][j]; } } } rrep(i, 100000 + 1) { if (dp[N][i] <= W) { cout << i << endl; break; } } } int main() { // FastIO // ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; // Type alias using ll = long long; using ld = double; using pi = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; using ti3 = tuple<int, int, int>; using vi = vector<int>; using vll = vector<ll>; using vld = vector<ld>; using vpi = vector<pi>; using vpll = vector<ll>; using vpld = vector<ld>; using vti3 = vector<ti3>; // Constants const double EPS = 1e-9; const int inf = numeric_limits<int>::max() / 2; const ll llinf = numeric_limits<ll>::max() / 2; const ll mod = 1e9 + 7; // Macro #define rep(i, n) for (int i = 0; i < int(n); ++i) #define rrep(i, n) for (int i = int(n - 1); i >= 0; --i) #define REP(i, a, b) for (int i = int(a); i < int(b); ++i) #define RREP(i, a, b) for (int i = int(b - 1); i >= int(a); --i) #define SHOW(a) cout << #a << " = " << a << endl #define ARR(a, n) \ for (int i = 0; i < int(n); ++i) \ cout << #a << "[" << i << "]" \ << " = " << a[i] << endl #define ALL(a) a.begin(), a.end() // Funtcions ll pow(ll base, ll i, ll mod) { ll a = 1; while (i) { if (i & 1) { a *= base; a %= mod; } base *= base; base %= mod; i >>= 1; } return a; } ll gcd(ll a, ll b) { while (b) { ll c = a % b; a = b; b = c; } return a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) return a = b, true; else return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) return a = b, true; else return false; } ll dp[105][100005]; void solve() { ll N, W; cin >> N >> W; ll w[105], v[105]; rep(i, N) cin >> w[i] >> v[i]; dp[0][0] = 0; REP(j, 1, 100000 + 1) dp[0][j] = llinf; rep(i, N) { rep(j, 100000 + 1) { if (j - v[i] >= 0) { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } else { dp[i + 1][j] = dp[i][j]; } } } rrep(i, 100000 + 1) { if (dp[N][i] <= W) { cout << i << endl; break; } } } int main() { // FastIO // ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
970,125
970,126
u969945299
cpp
p03164
#include <bits/stdc++.h> using namespace std; const int UNCALCULATED = -1; const int MAXN = 100 + 10, MAXV = 100 * 1000 + 10; long dp[MAXN][MAXV]; long v[MAXN], w[MAXN]; long calc(int i, int j) { if (j < 0) return 1e9; if (i == 0) if (j == 0) return 0; else return 1e9; if (dp[i][j] != UNCALCULATED) return dp[i][j]; return dp[i][j] = min(w[i] + calc(i - 1, j - v[i]), calc(i - 1, j)); } int main() { for (int i = 0; i < MAXN; i++) { for (int j = 0; j < MAXV; j++) { dp[i][j] = UNCALCULATED; } } int n, total; cin >> n >> total; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int j = MAXV - 1; j >= 0; j--) { if (calc(n, j) <= total) { cout << j << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int UNCALCULATED = -1; const int MAXN = 100 + 10, MAXV = 100 * 1000 + 10; long dp[MAXN][MAXV]; long v[MAXN], w[MAXN]; long calc(int i, int j) { if (j < 0) return 2e9; if (i == 0) if (j == 0) return 0; else return 2e9; if (dp[i][j] != UNCALCULATED) return dp[i][j]; return dp[i][j] = min(w[i] + calc(i - 1, j - v[i]), calc(i - 1, j)); } int main() { for (int i = 0; i < MAXN; i++) { for (int j = 0; j < MAXV; j++) { dp[i][j] = UNCALCULATED; } } int n, total; cin >> n >> total; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int j = MAXV - 1; j >= 0; j--) { if (calc(n, j) <= total) { cout << j << endl; return 0; } } return 0; }
[ "literal.number.change", "function.return_value.change" ]
970,135
970,136
u337802798
cpp
p03164
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) using namespace std; using P = pair<int, int>; using ll = long long; ll INF = 100100100100100100; int main() { // input int n; int w; cin >> n >> w; vector<int> weights(n + 1); vector<int> values(n + 1); ll max_value_sum = 0; ll max_weight_sum = 0; rep(i, n) { cin >> weights[i + 1]; // weight cin >> values[i + 1]; // values max_value_sum += values[i + 1]; max_weight_sum += weights[i + 1]; } // dp vector<vector<ll>> dp(n + 1, vector<ll>(max_value_sum + 1)); rep(i, n + 1) rep(v, max_value_sum + 1) dp[i][v] = INF; dp[0][0] = 0; for (int i = 0; i < n; i++) { for (ll v = 0; v <= max_value_sum; v++) { if (values[i] <= v) dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i + 1]] + weights[i + 1]); else dp[i + 1][v] = dp[i][v]; } } // output ll ans = 0; for (ll v = 0; v <= max_value_sum; v++) { if (dp[n][v] <= w) { ans = max(ans, (ll)v); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) using namespace std; using P = pair<int, int>; using ll = long long; ll INF = 100100100100100100; int main() { // input int n; int w; cin >> n >> w; vector<int> weights(n + 1); vector<int> values(n + 1); ll max_value_sum = 0; ll max_weight_sum = 0; rep(i, n) { cin >> weights[i + 1]; // weight cin >> values[i + 1]; // values max_value_sum += values[i + 1]; max_weight_sum += weights[i + 1]; } // dp vector<vector<ll>> dp(n + 1, vector<ll>(max_value_sum + 1)); rep(i, n + 1) rep(v, max_value_sum + 1) dp[i][v] = INF; dp[0][0] = 0; for (int i = 0; i < n; i++) { for (ll v = 0; v <= max_value_sum; v++) { if (values[i + 1] <= v) dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i + 1]] + weights[i + 1]); else dp[i + 1][v] = dp[i][v]; } } // output ll ans = 0; for (ll v = 0; v <= max_value_sum; v++) { if (dp[n][v] <= w) { ans = max(ans, (ll)v); } } cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
970,147
970,148
u058958514
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const int MOD = (int)1e9 + 7; const int INF = (int)1e9; const ll LINF = (ll)1e18; const int MAX_N = 110; const int MAX_V = 100100; int N; ll W, weight[MAX_N], value[MAX_N]; ll dp[MAX_N][MAX_V]; int main() { cin >> N >> W; rep(i, N) cin >> weight[i] >> value[i]; rep(i, MAX_N) rep(j, MAX_V) dp[i][j]; dp[0][0] = 0; rep(i, N) { for (int sum_v = 0; sum_v < MAX_V; sum_v++) { if (sum_v - value[i] >= 0) dp[i + 1][sum_v] = max(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]); dp[i + 1][sum_v] = max(dp[i + 1][sum_v], dp[i][sum_v]); } } ll res = 0; rep(sum_v, MAX_V) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << 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 int MOD = (int)1e9 + 7; const int INF = (int)1e9; const ll LINF = (ll)1e18; const int MAX_N = 110; const int MAX_V = 100100; int N; ll W, weight[MAX_N], value[MAX_N]; ll dp[MAX_N][MAX_V]; int main() { cin >> N >> W; rep(i, N) cin >> weight[i] >> value[i]; rep(i, MAX_N) rep(j, MAX_V) dp[i][j] = LINF; dp[0][0] = 0; rep(i, N) { for (int sum_v = 0; sum_v < MAX_V; sum_v++) { if (sum_v - value[i] >= 0) dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]); dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v]); } } ll res = 0; rep(sum_v, MAX_V) { if (dp[N][sum_v] <= W) res = sum_v; } cout << res << endl; }
[ "assignment.change", "misc.opposites", "assignment.value.change", "identifier.change", "call.function.change" ]
970,164
970,165
u607594286
cpp
p03164
#include <algorithm> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; #define rep(i, a, n) for (int i = (a); i < (n); i++) #define ll long long #define llint long long int #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) \ if (ans) \ cout << "Yes" << endl; \ else \ cout << "No" << endl; #define YES(ans) \ if (ans) \ cout << "YES" << endl; \ else \ cout << "NO" << endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define Pint pair<int, int> #define keta(a) fixed << setprecision(a) constexpr auto INF = 1000000000; constexpr auto mod = 1000000007; //่พžๆ›ธ้ †ใฏnext_permutation( begin( v ), end( v ) );ใ‚„ใง๏ผ llint gcd(llint a, llint b) { if (b > a) swap(a, b); if (a % b == 0) return b; return gcd(b, a % b); } llint Tow(int n) { // 2ใฎnไน— if (n == 0) return 1; llint x = Tow(n / 2); x %= mod; x *= x; x %= mod; if (n % 2 == 1) x *= 10; x %= mod; return x; } int main() { int N, W; cin >> N >> W; hei(llint) w(N), v(N); int sumV = 0; rep(i, 0, N) { cin >> w[i] >> v[i]; sumV += v[i]; } whei(llint) dp(N + 1, hei(llint)(sumV + 1, INF)); rep(i, 0, N + 1) dp[i][0] = 0; rep(i, 0, N) { rep(j, 0, sumV) { if (j >= v[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } int ans = 0; rep(i, 0, sumV + 1) if (dp[N][i] <= W) ans = i; cout << ans << endl; return 0; }
#include <algorithm> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <time.h> #include <vector> using namespace std; #define rep(i, a, n) for (int i = (a); i < (n); i++) #define ll long long #define llint long long int #define reverse(v) reverse(v.begin(), v.end()); #define Yes(ans) \ if (ans) \ cout << "Yes" << endl; \ else \ cout << "No" << endl; #define YES(ans) \ if (ans) \ cout << "YES" << endl; \ else \ cout << "NO" << endl; #define hei(a) vector<a> #define whei(a) vector<vector<a>> #define UF UnionFind #define Pint pair<int, int> #define keta(a) fixed << setprecision(a) constexpr auto INF = 1000000000; constexpr auto mod = 1000000007; //่พžๆ›ธ้ †ใฏnext_permutation( begin( v ), end( v ) );ใ‚„ใง๏ผ llint gcd(llint a, llint b) { if (b > a) swap(a, b); if (a % b == 0) return b; return gcd(b, a % b); } llint Tow(int n) { // 2ใฎnไน— if (n == 0) return 1; llint x = Tow(n / 2); x %= mod; x *= x; x %= mod; if (n % 2 == 1) x *= 10; x %= mod; return x; } int main() { int N, W; cin >> N >> W; hei(llint) w(N), v(N); int sumV = 0; rep(i, 0, N) { cin >> w[i] >> v[i]; sumV += v[i]; } whei(llint) dp(N + 1, hei(llint)(sumV + 1, INF)); rep(i, 0, N + 1) dp[i][0] = 0; rep(i, 0, N) { rep(j, 0, sumV + 1) { if (j >= v[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } int ans = 0; rep(i, 0, sumV + 1) if (dp[N][i] <= W) ans = i; cout << ans << endl; return 0; }
[ "expression.operation.binary.add" ]
970,170
970,171
u407213771
cpp
p03164
#include <algorithm> #include <array> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; #define i64 long long #define int long long #define I32_MAX 2147483647 #define I64_MAX 9223372036854775807 #define INF I64_MAX #define MOD 1000000007 #define MEM_SIZE = 1e5 + 5; template <typename T> void DEBUG(T e) { std::cout << "DEBUG>>" << e << std::endl; } template <typename T> void DEBUG(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { DEBUG(v); } } void solve(void) { int N, W; cin >> N >> W; vector<int> weight(N); vector<int> value(N); int V = 0; for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; V += value[i]; } vector<vector<int>> DP(N + 1, vector<int>(V + 1, INF / 4)); DP[0][0] = 0; for (int i = 1; i <= N; i++) { for (int v = 0; v <= V; v++) { if (v >= value[i - 1]) { DP[i][v] = min(DP[i - 1][v], DP[i - 1][v - value[i - 1]] + weight[i - 1]); } else { DP[i][v] = DP[i - 1][v]; } } } // DEBUG(DP); int ANS = 0; for (int i = 0; i < V; i++) { if (DP[N][i] <= W) { ANS = max(ANS, i); } } cout << ANS << endl; return; } int32_t main(int32_t argc, const char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed; std::cout << std::setprecision(8); solve(); return 0; }
#include <algorithm> #include <array> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; #define i64 long long #define int long long #define I32_MAX 2147483647 #define I64_MAX 9223372036854775807 #define INF I64_MAX #define MOD 1000000007 #define MEM_SIZE = 1e5 + 5; template <typename T> void DEBUG(T e) { std::cout << "DEBUG>>" << e << std::endl; } template <typename T> void DEBUG(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { DEBUG(v); } } void solve(void) { int N, W; cin >> N >> W; vector<int> weight(N); vector<int> value(N); int V = 0; for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; V += value[i]; } vector<vector<int>> DP(N + 1, vector<int>(V + 1, INF / 4)); DP[0][0] = 0; for (int i = 1; i <= N; i++) { for (int v = 0; v <= V; v++) { if (v >= value[i - 1]) { DP[i][v] = min(DP[i - 1][v], DP[i - 1][v - value[i - 1]] + weight[i - 1]); } else { DP[i][v] = DP[i - 1][v]; } } } // DEBUG(DP); int ANS = 0; for (int i = 0; i <= V; i++) { if (DP[N][i] <= W) { ANS = max(ANS, i); } } // DEBUG(DP); cout << ANS << endl; return; } int32_t main(int32_t argc, const char *argv[]) { std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout << std::fixed; std::cout << std::setprecision(8); solve(); return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
970,194
970,195
u221285045
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18L + 5; void solve() { int n; int W; cin >> n >> W; vector<int> w(n); vector<int> v(n); int total_value = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; total_value += v[i]; } vector<ll> dp(total_value + 1, INF); dp[0] = 0; // dp[i] = min weight for value i for (int item = 0; item < n; item++) { for (int value = total_value - v[item]; value >= 0; value--) { dp[value + v[item]] = min(dp[value + v[item]], dp[value] + w[item]); } } ll ans = 0; for (int i = 0; i < total_value; i++) { if (dp[i] <= W) { ans = max(ans, (ll)i); } } cout << ans << endl; } int main() { // int t; t = 1; // int t; cin >> t; // while(t--){ solve(); //} }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18L + 5; void solve() { int n; int W; cin >> n >> W; vector<int> w(n); vector<int> v(n); int total_value = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; total_value += v[i]; } vector<ll> dp(total_value + 1, INF); dp[0] = 0; // dp[i] = min weight for value i for (int item = 0; item < n; item++) { for (int value = total_value - v[item]; value >= 0; value--) { dp[value + v[item]] = min(dp[value + v[item]], dp[value] + w[item]); } } ll ans = 0; for (int i = 0; i <= total_value; i++) { if (dp[i] <= W) { ans = max(ans, (ll)i); } } cout << ans << endl; } int main() { // int t; t = 1; // int t; cin >> t; // while(t--){ solve(); //} }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
970,200
970,201
u922347667
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18L + 5; void solve() { ll n, W; cin >> n >> W; vector<ll> weight(n), value(n); int sum_value = 0; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; sum_value = value[i]; } vector<ll> dp(sum_value + 1, INF); dp[0] = 0; for (int item = 0; item < n; item++) { for (int value_already = sum_value - value[item]; value_already >= 0; value_already--) { dp[value_already + value[item]] = min(dp[value_already + value[item]], dp[value_already] + weight[item]); } } ll answer = 0; for (int i = 0; i <= sum_value; i++) { if (dp[i] <= W) { answer = max(answer, (ll)i); } } cout << answer << endl; } int main() { int t; // cin >> t; t = 1; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18L + 5; void solve() { ll n, W; cin >> n >> W; vector<ll> weight(n), value(n); int sum_value = 0; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; sum_value += value[i]; } vector<ll> dp(sum_value + 1, INF); dp[0] = 0; for (int item = 0; item < n; item++) { for (int value_already = sum_value - value[item]; value_already >= 0; value_already--) { dp[value_already + value[item]] = min(dp[value_already + value[item]], dp[value_already] + weight[item]); } } ll answer = 0; for (int i = 0; i <= sum_value; i++) { if (dp[i] <= W) { answer = max(answer, (ll)i); } } cout << answer << endl; } int main() { int t; // cin >> t; t = 1; while (t--) { solve(); } }
[ "assignment.value.change" ]
970,202
970,203
u922347667
cpp
p03164
#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 ld long double #define dd double #define ff first #define ss second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pll> vplll; ll mod = 1e9 + 7; const ld PI = 2 * acos(0.0); const vector<ll> dx = {1, -1, 0, 0}; const vector<ll> dy = {0, 0, 1, -1}; #define round(x, y) ((x + y - 1) / y) #define ce(x, y) ((x + y - 1) / y) #define amax(x, y) \ if (y > x) \ x = y; #define amin(x, y) \ if (y < x) \ x = y; #define lcm(x, y) ((x) * (y) / __gcd(x, y)) #define len(x) (ll) x.length() #define sq(x) ((x) * (x)) #define cb(x) ((x) * (x) * (x)) ll dp[101][100001]; ll ar[101][2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll a, b, c, t, w, n, m, k, q; t = 1; // cin>>t; while (t--) { // memset(dp,1e15,sizeof(dp)); cin >> n >> w; for (int i = 1; i <= n; i++) cin >> ar[i][0] >> ar[i][1]; for (int i = 0; i <= n; i++) for (int j = 1; j <= 1000 * n; j++) dp[i][j] = 1e18; for (int i = 1; i <= n; i++) { for (int v = 1; v <= 140; v++) { if (v >= ar[i][1]) dp[i][v] = min(dp[i - 1][v], dp[i - 1][v - ar[i][1]] + ar[i][0]); else dp[i][v] = dp[i - 1][v]; // cout<<i<<' '<<v<<" "<<dp[i][v]<<endl; } } ll ans = 0; for (ll i = 1; i <= 1000 * n; i++) { if (dp[n][i] <= w) ans = max(i, ans); } cout << ans << endl; } 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 ld long double #define dd double #define ff first #define ss second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() #define sz(a) (ll)(a.size()) typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef vector<pll> vplll; ll mod = 1e9 + 7; const ld PI = 2 * acos(0.0); const vector<ll> dx = {1, -1, 0, 0}; const vector<ll> dy = {0, 0, 1, -1}; #define round(x, y) ((x + y - 1) / y) #define ce(x, y) ((x + y - 1) / y) #define amax(x, y) \ if (y > x) \ x = y; #define amin(x, y) \ if (y < x) \ x = y; #define lcm(x, y) ((x) * (y) / __gcd(x, y)) #define len(x) (ll) x.length() #define sq(x) ((x) * (x)) #define cb(x) ((x) * (x) * (x)) ll dp[101][100001]; ll ar[101][2]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll a, b, c, t, w, n, m, k, q; t = 1; // cin>>t; while (t--) { // memset(dp,1e15,sizeof(dp)); cin >> n >> w; for (int i = 1; i <= n; i++) cin >> ar[i][0] >> ar[i][1]; for (int i = 0; i <= n; i++) for (int j = 1; j <= 1000 * n; j++) dp[i][j] = 1e18; for (int i = 1; i <= n; i++) { for (int v = 1; v <= 1000 * n; v++) { if (v >= ar[i][1]) dp[i][v] = min(dp[i - 1][v], dp[i - 1][v - ar[i][1]] + ar[i][0]); else dp[i][v] = dp[i - 1][v]; // cout<<i<<' '<<v<<" "<<dp[i][v]<<endl; } } ll ans = 0; for (ll i = 1; i <= 1000 * n; i++) { if (dp[n][i] <= w) ans = max(i, ans); } cout << ans << endl; } return 0; }
[ "literal.number.change", "control_flow.loop.condition.change", "control_flow.loop.for.condition.change" ]
970,208
970,209
u564435024
cpp
p03164
#include "bits/stdc++.h" using namespace std; ////////////// Prewritten code follows. Look down for solution. //////////////// #define fs first #define sc second #define pb push_back #define len(x) ((int)(x).size()) #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; const ll LINF = 1e18; const int INF = 1e9; const int MOD = 1e9 + 7; /// command for char arrays with spaces -> scanf(" %[^\n]", text); ////////////////////////// Solution starts below. ////////////////////////////// int main() { fastio; int n; ll p; cin >> n >> p; int max_value = 0; vector<int> valor(n); vector<ll> peso(n); for (int i = 1; i <= n; i++) { cin >> peso[i] >> valor[i]; max_value += valor[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(max_value + 1, LINF)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i - 1][0] = 0; for (int j = 1; j <= max_value; j++) { if (j < valor[i]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - valor[i]] + peso[i]); } } int ans = 0; for (int i = max_value; i >= 0; i--) { // cout << i << endl; if (dp[n][i] <= p) { ans = i; break; } } cout << ans << '\n'; return 0; }
#include "bits/stdc++.h" using namespace std; ////////////// Prewritten code follows. Look down for solution. //////////////// #define fs first #define sc second #define pb push_back #define len(x) ((int)(x).size()) #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; const ll LINF = 1e18; const int INF = 1e9; const int MOD = 1e9 + 7; /// command for char arrays with spaces -> scanf(" %[^\n]", text); ////////////////////////// Solution starts below. ////////////////////////////// int main() { fastio; int n; ll p; cin >> n >> p; int max_value = 0; vector<int> valor(n + 1); vector<ll> peso(n + 1); for (int i = 1; i <= n; i++) { cin >> peso[i] >> valor[i]; max_value += valor[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(max_value + 1, LINF)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i - 1][0] = 0; for (int j = 1; j <= max_value; j++) { if (j < valor[i]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - valor[i]] + peso[i]); } } int ans = 0; for (int i = max_value; i >= 0; i--) { // cout << i << endl; if (dp[n][i] <= p) { ans = i; break; } } cout << ans << '\n'; return 0; }
[ "assignment.change" ]
970,213
970,214
u567661286
cpp