Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03163
#include <bits/stdc++.h> #define ll long long #define lsb(x) (x & -x) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("a.in", "r", stdin); int n, w; cin >> n >> w; vector<int> dp(w + 1, 0); vector<int> a(n + 1, 0); vector<int> b(n + 1, 0); for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; int lim = 0; for (int i = 1; i <= n; i++) { for (int s = lim; s >= 0; s--) if (s + a[i] <= w) dp[s + a[i]] = max(dp[s] + b[i], dp[s + a[i]]); lim += a[i]; } int ans = 0; for (int i = 0; i <= w; i++) ans = max(ans, dp[i]); cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define lsb(x) (x & -x) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen("a.in", "r", stdin); int n, w; cin >> n >> w; vector<ll> dp(w + 1, 0); vector<int> a(n + 1, 0); vector<ll> b(n + 1, 0); for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; int lim = 0; for (int i = 1; i <= n; i++) { for (int s = lim; s >= 0; s--) if (s + a[i] <= w) dp[s + a[i]] = max(dp[s] + b[i], dp[s + a[i]]); lim += a[i]; } ll ans = 0; for (int i = 0; i <= w; i++) ans = max(ans, dp[i]); cout << ans; return 0; }
[ "variable_declaration.type.change" ]
970,957
970,958
u088237968
cpp
p03164
// {{{ #include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define FOR(i, a, b) \ for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++) #define FORR(i, a, b) \ for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--) #define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++) #define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> IP; typedef pair<ll, LP> LLP; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; constexpr int INF = 100000000; constexpr ll LINF = 10000000000000000ll; constexpr int MOD = static_cast<int>(1e9 + 7); constexpr double EPS = 1e-9; // }}} ll N, W; ll w[101], v[101]; ll dp[101][100001]; void init() {} void solve() { FOR(i, 0, 100001) dp[1][i] = (i <= v[1] ? w[i] : LINF); // FOR(i, 0, 100001){ // FOR(j, 1, N+1){ // if(i <= v[j]) dp[1][i] = min(dp[1][i], w[j]); // } //} FOR(i, 2, N + 1) { REP(j, 100001) { 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]); } } } REPR(i, 100000) { if (dp[N][i] <= W) { cout << i << endl; break; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> W; FOR(i, 1, N + 1) cin >> w[i] >> v[i]; solve(); return 0; } // vim:set foldmethod=marker:
// {{{ #include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define FOR(i, a, b) \ for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++) #define FORR(i, a, b) \ for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--) #define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++) #define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> IP; typedef pair<ll, LP> LLP; const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, 1, -1}; constexpr int INF = 100000000; constexpr ll LINF = 10000000000000000ll; constexpr int MOD = static_cast<int>(1e9 + 7); constexpr double EPS = 1e-9; // }}} ll N, W; ll w[101], v[101]; ll dp[101][100001]; void init() {} void solve() { FOR(i, 1, 100001) dp[1][i] = (i <= v[1] ? w[1] : LINF); FOR(i, 2, N + 1) { REP(j, 100001) { 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]); } } } REPR(i, 100000) { if (dp[N][i] <= W) { cout << i << endl; break; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> W; FOR(i, 1, N + 1) cin >> w[i] >> v[i]; solve(); return 0; } // vim:set foldmethod=marker:
[ "literal.number.change", "assignment.variable.change", "call.arguments.change", "assignment.value.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change" ]
970,970
970,971
u367602070
cpp
p03164
#include <bits/stdc++.h> using namespace std; const long long k = 1e11; #define ll long long void min_s(ll &a, ll b) { a = min(a, b); } int main() { ll n, m; cin >> n >> m; ll w[n], p[n]; ll sum = 0; for (ll i = 0; i < n; i++) { cin >> w[i] >> p[i]; sum += p[i]; } vector<ll> v(sum + 1, k); v[0] = 0; for (ll i = 0; i < n; i++) { for (ll j = sum - p[i]; j >= 0; --j) { min_s(v[j + p[i]], v[j] + w[i]); } } ll ans = 0; for (ll i = 0; i < sum; i++) { if (v[i] <= m) { ans = max(ans, i); } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const long long k = 1e11; #define ll long long void min_s(ll &a, ll b) { a = min(a, b); } int main() { ll n, m; cin >> n >> m; ll w[n], p[n]; ll sum = 0; for (ll i = 0; i < n; i++) { cin >> w[i] >> p[i]; sum += p[i]; } vector<ll> v(sum + 1, k); v[0] = 0; for (ll i = 0; i < n; i++) { for (ll j = sum - p[i]; j >= 0; --j) { min_s(v[j + p[i]], v[j] + w[i]); } } ll ans = 0; for (ll i = 0; i <= sum; i++) { // cout<<v[i]<<' '; if (v[i] <= m) { ans = max(ans, i); } } cout << ans; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
970,974
970,975
u694722603
cpp
p03164
#include <bits/stdc++.h> using namespace std; const long long k = 1e11; #define ll long long void min_s(ll &a, ll b) { a = min(a, b); } int main() { ll n, m; cin >> n >> m; ll w[n], p[n]; ll sum = 0; for (ll i = 0; i < n; i++) { cin >> w[i] >> p[i]; sum += p[i]; } vector<ll> v(sum + 1, k); v[0] = 0; for (ll i = 0; i < n; i++) { for (int j = sum - p[i]; j >= 0; --j) { min_s(v[j + p[i]], v[j] + w[i]); // cout<<v[j+p[i]]<<' '; } // cout<<'\n'; } ll ans = 0; for (ll i = 0; i < sum; i++) { // cout<<v[i]<<' '; if (v[i] <= m) { ans = max(ans, i); } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const long long k = 1e11; #define ll long long void min_s(ll &a, ll b) { a = min(a, b); } int main() { ll n, m; cin >> n >> m; ll w[n], p[n]; ll sum = 0; for (ll i = 0; i < n; i++) { cin >> w[i] >> p[i]; sum += p[i]; } vector<ll> v(sum + 1, k); v[0] = 0; for (ll i = 0; i < n; i++) { for (ll j = sum - p[i]; j >= 0; --j) { min_s(v[j + p[i]], v[j] + w[i]); } } ll ans = 0; for (ll i = 0; i <= sum; i++) { // cout<<v[i]<<' '; if (v[i] <= m) { ans = max(ans, i); } } cout << ans; return 0; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
970,976
970,975
u694722603
cpp
p03164
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define s second #define f first #define MOD 1000000007 // #define using namespace std; const ll INF = 1e18L + 5; int main() { ll a, b, i, j, n, w, val = 0; vector<pair<ll, ll>> v; cin >> n >> w; for (i = 0; i < n; i++) { cin >> a >> b; val += b; v.pb({a, b}); } vector<ll> arr(val + 5, INF); arr[0] = 0; for (i = 0; i < n; i++) { for (j = val - v[i].s; j >= 0; j--) { arr[j + v[i].s] = min(arr[i + v[i].s], arr[j] + v[i].f); } } // for(i=0;i<=val;i++) // cout<<arr[i]<<" "; ll ans = 0; for (i = 0; i <= val; i++) { if (arr[i] <= w) ans = max(ans, i); } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long int #define pb push_back #define s second #define f first #define MOD 1000000007 // #define using namespace std; const ll INF = 1e18L + 5; int main() { ll a, b, i, j, n, w, val = 0; vector<pair<ll, ll>> v; cin >> n >> w; for (i = 0; i < n; i++) { cin >> a >> b; val += b; v.pb({a, b}); } vector<ll> arr(val + 5, INF); arr[0] = 0; for (i = 0; i < n; i++) { for (j = val - v[i].s; j >= 0; j--) { arr[j + v[i].s] = min(arr[j + v[i].s], arr[j] + v[i].f); } } // for(i=0;i<=val;i++) // cout<<arr[i]<<" "; ll ans = 0; for (i = 0; i <= val; i++) { if (arr[i] <= w) ans = max(ans, i); } cout << ans; return 0; }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
970,988
970,989
u460223842
cpp
p03164
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < (int)n; ++i) #define rfor(i, n) for (int i = n - 1; i >= 0; --i) #define rmod(x, y) (((x % y) + y) % y) using namespace std; typedef vector<int>::iterator vit; typedef unsigned int uint; typedef unsigned short ushort; typedef long long ll; const int MAXN = 1024; // OPERATORS // GLOBALS // FUNCTIONS ll arr[100000]; int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, w; cin >> n >> w; vector<ll> pesos(n, 0); vector<ll> costo(n, 0); int costoT = 0; for (int i = 0; i < n; i++) { cin >> pesos[i] >> costo[i]; costoT += costo[i]; } for (int i = 0; i <= costoT; i++) { arr[i] = 100000000000; } arr[0] = 0; for (int i = 0; i < n; i++) { for (int j = costoT; j >= costo[i]; j--) { arr[j] = min(arr[j], arr[j - costo[i]] + pesos[i]); } } ll mx = 0; for (ll i = 0; i < costoT; i++) { if (arr[i] <= w) mx = max(i, mx); } cout << mx << endl; return 0; }
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < (int)n; ++i) #define rfor(i, n) for (int i = n - 1; i >= 0; --i) #define rmod(x, y) (((x % y) + y) % y) using namespace std; typedef vector<int>::iterator vit; typedef unsigned int uint; typedef unsigned short ushort; typedef long long ll; const int MAXN = 1024; // OPERATORS // GLOBALS // FUNCTIONS ll arr[100000]; int main() { ios::sync_with_stdio(0); cin.tie(0); ll n, w; cin >> n >> w; vector<ll> pesos(n, 0); vector<ll> costo(n, 0); int costoT = 0; for (int i = 0; i < n; i++) { cin >> pesos[i] >> costo[i]; costoT += costo[i]; } for (int i = 0; i <= costoT; i++) { arr[i] = 100000000000; } arr[0] = 0; for (int i = 0; i < n; i++) { for (int j = costoT; j >= costo[i]; j--) { arr[j] = min(arr[j], arr[j - costo[i]] + pesos[i]); } } ll mx = 0; for (ll i = 0; i <= costoT; i++) { if (arr[i] <= w) mx = max(i, mx); } cout << mx << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
970,998
970,999
u558825435
cpp
p03164
// Subhash Suman // Description : #include <bits/stdc++.h> #define ll long long int #define pll pair<ll, ll> #define pii pair<int, int> using namespace std; const int N = 105, V = 1e5 + 5, INF = 1e6; ll n, w, dp[N][V], arr1[N], arr2[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> arr1[i] >> arr2[i]; } for (int i = 0; i < N - 2; i++) { for (int j = 1; j < V - 2; j++) { dp[i][j] = INF; } } for (int i = 1; i <= n; i++) { for (int vi = 1; vi <= V - 3; vi++) { if (vi - arr2[i] >= 0) { dp[i][vi] = min(dp[i][vi], dp[i - 1][vi - arr2[i]] + arr1[i]); } dp[i][vi] = min(dp[i][vi], dp[i - 1][vi]); } } ll ans = 0; for (int i = 0; i < V - 2; i++) { if (dp[n][i] <= w) { ans = i; } } cout << ans << '\n'; return 0; }
// Subhash Suman // Description : #include <bits/stdc++.h> #define ll long long int #define pll pair<ll, ll> #define pii pair<int, int> using namespace std; const int N = 105, V = 1e5 + 5; ll INF = 1e10; ll n, w, dp[N][V], arr1[N], arr2[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> arr1[i] >> arr2[i]; } for (int i = 0; i < N - 2; i++) { for (int j = 1; j < V - 2; j++) { dp[i][j] = INF; } } for (int i = 1; i <= n; i++) { for (int vi = 1; vi <= V - 3; vi++) { if (vi - arr2[i] >= 0) { dp[i][vi] = min(dp[i][vi], dp[i - 1][vi - arr2[i]] + arr1[i]); } dp[i][vi] = min(dp[i][vi], dp[i - 1][vi]); } } ll ans = 0; for (int i = 0; i < V - 2; i++) { if (dp[n][i] <= w) { ans = i; } } cout << ans << '\n'; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
971,000
971,001
u680559271
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll dp[102][100005]; int main() { ll n, W; cin >> n >> W; ll va[n + 1], wt[n + 1]; for (int i = 1; i <= n; i++) cin >> wt[i] >> va[i]; for (int i = 0; i <= n; i++) for (int j = 1; j <= 100000; j++) dp[i][j] = INT_MAX; ll ans = 0; for (int i = 1; i <= n; i++) { for (ll j = 1; j <= 100; j++) { if (j < va[i]) { dp[i][j] = dp[i - 1][j]; continue; } dp[i][j] = min(dp[i - 1][j - va[i]] + wt[i], dp[i][j]); dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (dp[i][j] <= W) ans = max(ans, j); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll dp[102][100005]; int main() { ll n, W; cin >> n >> W; ll va[n + 1], wt[n + 1]; for (int i = 1; i <= n; i++) cin >> wt[i] >> va[i]; for (int i = 0; i <= n; i++) for (int j = 1; j <= 100000; j++) dp[i][j] = INT_MAX; ll ans = 0; for (int i = 1; i <= n; i++) { for (ll j = 1; j <= 100000; j++) { if (j < va[i]) { dp[i][j] = dp[i - 1][j]; continue; } dp[i][j] = min(dp[i - 1][j - va[i]] + wt[i], dp[i][j]); dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (dp[i][j] <= W) ans = max(ans, j); } } cout << ans << endl; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,002
971,003
u109008163
cpp
p03164
#include <bits/stdc++.h> #define itn int #define REP(i, n) for (int i = 0; i < (n); i++) #define IREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define REPEACH(itr, k) for (autaaaaaaaaaaaaaaaaaaaaaaao && itr : k) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll INF = 1ll << 60; const ll MOD = 1000000007; int n; vector<int> v(100000); int main() { int n, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>(n * 1000 + 1, INF)); dp[0][0] = 0; pair<int, int> inp[n]; REP(i, n) { cin >> inp[i].first >> inp[i].second; } REP(i, n) { REP(j, 1000 * n + 1) { if (j - inp[i].second >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - inp[i].second] + inp[i].second); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ll ans = 0; REP(i, 1000 * n) { if (dp[n][i + 1] <= w) { ans = i + 1; } } cout << ans << endl; }
#include <bits/stdc++.h> #define itn int #define REP(i, n) for (int i = 0; i < (n); i++) #define IREP(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (n); i++) #define REPEACH(itr, k) for (autaaaaaaaaaaaaaaaaaaaaaaao && itr : k) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll INF = 1ll << 60; const ll MOD = 1000000007; int n; vector<int> v(100000); int main() { int n, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>(n * 1000 + 1, INF)); dp[0][0] = 0; pair<int, int> inp[n]; REP(i, n) { cin >> inp[i].first >> inp[i].second; } REP(i, n) { REP(j, 1000 * n + 1) { if (j - inp[i].second >= 0) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - inp[i].second] + inp[i].first); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ll ans = 0; REP(i, 1000 * n) { if (dp[n][i + 1] <= w) { ans = i + 1; } } cout << ans << endl; }
[ "expression.operation.binary.remove", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change" ]
971,012
971,013
u118875091
cpp
p03164
#include <bits/stdc++.h> #define ll long long using namespace std; int f[200011], n, m, w[110], c[110], ans; int main() { memset(f, 0x7f, sizeof(f)); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i] >> c[i]; f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 200010; j >= c[i]; j--) { f[j] = min(f[j], f[j - c[i]] + w[i]); } } for (int j = 0; j <= 200010; j++) { if (f[j] <= m) ans = j; // cout<<f[j]<<endl; } // cout<<endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; ll f[200011], n, m, w[110], c[110], ans; int main() { memset(f, 0x7f, sizeof(f)); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i] >> c[i]; f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 200010; j >= c[i]; j--) { f[j] = min(f[j], f[j - c[i]] + w[i]); } } for (int j = 0; j <= 200010; j++) { if (f[j] <= m) ans = j; // cout<<f[j]<<endl; } // cout<<endl; cout << ans << endl; return 0; }
[ "variable_declaration.type.change" ]
971,018
971,019
u247270112
cpp
p03164
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long 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; } int main() { int n, upp_w; cin >> n >> upp_w; ll w[n], v[n]; for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; } int sum_vmax = 0; ll sum_wmax = 0; for (int i = 0; i < n; ++i) { sum_vmax += v[i]; sum_wmax += w[i]; } //初期化 初期条件 ll dp[n + 5][sum_vmax + 5]; for (int i = 0; i < n + 5; ++i) { for (int sum_v; sum_v < sum_vmax + 5; ++sum_v) { dp[i][sum_vmax] = sum_wmax; } } for (int i = 0; i < n; ++i) { for (int sum_v = 0; sum_v <= sum_vmax; ++sum_v) { chmin(dp[i + 1][sum_v], dp[i][sum_v]); } for (int sum_v = 0; sum_v <= sum_vmax - v[i]; ++sum_v) { chmin(dp[i + 1][sum_v], dp[i][sum_v + v[i]] - w[i]); } } int ans = 0; for (int sum_v = sum_vmax; sum_v >= 0; --sum_v) { for (int i = 0; i < n; ++i) { if (dp[i][sum_v] <= upp_w) { ans = sum_v; break; } } if (ans) break; } cout << ans; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long 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; } int main() { int n, upp_w; cin >> n >> upp_w; ll w[n], v[n]; for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; } int sum_vmax = 0; ll sum_wmax = 0; for (int i = 0; i < n; ++i) { sum_vmax += v[i]; sum_wmax += w[i]; } //初期化 初期条件 ll dp[n + 5][sum_vmax + 5]; for (int i = 0; i < n + 5; ++i) { for (int sum_v = 0; sum_v < sum_vmax + 5; ++sum_v) { dp[i][sum_v] = sum_wmax; } } //ループ for (int i = 0; i < n; ++i) { for (int sum_v = 0; sum_v <= sum_vmax; ++sum_v) { chmin(dp[i + 1][sum_v], dp[i][sum_v]); } for (int sum_v = 0; sum_v <= sum_vmax - v[i]; ++sum_v) { chmin(dp[i + 1][sum_v], dp[i][sum_v + v[i]] - w[i]); } } //解の出力 int ans = 0; for (int sum_v = sum_vmax; sum_v >= 0; --sum_v) { for (int i = 0; i < n + 1; ++i) { if (dp[i][sum_v] <= upp_w) { ans = sum_v; break; } } if (ans) break; } cout << ans; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.value.change", "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
971,022
971,023
u771806944
cpp
p03164
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) using namespace std; typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll mod = 1e9 + 7; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int N, W, w[101], v[101]; ll dp[101][200020]; int main() { cin >> N >> W; rep(i, 0, N) cin >> w[i] >> v[i]; rep(i, 0, N) rep(val, 0, N * 1010) dp[i][val] = inf; dp[0][0] = 0; rep(i, 0, N) rep(val, 0, N * 1010) { chmin(dp[i + 1][val], dp[i][val]); chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]); } int res = 0; rep(val, 0, N * 1010) if (dp[N][val] <= W) chmax(res, val); cout << res << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) using namespace std; typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; const ll mod = 1e9 + 7; template <typename T> ostream &operator<<(ostream &os, vector<T> v) { for (auto &i : v) os << i << " "; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &i : v) is >> i; return is; } template <typename K, typename V> ostream &operator<<(ostream &os, unordered_map<K, V> m) { for (auto &i : m) os << i.first << ":" << i.second << endl; return os; } template <typename T> inline bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } int N, W, w[101], v[101]; int dp[101][200020]; int main() { cin >> N >> W; rep(i, 0, N) cin >> w[i] >> v[i]; rep(i, 0, N + 1) rep(val, 0, N * 1010) dp[i][val] = inf; dp[0][0] = 0; rep(i, 0, N) rep(val, 0, N * 1010) { chmin(dp[i + 1][val], dp[i][val]); chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]); } int res = 0; rep(val, 0, N * 1010) if (dp[N][val] <= W) chmax(res, val); cout << res << endl; return 0; }
[ "variable_declaration.type.change" ]
971,024
971,025
u171804186
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<long long> dp(N * 1e3 + 1, INT_MAX / 2); dp[0] = 0; for (int i = 0; i < N; i++) { int w, v; cin >> w >> v; vector<long long> nextdp(dp); for (int j = 0; j < dp.size(); j++) { if (j + v < dp.size()) { nextdp[j + v] = min(dp[j + v], dp[j] + w); } } dp = nextdp; } int ans; for (int i = 0; i < dp.size(); i++) { if (dp[i] <= W) ans = i; } cout << 1e3 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; vector<long long> dp(N * 1e3 + 1, INT_MAX / 2); dp[0] = 0; for (int i = 0; i < N; i++) { int w, v; cin >> w >> v; vector<long long> nextdp(dp); for (int j = 0; j < dp.size(); j++) { if (j + v < dp.size()) { nextdp[j + v] = min(dp[j + v], dp[j] + w); } } dp = nextdp; } int ans; for (int i = 0; i < dp.size(); i++) { if (dp[i] <= W) ans = i; } cout << ans << endl; }
[ "identifier.replace.add", "literal.replace.remove", "io.output.change" ]
971,030
971,031
u544437817
cpp
p03164
#include <iostream> using namespace std; const int maxn = 100 + 10; const int maxnn = 1e5 + 10; long long n, W, now = 1, pre; long long dp[maxnn]; long long ans; long long v[maxn], w[maxnn]; int main() { cin >> n >> W; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int i = 1; i < maxnn; i++) { dp[i] = 1e9 + 10; } for (int i = 1; i <= n; i++) { for (long long j = maxnn - 1; j >= 0; j--) { if (j - v[i] < 0) { continue; } dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } // cout<<dp[10] << endl; for (long long i = 1; i <= maxnn; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; const int maxn = 100 + 10; const int maxnn = 1e5 + 10; long long n, W, now = 1, pre; long long dp[maxnn]; long long ans; long long v[maxn], w[maxnn]; int main() { cin >> n >> W; for (int i = 1; i <= n; i++) cin >> w[i] >> v[i]; for (int i = 1; i < maxnn; i++) { dp[i] = 1e9 + 10; } for (int i = 1; i <= n; i++) { for (long long j = maxnn - 1; j >= 0; j--) { if (j - v[i] < 0) { continue; } dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } // cout<<dp[10] << endl; for (long long i = 1; i < maxnn; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,036
971,037
u962571628
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; void solve() { ll n, tw; cin >> n >> tw; vector<ll> w(n), v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll total_val_possible = 0; for (int val : v) total_val_possible += val; vector<ll> dp(total_val_possible + 1, 1e10); dp[0] = 0; for (int i = 0; i < n; i++) { for (int value_already = total_val_possible - v[i]; value_already >= 0; value_already--) { dp[value_already + v[i]] = min(dp[value_already + v[i]], dp[value_already] + w[i]); } } ll ans = 0; for (int i = 0; i < total_val_possible; i++) { if (dp[i] <= tw) ans = i; } cout << ans << endl; } int main() { // int n; // cin>>n; // while(n--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; void solve() { ll n, tw; cin >> n >> tw; vector<ll> w(n), v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll total_val_possible = 0; for (int val : v) total_val_possible += val; vector<ll> dp(total_val_possible + 1, 1e9); dp[0] = 0; for (int i = 0; i < n; i++) { for (int value_already = total_val_possible - v[i]; value_already >= 0; value_already--) { dp[value_already + v[i]] = min(dp[value_already + v[i]], dp[value_already] + w[i]); } } ll ans = 0; for (int i = 0; i <= total_val_possible; i++) { if (dp[i] <= tw) ans = i; } cout << ans << endl; } int main() { // int n; // cin>>n; // while(n--) solve(); return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,060
971,061
u958501859
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; void solve() { int n, tw; cin >> n >> tw; vector<int> w(n), v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll total_val_possible = 0; for (int val : v) total_val_possible += val; vector<ll> dp(total_val_possible + 1, 1e10); dp[0] = 0; for (int i = 0; i < n; i++) { for (int value_already = total_val_possible - v[i]; value_already >= 0; value_already--) { dp[value_already + v[i]] = min(dp[value_already + v[i]], dp[value_already] + w[i]); } } ll ans = 0; for (int i = 0; i < total_val_possible; i++) { if (dp[i] <= tw) ans = i; } cout << ans << endl; } int main() { // int n; // cin>>n; // while(n--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; void solve() { ll n, tw; cin >> n >> tw; vector<ll> w(n), v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll total_val_possible = 0; for (int val : v) total_val_possible += val; vector<ll> dp(total_val_possible + 1, 1e9); dp[0] = 0; for (int i = 0; i < n; i++) { for (int value_already = total_val_possible - v[i]; value_already >= 0; value_already--) { dp[value_already + v[i]] = min(dp[value_already + v[i]], dp[value_already] + w[i]); } } ll ans = 0; for (int i = 0; i <= total_val_possible; i++) { if (dp[i] <= tw) ans = i; } cout << ans << endl; } int main() { // int n; // cin>>n; // while(n--) solve(); return 0; }
[ "variable_declaration.type.change", "literal.number.change", "call.arguments.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,062
971,061
u958501859
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define INF 2000000000 typedef long long ll; ll n, w, val[200], weight[200], dp[100010][200]; ll f(ll cur_val, ll cur_i) { // cout << "inside with: " << cur_val << " " << cur_i << endl; if (cur_val < 0) { // cout << "negative!" << endl; return INF; } if (dp[cur_val][cur_i] != -1) { // cout << "already: " << dp[cur_val][cur_i] << endl; return dp[cur_val][cur_i]; } if (cur_i == n) { if (cur_val == 0) { // cout << "returning 0" << endl; return 0; } else { // cout << "returning INF" << endl; return INF; } } dp[cur_val][cur_i] = min(f(cur_val, cur_i + 1), f(cur_val - val[cur_i], cur_i + 1) + weight[cur_i]); return dp[cur_val][cur_i]; } int main() { for (ll i = 0; i < 100001; i++) { for (ll j = 0; j < 200; j++) { dp[i][j] = -1; } } cin >> n >> w; for (ll i = 0; i < n; i++) { cin >> weight[i] >> val[i]; } // cout << " " << endl; // return 0; for (ll i = 100001; i >= 0; i--) { // cout << "outside with: " << i << endl; if (f(i, 0) <= w) { cout << i; return 0; } } }
#include <bits/stdc++.h> using namespace std; #define INF 2000000000 typedef long long ll; ll n, w, val[200], weight[200], dp[100010][200]; ll f(ll cur_val, ll cur_i) { // cout << "inside with: " << cur_val << " " << cur_i << endl; if (cur_val < 0) { // cout << "negative!" << endl; return INF; } if (dp[cur_val][cur_i] != -1) { // cout << "already: " << dp[cur_val][cur_i] << endl; return dp[cur_val][cur_i]; } if (cur_i == n) { if (cur_val == 0) { // cout << "returning 0" << endl; return 0; } else { // cout << "returning INF" << endl; return INF; } } dp[cur_val][cur_i] = min(f(cur_val, cur_i + 1), f(cur_val - val[cur_i], cur_i + 1) + weight[cur_i]); return dp[cur_val][cur_i]; } int main() { for (ll i = 0; i < 100001; i++) { for (ll j = 0; j < 200; j++) { dp[i][j] = -1; } } cin >> n >> w; for (ll i = 0; i < n; i++) { cin >> weight[i] >> val[i]; } // cout << " " << endl; // return 0; /* for(ll i = 0; i < 100001; i++){ for(ll j = 0; j < 200; j++){ cout << dp[i][j] << " "; } cout << endl; } */ for (ll i = 100000; i >= 0; i--) { // cout << "outside with: " << i << endl; if (f(i, 0) <= w) { cout << i; return 0; } } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
971,073
971,074
u509794431
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define INF 2000000000 typedef long long ll; ll n, w, val[200], weight[200], dp[100010][200]; ll f(ll cur_val, ll cur_i) { // cout << "inside with: " << cur_val << " " << cur_i << endl; if (cur_val < 0) { // cout << "negative!" << endl; return INF; } if (dp[cur_val][cur_i] != -1) { // cout << "already: " << dp[cur_val][cur_i] << endl; return dp[cur_val][cur_i]; } if (cur_i == n) { if (cur_val == 0) { // cout << "returning 0" << endl; return 0; } else { // cout << "returning INF" << endl; return INF; } } dp[cur_val][cur_i] = min(f(cur_val, cur_i + 1), f(cur_val - val[cur_i], cur_i + 1) + weight[cur_i]); return dp[cur_val][cur_i]; } int main() { for (ll i = 0; i < 100001; i++) { for (ll j = 0; j < 200; j++) { dp[i][j] = -1; } } cin >> n >> w; for (ll i = 0; i < n; i++) { cin >> weight[i] >> val[i]; } // cout << " " << endl; // return 0; for (ll i = 100; i >= 0; i--) { // cout << "outside with: " << i << endl; if (f(i, 0) <= w) { cout << i; return 0; } } }
#include <bits/stdc++.h> using namespace std; #define INF 2000000000 typedef long long ll; ll n, w, val[200], weight[200], dp[100010][200]; ll f(ll cur_val, ll cur_i) { // cout << "inside with: " << cur_val << " " << cur_i << endl; if (cur_val < 0) { // cout << "negative!" << endl; return INF; } if (dp[cur_val][cur_i] != -1) { // cout << "already: " << dp[cur_val][cur_i] << endl; return dp[cur_val][cur_i]; } if (cur_i == n) { if (cur_val == 0) { // cout << "returning 0" << endl; return 0; } else { // cout << "returning INF" << endl; return INF; } } dp[cur_val][cur_i] = min(f(cur_val, cur_i + 1), f(cur_val - val[cur_i], cur_i + 1) + weight[cur_i]); return dp[cur_val][cur_i]; } int main() { for (ll i = 0; i < 100001; i++) { for (ll j = 0; j < 200; j++) { dp[i][j] = -1; } } cin >> n >> w; for (ll i = 0; i < n; i++) { cin >> weight[i] >> val[i]; } // cout << " " << endl; // return 0; /* for(ll i = 0; i < 100001; i++){ for(ll j = 0; j < 200; j++){ cout << dp[i][j] << " "; } cout << endl; } */ for (ll i = 100000; i >= 0; i--) { // cout << "outside with: " << i << endl; if (f(i, 0) <= w) { cout << i; return 0; } } }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
971,075
971,074
u509794431
cpp
p03164
#include <iostream> #include <vector> using namespace std; constexpr auto INF = 100000000; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector<int> weight(N); vector<int> value(N); for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; vector<vector<long long>> dp(110, vector<long long>(100010, INF)); dp[0][0] = 0; for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < 100010; ++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]); } } long long ans = 0; for (int sum_v = 0; sum_v < 100010; ++sum_v) { if (dp[N][sum_v] <= W) ans = sum_v; } cout << ans << endl; return 0; }
#include <iostream> #include <vector> using namespace std; constexpr auto INF = 100000000001; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector<int> weight(N); vector<int> value(N); for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; vector<vector<long long>> dp(110, vector<long long>(100010, INF)); dp[0][0] = 0; for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < 100010; ++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]); } } long long ans = 0; for (int sum_v = 0; sum_v < 100010; ++sum_v) { if (dp[N][sum_v] <= W) ans = sum_v; } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
971,078
971,079
u616522759
cpp
p03164
#include <bits/stdc++.h> using namespace std; int const maxsize = 100005; int weight[maxsize], cost[maxsize]; long long int dp[103][maxsize]; int main() { int n, w; cin >> n >> w; for (int x = 1; x <= n; x++) cin >> weight[x] >> cost[x]; memset(dp, 63, sizeof(dp)); int ans = 0; // for(int x=0;x<=100000;x++) dp[0][x] = 0; // for(int x=0;x<=100;x++) dp[x][0] = 0; dp[0][0] = 0; for (int x = 1; x <= n; x++) { for (int i = 0; i < maxsize; i++) { dp[x][i] = dp[x - 1][i]; if (i - cost[x - 1] >= 0) { dp[x][i] = min(dp[x][i], dp[x - 1][i - cost[x]] + weight[x]); } // dp[x][i] = min(d, dp[x][i]); } } for (int x = 0; x < maxsize; x++) if (dp[n][x] <= w) ans = max(ans, x); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int const maxsize = 100005; int weight[maxsize], cost[maxsize]; long long int dp[103][maxsize]; int main() { int n, w; cin >> n >> w; for (int x = 1; x <= n; x++) cin >> weight[x] >> cost[x]; memset(dp, 63, sizeof(dp)); int ans = 0; // for(int x=0;x<=100000;x++) dp[0][x] = 0; // for(int x=0;x<=100;x++) dp[x][0] = 0; dp[0][0] = 0; for (int x = 1; x <= n; x++) { for (int i = 0; i < maxsize; i++) { dp[x][i] = dp[x - 1][i]; if (i - cost[x] >= 0) { dp[x][i] = min(dp[x - 1][i], dp[x - 1][i - cost[x]] + weight[x]); } // dp[x][i] = min(d, dp[x][i]); } } for (int x = 0; x < maxsize; x++) if (dp[n][x] <= w) ans = max(ans, x); cout << ans; return 0; }
[ "control_flow.loop.for.condition.change", "expression.operation.binary.remove", "assignment.change" ]
971,083
971,084
u426169581
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, w; cin >> n >> w; vector<ll> weight(n), value(n); int sumvalue = 0; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; sumvalue += value[i]; } vector<ll> dp(sumvalue, INF); // dp[i] = the minimum total weight of items with total value exactly equal to // i dp[0] = 0; for (int i = 0; i < n; i++) { for (ll curval = sumvalue - value[i]; curval >= 0; --curval) { dp[curval + value[i]] = min(dp[curval + value[i]], dp[curval] + weight[i]); } } ll ans = 0; for (int i = 0; i <= sumvalue; i++) { if (dp[i] <= w) { ans = max(ans, 1LL * i); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, w; cin >> n >> w; vector<ll> weight(n), value(n); int sumvalue = 0; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; sumvalue += value[i]; } vector<ll> dp(sumvalue + 1, INF); // dp[i] = the minimum total weight of items with total value exactly equal to // i dp[0] = 0; for (int i = 0; i < n; i++) { for (ll curval = sumvalue - value[i]; curval >= 0; --curval) { dp[curval + value[i]] = min(dp[curval + value[i]], dp[curval] + weight[i]); } } ll ans = 0; for (int i = 0; i <= sumvalue; i++) { if (dp[i] <= w) { ans = max(ans, 1LL * i); } } cout << ans << endl; return 0; }
[ "assignment.change" ]
971,105
971,106
u288989709
cpp
p03163
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> weight(N), value(N); for (int i = 0; i < N; ++i) { cin >> weight[i] >> value[i]; } vector<int> dp(W + 1); for (int i = 0; i < N; ++i) { for (int j = W; j >= weight[i]; --j) { dp[j] = max(dp[j], dp[j - weight[i]] + value[i]); } } cout << dp[W] << '\n'; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int N, W; cin >> N >> W; vector<int> weight(N), value(N); for (int i = 0; i < N; ++i) { cin >> weight[i] >> value[i]; } vector<long long> dp(W + 1); for (int i = 0; i < N; ++i) { for (int j = W; j >= weight[i]; --j) { dp[j] = max(dp[j], dp[j - weight[i]] + value[i]); } } cout << dp[W] << '\n'; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
971,123
971,124
u837745858
cpp
p03163
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> #define ff first #define ss second #define pb push_back #define mp make_pair #define len(s) s.length() #define forp(i, a, b) for (i = a; i <= b; i++) #define rep(i, n) for (i = 0; i < n; i++) #define ren(i, n) for (i = n - 1; i >= 0; i--) #define forn(i, a, b) for (i = a; i >= b; i--) #define all(v) v.begin(), v.end() #define b(v) v.begin() #define e(v) v.end() #define mem(n, m) memset(n, m, sizeof(n)) #define lb lower_bound #define ub upper_bound #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<int> #define vll vector<long long> #define gl(cin, s) getline(cin, s); #define bitc(n) __builtin_popcountll(n) #define present(s, x) (s.find(x) != s.end()) #define cpresent(s, x) (find(all(s), x) != s.end()) #define tr(container, it) \ for (__typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define boost ios_base::sync_with_stdio(0) #define MOD 1000000007 #define EPSILON 1e-9 #define PI 3.14159265358979323846 #define SIZE 100001 #define SZ 101 typedef long long ll; typedef unsigned long long ull; typedef long double ldo; typedef double db; using namespace std; long long dp[SZ][SIZE]; int N, W; int We[SZ]; int Va[SZ]; long long func(int which, int rem) { if (which > N) return 0LL; if (dp[which][rem] != -1) return dp[which][rem]; long long fans = 0; fans = max(fans, func(which + 1, rem)); if (rem >= We[which]) ; fans = max(fans, Va[which] + func(which + 1, rem - We[which])); dp[which][rem] = fans; return fans; } int main() { /* #ifndef ONLINE_JUDGE freopen(fi, "r", stdin); #endif */ // freopen("route.in","r",stdin); // freopen("route.out","w",stdout); // cin.ignore(); // cin.clear(); boost; // cin.tie(0); // cout<<"Case "<<tt<<": "; cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> We[i] >> Va[i]; } mem(dp, -1); cout << func(1, W) << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> #define ff first #define ss second #define pb push_back #define mp make_pair #define len(s) s.length() #define forp(i, a, b) for (i = a; i <= b; i++) #define rep(i, n) for (i = 0; i < n; i++) #define ren(i, n) for (i = n - 1; i >= 0; i--) #define forn(i, a, b) for (i = a; i >= b; i--) #define all(v) v.begin(), v.end() #define b(v) v.begin() #define e(v) v.end() #define mem(n, m) memset(n, m, sizeof(n)) #define lb lower_bound #define ub upper_bound #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<int> #define vll vector<long long> #define gl(cin, s) getline(cin, s); #define bitc(n) __builtin_popcountll(n) #define present(s, x) (s.find(x) != s.end()) #define cpresent(s, x) (find(all(s), x) != s.end()) #define tr(container, it) \ for (__typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define boost ios_base::sync_with_stdio(0) #define MOD 1000000007 #define EPSILON 1e-9 #define PI 3.14159265358979323846 #define SIZE 100001 #define SZ 101 typedef long long ll; typedef unsigned long long ull; typedef long double ldo; typedef double db; using namespace std; long long dp[SZ][SIZE]; int N, W; int We[SZ]; int Va[SZ]; long long func(int which, int rem) { if (which > N) return 0LL; if (dp[which][rem] != -1) return dp[which][rem]; long long fans = 0; fans = max(fans, func(which + 1, rem)); if (rem >= We[which]) fans = max(fans, Va[which] + func(which + 1, rem - We[which])); dp[which][rem] = fans; return fans; } int main() { /* #ifndef ONLINE_JUDGE freopen(fi, "r", stdin); #endif */ // freopen("route.in","r",stdin); // freopen("route.out","w",stdout); // cin.ignore(); // cin.clear(); boost; // cin.tie(0); // cout<<"Case "<<tt<<": "; cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> We[i] >> Va[i]; } mem(dp, -1); cout << func(1, W) << endl; return 0; }
[]
971,125
971,126
u864537413
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; typedef pair<ll, ll> P; #define M 1000000007 #define F first #define S second #define PB push_back #define INF 100000000000000000 ll n, dp[105][100005], v[105], w[105], m; int main(void) { scanf("%lld%lld", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld%lld", w + i, v + i); for (int i = 1; i <= n; i++) { for (int j = m; j >= 0; j--) { if (j - w[i] >= 0) dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]); else dp[i][j] = dp[i][j - 1]; } } printf("%lld\n", dp[n][m]); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; typedef pair<ll, ll> P; #define M 1000000007 #define F first #define S second #define PB push_back #define INF 100000000000000000 ll n, dp[105][100005], v[105], w[105], m; int main(void) { scanf("%lld%lld", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld%lld", w + i, v + i); for (int i = 1; i <= n; i++) { for (int j = m; j >= 0; j--) { if (j - w[i] >= 0) dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } printf("%lld\n", dp[n][m]); }
[]
971,127
971,128
u743900647
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; typedef pair<ll, ll> P; #define M 1000000007 #define F first #define S second #define PB push_back #define INF 100000000000000000 ll n, dp[100][100005], v[105], w[105], m; int main(void) { scanf("%lld%lld", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld%lld", w + i, v + i); for (int i = 1; i <= n; i++) { for (int j = m; j >= 0; j--) { if (j - w[i] >= 0) dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]); else dp[i][j] = dp[i][j - 1]; } } printf("%lld\n", dp[n][m]); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; typedef pair<ll, ll> P; #define M 1000000007 #define F first #define S second #define PB push_back #define INF 100000000000000000 ll n, dp[105][100005], v[105], w[105], m; int main(void) { scanf("%lld%lld", &n, &m); for (int i = 1; i <= n; i++) scanf("%lld%lld", w + i, v + i); for (int i = 1; i <= n; i++) { for (int j = m; j >= 0; j--) { if (j - w[i] >= 0) dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } printf("%lld\n", dp[n][m]); }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
971,129
971,128
u743900647
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long int n, k, w[110], v[110]; ll f[100010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d%d", &w[i], &v[i]); } for (int i = 1; i <= n; i++) { for (int j = k; j >= w[i]; j--) { f[j] = max(f[j], f[i] + v[i]); } } cout << f[k] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int n, k, w[110], v[110]; ll f[100010]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%d%d", &w[i], &v[i]); } for (int i = 1; i <= n; i++) { for (int j = k; j >= w[i]; j--) { f[j] = max(f[j], f[j - w[i]] + v[i]); } } cout << f[k] << endl; return 0; }
[ "assignment.change", "call.arguments.change" ]
971,136
971,137
u195756521
cpp
p03163
#include <algorithm> #include <stdio.h> using namespace std; int N, W; long long D[100100]; int main() { scanf("%d %d", &N, &W); for (int i = 1; i <= N; i++) { int w, v; scanf("%d %d", &w, &v); for (int j = W - w; j >= 0; j--) if (D[j + w] < D[j] + v) D[j + w] = D[j] + v; } printf("%lld\n", D[N]); return 0; }
#include <algorithm> #include <stdio.h> using namespace std; int N, W; long long D[100100]; int main() { scanf("%d %d", &N, &W); for (int i = 1; i <= N; i++) { int w, v; scanf("%d %d", &w, &v); for (int j = W - w; j >= 0; j--) if (D[j + w] < D[j] + v) D[j + w] = D[j] + v; } printf("%lld\n", D[W]); return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "call.arguments.change", "io.output.change" ]
971,140
971,141
u233632872
cpp
p03163
#include <algorithm> #include <stdio.h> using namespace std; int N, W, D[100100]; int main() { scanf("%d %d", &N, &W); for (int i = 1; i <= N; i++) { int w, v; scanf("%d %d", &w, &v); for (int j = W - w; j >= 0; j--) if (D[j + w] < D[j] + v) D[j + w] = D[j] + v; } printf("%d\n", D[N]); return 0; }
#include <algorithm> #include <stdio.h> using namespace std; int N, W; long long D[100100]; int main() { scanf("%d %d", &N, &W); for (int i = 1; i <= N; i++) { int w, v; scanf("%d %d", &w, &v); for (int j = W - w; j >= 0; j--) if (D[j + w] < D[j] + v) D[j + w] = D[j] + v; } printf("%lld\n", D[W]); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change", "identifier.change", "variable_access.subscript.index.change" ]
971,142
971,141
u233632872
cpp
p03163
#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, w; cin >> n >> w; int dp[w + 1]; for (int i = 0; i <= w; i++) dp[i] = 0; for (int i = 0; i < n; i++) { int wi, v; cin >> wi >> v; for (int j = w; j >= wi; j--) dp[j] = max(dp[j], dp[j - wi] + v); } int ans = 0; for (int i = 0; i <= w; i++) ans = max(ans, dp[i]); cout << ans; return 0; }
#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, w; cin >> n >> w; long long dp[w + 1]; for (int i = 0; i <= w; i++) dp[i] = 0; for (int i = 0; i < n; i++) { int wi, v; cin >> wi >> v; for (int j = w; j >= wi; j--) dp[j] = max(dp[j], dp[j - wi] + v); } long long ans = 0; for (int i = 0; i <= w; i++) ans = max(ans, dp[i]); cout << ans; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
971,145
971,146
u538129823
cpp
p03164
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) const int MOD = 1000000007; const int INF_32 = 1LL << 30; const int64_t INF_64 = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; int N; ll W, weight[110], value[110]; // dp[i][j]はi-1番目までの品物を選ぶとき,価値の総和をj以上にするための重さの総和の最小値 ll dp[110][100100]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) cin >> weight[i] >> value[i]; for (int i = 0; i < 110; i++) { for (int j = 0; j < 100100; j++) { dp[i][j] = INF_64; } } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int sum_value = 0; sum_value <= 100100; ++sum_value) { // i番目の品物を選ぶ場合 if (sum_value - value[i] >= 0) { chmin(dp[i + 1][sum_value], dp[i][sum_value - value[i]] + weight[i]); } // i番目の品物を選ばない場合 chmin(dp[i + 1][sum_value], dp[i][sum_value]); } } int ans = 0; for (int sum_value = 0; sum_value <= 100100; ++sum_value) { if (dp[N][sum_value] <= W) { ans = sum_value; } } cout << ans << endl; }
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) const int MOD = 1000000007; const int INF_32 = 1LL << 30; const int64_t INF_64 = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } typedef long long ll; int N; ll W, weight[110], value[110]; // dp[i][j]はi-1番目までの品物を選ぶとき,価値の総和をj以上にするための重さの総和の最小値 ll dp[110][100100]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) cin >> weight[i] >> value[i]; for (int i = 0; i < 110; i++) { for (int j = 0; j < 100100; j++) { dp[i][j] = INF_64; } } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int sum_value = 0; sum_value < 100100; ++sum_value) { // i番目の品物を選ぶ場合 if (sum_value - value[i] >= 0) { chmin(dp[i + 1][sum_value], dp[i][sum_value - value[i]] + weight[i]); } // i番目の品物を選ばない場合 chmin(dp[i + 1][sum_value], dp[i][sum_value]); } } int ans = 0; for (int sum_value = 0; sum_value < 100100; ++sum_value) { if (dp[N][sum_value] <= W) { ans = sum_value; } } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,149
971,150
u715366261
cpp
p03164
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; const int N = 1e5 + 4; int n, w, W[200], V[200], dp[200][N], mx; int32_t main() { // freopen("haybales.in", "r", stdin ) ; // freopen("haybales.out", "w", stdout ) ; cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> W[i] >> V[i]; } for (int i = 0; i <= n; i++) { for (int j = 1; j < N; j++) { dp[i][j] = 1e7; } } for (int i = 1; i <= n; i++) { for (int j = 1; j < N; j++) { dp[i][j] = dp[i - 1][j]; if (V[i] <= j) { dp[i][j] = min(dp[i][j], dp[i - 1][j - V[i]] + W[i]); } } } for (int i = 1; i < N; i++) { if (dp[n][i] <= w) mx = i; } cout << mx << endl; }
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; const int N = 1e5 + 4; int n, w, W[200], V[200], dp[200][N], mx; int32_t main() { // freopen("haybales.in", "r", stdin ) ; // freopen("haybales.out", "w", stdout ) ; cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> W[i] >> V[i]; } for (int i = 0; i <= n; i++) { for (int j = 1; j < N; j++) { dp[i][j] = 1e12 + 1; } } for (int i = 1; i <= n; i++) { for (int j = 1; j < N; j++) { dp[i][j] = dp[i - 1][j]; if (V[i] <= j) { dp[i][j] = min(dp[i][j], dp[i - 1][j - V[i]] + W[i]); } } } for (int i = 1; i < N; i++) { if (dp[n][i] <= w) mx = i; } cout << mx << endl; }
[ "literal.number.change", "assignment.value.change", "assignment.change" ]
971,161
971,162
u089230684
cpp
p03164
#include <bits/stdc++.h> // freopen("transmitters.in","r",stdin); // cout<<fixed<<setprecision(6)<<n<<endl; // transform(s.begin(), s.end(), s.begin(), ::tolower); // double PI=3.14159265359,c=0; #define all(v) v.begin(), v.end() #define endl '\n' #define ll long long //#define f(n) for(int i=;i<n;i++) double PI = acos(-1); using namespace std; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ll n, arr[1000][3], vist[111][100005], v = 1e5; ll Knapsack(int i, int r) { if (r == 0) return 0; if (i >= n || r < 0) return 1e9; if (vist[i][r] != -1) return vist[i][r]; return vist[i][r] = min(Knapsack(i + 1, r), Knapsack(i + 1, r - arr[i][1]) + arr[i][0]); } int main() { fast(); int w, mx = 0; cin >> n >> w; for (int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1]; memset(vist, -1, sizeof(vist)); for (int i = 0; i < 1e5 + 2; i++) { if (Knapsack(0, i) <= w) mx = max(mx, i); } cout << mx << endl; return 0; }
#include <bits/stdc++.h> // freopen("transmitters.in","r",stdin); // cout<<fixed<<setprecision(6)<<n<<endl; // transform(s.begin(), s.end(), s.begin(), ::tolower); // double PI=3.14159265359,c=0; #define all(v) v.begin(), v.end() #define endl '\n' #define ll long long //#define f(n) for(int i=;i<n;i++) double PI = acos(-1); using namespace std; void fast() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } ll n, arr[1000][3], vist[111][100005], v = 1e5; ll Knapsack(int i, int r) { if (r == 0) return 0; if (i >= n || r < 0) return (1e9 + 2); if (vist[i][r] != -1) return vist[i][r]; return vist[i][r] = min(Knapsack(i + 1, r), Knapsack(i + 1, r - arr[i][1]) + arr[i][0]); } int main() { fast(); int w, mx = 0; cin >> n >> w; for (int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1]; memset(vist, -1, sizeof(vist)); for (int i = 0; i < 1e5 + 2; i++) { if (Knapsack(0, i) <= w) mx = max(mx, i); } cout << mx << endl; return 0; }
[ "function.return_value.change" ]
971,165
971,166
u089230684
cpp
p03164
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define rep(i, n) for (int i = 0; i < n; i++) #define NIL = -1; ll gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { a / gcd(a, b) * b; } const ll mod = 1e9 + 7; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; const ll INF = 1e9; ///////////////////////////////////////////////////////////////////////////////////////// int main() { int n, w; cin >> n >> w; vector<vector<int>> dp(n + 1, vector<int>(100001, INF)); dp[0][0] = 0; vector<int> W(n + 1), V(n + 1); for (int i = 1; i <= n; i++) { cin >> W[i] >> V[i]; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= 100000; j++) { 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]; } } ll ans = 100000; while (dp[n][ans] > w) ans--; cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define rep(i, n) for (int i = 0; i < n; i++) #define NIL = -1; ll gcd(long long a, long long b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { a / gcd(a, b) * b; } const ll mod = 1e9 + 7; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; const ll INF = 1e9; ///////////////////////////////////////////////////////////////////////////////////////// int main() { int n, w; cin >> n >> w; vector<vector<int>> dp(n + 1, vector<int>(100001, INF + 7)); dp[0][0] = 0; vector<int> W(n + 1), V(n + 1); for (int i = 1; i <= n; i++) { cin >> W[i] >> V[i]; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= 100000; j++) { 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]; } } ll ans = 100000; while (dp[n][ans] > w) ans--; cout << ans << endl; }
[ "assignment.change" ]
971,169
971,170
u111600809
cpp
p03164
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define init \ ios::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define setpr(x) cout << setprecision((x)) #define PI atan(1) * 4 #define fi first #define se second #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define mk(a, b) \ { min((a), (b)), max((a), (b)) } #define flush cout.flush() #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define endc "\n" #define MOD 998244353 #define meme(x) memset((x), 0, sizeof((x))) #define memo(x) memset((x), -1, sizeof((x))) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; // #define int ll ll egcd(ll a, ll b, ll &x, ll &y) { if (a == 0LL) { x = 0LL; y = 1LL; return b; } ll xx, yy; ll val = egcd(b % a, a, xx, yy); x = yy - (b / a) * xx; y = xx; return val; } ll gcd(ll a, ll b) { while (true) { if (a > b) swap(a, b); if (a == 0) return b; ll p = b % a, q = a; a = p; b = q; } } ll powerMod(ll x, ll y) { ll res = 1; x %= MOD; while (y > 0) { if (y & 1) res = (res * x) % MOD; y = y >> 1; x = (x * x) % MOD; } return res % MOD; } // ========== //\\ //|| ||====//|| // || // \\ || || // || // || //====\\ || || // || // || // \\ || || // || // ========== // \\ ======== ||//====|| // code void solve() { ll n, i, j, k, l, p, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>(100001, INT_MAX)); vector<ll> weights(n), values(n); for (i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } dp[0][0] = 0LL; for (i = 0; i < n; i++) { for (j = 0; j < 201; j++) { dp[i + 1][j] = dp[i][j]; if (j >= values[i]) { if (dp[i][j - values[i]] + weights[i] <= w) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - values[i]] + weights[i]); } } } } p = 0; for (i = 0; i < 100001; i++) { if (dp[n][i] <= w) { p = i; } } cout << p << endc; } int32_t main() { init; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define init \ ios::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define setpr(x) cout << setprecision((x)) #define PI atan(1) * 4 #define fi first #define se second #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define mk(a, b) \ { min((a), (b)), max((a), (b)) } #define flush cout.flush() #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define endc "\n" #define MOD 998244353 #define meme(x) memset((x), 0, sizeof((x))) #define memo(x) memset((x), -1, sizeof((x))) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; // #define int ll ll egcd(ll a, ll b, ll &x, ll &y) { if (a == 0LL) { x = 0LL; y = 1LL; return b; } ll xx, yy; ll val = egcd(b % a, a, xx, yy); x = yy - (b / a) * xx; y = xx; return val; } ll gcd(ll a, ll b) { while (true) { if (a > b) swap(a, b); if (a == 0) return b; ll p = b % a, q = a; a = p; b = q; } } ll powerMod(ll x, ll y) { ll res = 1; x %= MOD; while (y > 0) { if (y & 1) res = (res * x) % MOD; y = y >> 1; x = (x * x) % MOD; } return res % MOD; } // ========== //\\ //|| ||====//|| // || // \\ || || // || // || //====\\ || || // || // || // \\ || || // || // ========== // \\ ======== ||//====|| // code void solve() { ll n, i, j, k, l, p, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>(100001, INT_MAX)); vector<ll> weights(n), values(n); for (i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } dp[0][0] = 0LL; for (i = 0; i < n; i++) { for (j = 0; j < 100001; j++) { dp[i + 1][j] = dp[i][j]; if (j >= values[i]) { if (dp[i][j - values[i]] + weights[i] <= w) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - values[i]] + weights[i]); } } } } p = 0; for (i = 0; i < 100001; i++) { if (dp[n][i] <= w) { p = i; } } cout << p << endc; } int32_t main() { init; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,194
971,195
u771710924
cpp
p03164
// https://atcoder.jp/contests/dp/tasks/dp_e #include <bits/stdc++.h> using namespace std; #define ll long long int typedef vector<ll> vi; typedef vector<vi> vii; #define rep(i, k, n) for (ll i = k; i < (int)(n); i++) int main() { ll n, w; ll ans; cin >> n >> w; vi ws(n + 1); vi vs(n + 1); ll totalVal = 0; rep(i, 1, n + 1) { cin >> ws[i] >> vs[i]; totalVal += vs[i]; } vii dp(n + 1, vi(totalVal + 1)); // dp[i][j] denotes the least weight to get a value of j from the first i // objects dp[0][0] = 0; int INF = w + 1; rep(V, 1, totalVal + 1) dp[0][V] = INF; // arbitary large num thats impossible rep(N, 1, n + 1) { rep(V, 0, totalVal + 1) { dp[N][V] = (V < vs[N]) ? dp[N - 1][V] : min(dp[N - 1][V], dp[N - 1][V - vs[N]] + ws[N]); if (dp[N][V] <= w) { ans = max(ans, (ll)V); } } } cout << ans << endl; }
// https://atcoder.jp/contests/dp/tasks/dp_e #include <bits/stdc++.h> using namespace std; #define ll long long int typedef vector<ll> vi; typedef vector<vi> vii; #define rep(i, k, n) for (ll i = k; i < (int)(n); i++) int main() { ll n, w; ll ans = 0; cin >> n >> w; vi ws(n + 1); vi vs(n + 1); ll totalVal = 0; rep(i, 1, n + 1) { cin >> ws[i] >> vs[i]; totalVal += vs[i]; } vii dp(n + 1, vi(totalVal + 1)); // dp[i][j] denotes the least weight to get a value of j from the first i // objects dp[0][0] = 0; int INF = w + 1; rep(V, 1, totalVal + 1) dp[0][V] = INF; // arbitary large num thats impossible rep(N, 1, n + 1) { rep(V, 1, totalVal + 1) { dp[N][V] = (V < vs[N]) ? dp[N - 1][V] : min(dp[N - 1][V], dp[N - 1][V - vs[N]] + ws[N]); if (dp[N][V] <= w) { ans = max(ans, (ll)V); } } } cout << ans << endl; }
[ "variable_declaration.value.change", "literal.number.change", "call.arguments.change" ]
971,215
971,216
u657818166
cpp
p03164
// https://atcoder.jp/contests/dp/tasks/dp_e #include <bits/stdc++.h> using namespace std; #define ll long long int typedef vector<ll> vi; typedef vector<vi> vii; #define rep(i, k, n) for (ll i = k; i < (int)(n); i++) int main() { ll n, w; ll ans; cin >> n >> w; vi ws(n + 1); vi vs(n + 1); ll totalVal = 0; rep(i, 1, n + 1) { cin >> ws[i] >> vs[i]; totalVal += vs[i]; } vii dp(n + 1, vi(totalVal + 1)); // dp[i][j] denotes the least weight to get a value of j from the first i // objects dp[0][0] = 0; int INF = w + 1; rep(V, 1, totalVal + 1) dp[0][V] = INF; // arbitary large num thats impossible rep(N, 1, n + 1) { rep(V, 0, totalVal + 1) { dp[N][V] = (V < vs[N]) ? dp[N - 1][V] : min(dp[N - 1][V], dp[N - 1][V - vs[N]] + ws[N]); if (dp[N][V] <= w) { ans = max(ans, (ll)V); } } } cout << ans << endl; }
// https://atcoder.jp/contests/dp/tasks/dp_e #include <bits/stdc++.h> using namespace std; #define ll long long int typedef vector<ll> vi; typedef vector<vi> vii; #define rep(i, k, n) for (ll i = k; i < (int)(n); i++) int main() { ll n, w; ll ans = 0; cin >> n >> w; vi ws(n + 1); vi vs(n + 1); ll totalVal = 0; rep(i, 1, n + 1) { cin >> ws[i] >> vs[i]; totalVal += vs[i]; } vii dp(n + 1, vi(totalVal + 1)); // dp[i][j] denotes the least weight to get a value of j from the first i // objects dp[0][0] = 0; int INF = w + 1; rep(V, 1, totalVal + 1) dp[0][V] = INF; // arbitary large num thats impossible rep(N, 1, n + 1) { rep(V, 0, totalVal + 1) { dp[N][V] = (V < vs[N]) ? dp[N - 1][V] : min(dp[N - 1][V], dp[N - 1][V - vs[N]] + ws[N]); if (dp[N][V] <= w) { ans = max(ans, (ll)V); } } } cout << ans << endl; }
[ "variable_declaration.value.change" ]
971,215
971,217
u657818166
cpp
p03164
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <numeric> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; using ll = long long int; constexpr int INF = 1 << 29; constexpr ll MOD = ll(1e9 + 7); constexpr int vmax = 1000; int n; ll W; vector<ll> w; vector<int> v; vector<vector<ll>> dp; int main(void) { cin >> n >> W; w = vector<ll>(n + 1, 0); v = vector<int>(n + 1, 0); for (int i = 1; i < n + 1; i++) cin >> w[i] >> v[i]; dp = vector<vector<ll>>(n + 1, vector<ll>(n * vmax + 1, INF)); dp[0][0] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < n * vmax + 1; 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]; } } int ret = n * vmax; while (dp[n][ret] > W) ret--; cout << ret << endl; return 0; }
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <numeric> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; using ll = long long int; constexpr int INF = 1 << 30; constexpr ll MOD = ll(1e9 + 7); constexpr int vmax = 1000; int n; ll W; vector<ll> w; vector<int> v; vector<vector<ll>> dp; int main(void) { cin >> n >> W; w = vector<ll>(n + 1, 0); v = vector<int>(n + 1, 0); for (int i = 1; i < n + 1; i++) cin >> w[i] >> v[i]; dp = vector<vector<ll>>(n + 1, vector<ll>(n * vmax + 1, INF)); dp[0][0] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < n * vmax + 1; 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]; } } int ret = n * vmax; while (dp[n][ret] > W) ret--; cout << ret << endl; return 0; }
[ "literal.number.change", "expression.operation.binary.change" ]
971,222
971,223
u728082661
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define pb push_back #define mk make_pair #define pii pair<int, int> #define vi vector<int> #define all(x) (x).begin(), (x).end() #define umap unordered_map #define uset unordered_set #define mod 1000000007 #define imax INT_MAX #define imin INT_MIN #define exp 1e9 #define sz(x) (int((x).size())) #define int long long struct item { int wt; int val; }; int solve(vector<item> ar, int n, int W) { int maxVal = n * 1000; int dp[n + 1][maxVal + 1]; for (int val = 0; val <= maxVal; val++) { dp[0][val] = imax; } for (int i = 0; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= n; i++) { for (int v = 0; v <= 20; v++) { dp[i][v] = dp[i - 1][v]; if (ar[i].val > v) { continue; } dp[i][v] = min(dp[i][v], ar[i].wt + dp[i - 1][v - ar[i].val]); // cout<<dp[i-1][v-ar[i].val]+ar[i].wt<<" "; } // cout<<"\n"; } /* for(int i=1;i<=n;i++) { for(int j=0;j<18;j++) { cout<<dp[i][j]<<" "; } cout<<"\n"; }*/ int ans = 0; for (int val = 0; val <= maxVal; val++) { if (dp[n][val] <= W) { ans = val; } } return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; vector<item> v(n + 1); for (int i = 1; i <= n; i++) { cin >> v[i].wt >> v[i].val; } cout << solve(v, n, w); return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define pb push_back #define mk make_pair #define pii pair<int, int> #define vi vector<int> #define all(x) (x).begin(), (x).end() #define umap unordered_map #define uset unordered_set #define mod 1000000007 #define imax INT_MAX #define imin INT_MIN #define exp 1e9 #define sz(x) (int((x).size())) #define int long long struct item { int wt; int val; }; int solve(vector<item> ar, int n, int W) { int maxVal = n * 1000; int dp[n + 1][maxVal + 1]; for (int val = 0; val <= maxVal; val++) { dp[0][val] = imax; } for (int i = 0; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= n; i++) { for (int v = 0; v <= maxVal; v++) { dp[i][v] = dp[i - 1][v]; if (ar[i].val > v) { continue; } dp[i][v] = min(dp[i][v], ar[i].wt + dp[i - 1][v - ar[i].val]); // cout<<dp[i-1][v-ar[i].val]+ar[i].wt<<" "; } // cout<<"\n"; } /* for(int i=1;i<=n;i++) { for(int j=0;j<18;j++) { cout<<dp[i][j]<<" "; } cout<<"\n"; }*/ int ans = 0; for (int val = 0; val <= maxVal; val++) { if (dp[n][val] <= W) { ans = val; } } return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; vector<item> v(n + 1); for (int i = 1; i <= n; i++) { cin >> v[i].wt >> v[i].val; } cout << solve(v, n, w); return 0; }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,231
971,232
u157659681
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; struct item { // weight, value ll w = 0, v = 0; item(ll a = 0, ll b = 0) { w = a; v = b; } }; const ll INF = 1e15; ll n, cap; vector<item> items; bool cached[100][100000]; ll memo[100][100000]; ll knap(ll i, ll sum) { if (sum < 0) return INF; if (sum == 0) return 0LL; if (i == n) return INF; if (cached[i][sum]) return memo[i][sum]; ll res1 = knap(i + 1, sum - items[i].v) + items[i].w; ll res2 = knap(i + 1, sum); ll res = min(res1, res2); cached[i][sum] = true; memo[i][sum] = res; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> cap; items = vector<item>(n); for (int i = 0; i < n; i++) { ll w, v; cin >> w >> v; items[i] = item(w, v); } for (ll i = 100000; i >= 1; i--) { ll reqcap = knap(0, i); if (reqcap <= cap) { cout << i; break; } } }
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; struct item { // weight, value ll w = 0, v = 0; item(ll a = 0, ll b = 0) { w = a; v = b; } }; const ll INF = 1e15; ll n, cap; vector<item> items; bool cached[100][100001]; ll memo[100][100001]; ll knap(ll i, ll sum) { if (sum < 0) return INF; if (sum == 0) return 0LL; if (i == n) return INF; if (cached[i][sum]) return memo[i][sum]; ll res1 = knap(i + 1, sum - items[i].v) + items[i].w; ll res2 = knap(i + 1, sum); ll res = min(res1, res2); cached[i][sum] = true; memo[i][sum] = res; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> cap; items = vector<item>(n); for (int i = 0; i < n; i++) { ll w, v; cin >> w >> v; items[i] = item(w, v); } for (ll i = 100000; i >= 0; i--) { ll reqcap = knap(0, i); if (reqcap <= cap) { cout << i; break; } } }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,241
971,240
u281053019
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; struct item { // weight, value ll w = 0, v = 0; item(ll a = 0, ll b = 0) { w = a; v = b; } }; const ll INF = 1e15; ll n, cap; vector<item> items; bool cached[100][100000]; ll memo[100][100000]; ll knap(int i, ll sum) { if (sum < 0) return INF; if (sum == 0) return 0LL; if (i == n) return INF; if (cached[i][sum]) return memo[i][sum]; ll res1 = knap(i + 1, sum - items[i].v) + items[i].w; ll res2 = knap(i + 1, sum); ll res = min(res1, res2); cached[i][sum] = true; memo[i][sum] = res; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> cap; items = vector<item>(n); for (int i = 0; i < n; i++) { ll w, v; cin >> w >> v; items[i] = item(w, v); } for (int i = 100000; i >= 1; i--) { ll reqcap = knap(0, i); if (reqcap <= cap) { cout << i; break; } } }
#include <bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; struct item { // weight, value ll w = 0, v = 0; item(ll a = 0, ll b = 0) { w = a; v = b; } }; const ll INF = 1e15; ll n, cap; vector<item> items; bool cached[100][100001]; ll memo[100][100001]; ll knap(ll i, ll sum) { if (sum < 0) return INF; if (sum == 0) return 0LL; if (i == n) return INF; if (cached[i][sum]) return memo[i][sum]; ll res1 = knap(i + 1, sum - items[i].v) + items[i].w; ll res2 = knap(i + 1, sum); ll res = min(res1, res2); cached[i][sum] = true; memo[i][sum] = res; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> cap; items = vector<item>(n); for (int i = 0; i < n; i++) { ll w, v; cin >> w >> v; items[i] = item(w, v); } for (ll i = 100000; i >= 0; i--) { ll reqcap = knap(0, i); if (reqcap <= cap) { cout << i; break; } } }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,242
971,240
u281053019
cpp
p03164
#include <bits/stdc++.h> #include <iostream> #include <string> #define ll long long int #define pb push_back #define mp make_pair #define fi first #define se second #define phi 3.1415926535 #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl '\n' using namespace std; const ll mod = 1000000007; ll tc, cnt = 0, number, many, total = 0, query; // vector <vector <int> > adjList; int rmove[8] = {-1, 0, 1, 0, -1, 1, -1, 1}; int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1}; ll power(ll x, ll y, ll mod) { if (y == 0) return 1; else if (y % 2 == 0) return (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod; else return x * (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod; } ll dp[100 + 5][100000 + 5], answer = 0; int main() { fastio(); // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // g++ -std=c++11 Default.cpp -o test // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp -o test cin >> many >> number; pair<ll, ll> arr[many]; ll sum = 0; for (int i = 0; i < many; i++) { cin >> arr[i].fi >> arr[i].se; sum += arr[i].se; } memset(dp, 0, sizeof(dp)); for (int i = 0; i <= 100000; i++) dp[0][i] = 1e9; ll answer = 0; for (int i = 1; i <= many; i++) { for (int j = 0; j <= 100000; j++) { dp[i][j] = dp[i - 1][j]; if (j - arr[i - 1].se >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - arr[i - 1].se] + arr[i - 1].fi); if (j <= arr[i - 1].se) dp[i][j] = min(dp[i][j], arr[i - 1].fi); if (dp[i][j] <= number) answer = max(answer, j * 1LL); } } cout << answer << endl; // return 0; }
#include <bits/stdc++.h> #include <iostream> #include <string> #define ll long long int #define pb push_back #define mp make_pair #define fi first #define se second #define phi 3.1415926535 #define fastio() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl '\n' using namespace std; const ll mod = 1000000007; ll tc, cnt = 0, number, many, total = 0, query; // vector <vector <int> > adjList; int rmove[8] = {-1, 0, 1, 0, -1, 1, -1, 1}; int cmove[8] = {0, 1, 0, -1, 1, -1, -1, 1}; ll power(ll x, ll y, ll mod) { if (y == 0) return 1; else if (y % 2 == 0) return (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod; else return x * (power(x, y / 2, mod) % mod * power(x, y / 2, mod) % mod) % mod; } ll dp[100 + 5][100000 + 5], answer = 0; int main() { fastio(); // freopen("input.txt","r", stdin); // freopen("output.txt","w", stdout); // g++ -std=c++11 Default.cpp -o test // g++ -Wl,--stack=268435456 -std=c++11 Default.cpp -o test cin >> many >> number; pair<ll, ll> arr[many]; ll sum = 0; for (int i = 0; i < many; i++) { cin >> arr[i].fi >> arr[i].se; sum += arr[i].se; } memset(dp, 0, sizeof(dp)); for (int i = 0; i <= 100000; i++) dp[0][i] = 1e14; ll answer = 0; for (int i = 1; i <= many; i++) { for (int j = 0; j <= 100000; j++) { dp[i][j] = dp[i - 1][j]; if (j - arr[i - 1].se >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - arr[i - 1].se] + arr[i - 1].fi); if (j <= arr[i - 1].se) dp[i][j] = min(dp[i][j], arr[i - 1].fi); if (dp[i][j] <= number) answer = max(answer, j * 1LL); } } cout << answer << endl; // return 0; }
[ "literal.number.change", "assignment.value.change" ]
971,263
971,264
u252292568
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define all(c) c.begin(), c.end() #define REP(i, a, b) for (int i = a; i <= b; ++i) #define tr(container, it) \ for (auto it = container.begin(); it != container.end(); ++it) typedef long long ll; typedef vector<int> vi; #define mod 1000000007 int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // ios::sync_with_stdio(0); // cin.tie(0); ll n, w; cin >> n >> w; vi a(n), b(n); for (ll i = 0; i < n; ++i) cin >> a[i] >> b[i]; ll sum_value = accumulate(all(b), 0); vector<ll> dp(sum_value + 1, 1e18 + 5); dp[0] = 0; for (int i = 0; i < n; ++i) { for (int value_taken = sum_value - b[i]; value_taken >= 0; --value_taken) { dp[value_taken + b[i]] = min(dp[value_taken + b[i]], dp[value_taken] + a[i]); } } ll best = 0; for (int i = 0; i < sum_value; ++i) if (dp[i] <= w) best = max(best, (ll)i); cout << best; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(c) c.begin(), c.end() #define REP(i, a, b) for (int i = a; i <= b; ++i) #define tr(container, it) \ for (auto it = container.begin(); it != container.end(); ++it) typedef long long ll; typedef vector<int> vi; #define mod 1000000007 int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // ios::sync_with_stdio(0); // cin.tie(0); ll n, w; cin >> n >> w; vi a(n), b(n); for (ll i = 0; i < n; ++i) cin >> a[i] >> b[i]; ll sum_value = accumulate(all(b), 0); vector<ll> dp(sum_value + 1, 1e18 + 5); dp[0] = 0; for (int i = 0; i < n; ++i) { for (int value_taken = sum_value - b[i]; value_taken >= 0; --value_taken) { dp[value_taken + b[i]] = min(dp[value_taken + b[i]], dp[value_taken] + a[i]); } } ll best = 0; for (int i = 0; i <= sum_value; ++i) if (dp[i] <= w) best = max(best, (ll)i); cout << best; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,276
971,277
u488777116
cpp
p03164
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <vector> #define ll long long int #define mp make_pair #define pb push_back #define vi vector<int> using namespace std; struct objects { int weight, value; }; ll solve() { int n, w; cin >> n >> w; objects object[n]; int totalvalue = 0; for (int i = 0; i < n; i++) { cin >> object[i].weight >> object[i].value; totalvalue += object[i].value; } ll dp[totalvalue + 1]; dp[0] = 0; int ans = 0; for (int i = 1; i <= totalvalue; i++) { dp[i] = 1e18; } for (int i = 0; i < n; i++) { for (int j = totalvalue; j >= 0; j--) { if (j >= object[i].value) { dp[j] = min(dp[j], dp[j - object[i].value] + object[i].weight); } if (dp[j] <= w) { ans = max(ans, j); break; } } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; cout << solve(); }
#include <bits/stdc++.h> #include <cmath> #include <iostream> #include <vector> #define ll long long int #define mp make_pair #define pb push_back #define vi vector<int> using namespace std; struct objects { int weight, value; }; ll solve() { int n, w; cin >> n >> w; objects object[n]; int totalvalue = 0; for (int i = 0; i < n; i++) { cin >> object[i].weight >> object[i].value; totalvalue += object[i].value; } ll dp[totalvalue + 1]; dp[0] = 0; int ans = 0; for (int i = 1; i <= totalvalue; i++) { dp[i] = 1e18; } for (int i = 0; i < n; i++) { for (int j = totalvalue; j >= 0; j--) { if (j >= object[i].value) { dp[j] = min(dp[j], dp[j - object[i].value] + object[i].weight); } if (dp[j] <= w) { ans = max(ans, j); } } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; cout << solve(); }
[]
971,284
971,285
u422679050
cpp
p03164
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, even when nobody else believes they can come true but you. These are not cliches but real tools you need no matter what you do in life to stay focused on your path. */ /*Pppppppp UU UU CCCCCCCC CCCCCCCC HH HH UU UU pp pp UU UU CC CC HH HH UU UU pp pp UU UU CC CC HHHHHHHHH UU UU pppppppp UU UU CC CC HHHHHHHHH UU UU pp UU UU CC CC HH HH UU UU pp UUUUUUUUUU CCCCCCCC CCCCCCCC HH HH UUUUUUUUUU */ #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; long wt; cin >> n >> wt; int v[n], w[n]; long maxv = 100000; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; long long dp[n + 1][maxv + 10]; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < maxv + 1; j++) dp[i][j] = 1000000000; } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < maxv + 1; j++) { if (dp[i][j] == 1000000000) continue; else { dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]); dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } } for (int i = maxv; i >= 0; i--) { if (dp[n][i] <= wt) { cout << i; return 0; } } cout << 0 << endl; return 0; }
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, even when nobody else believes they can come true but you. These are not cliches but real tools you need no matter what you do in life to stay focused on your path. */ /*Pppppppp UU UU CCCCCCCC CCCCCCCC HH HH UU UU pp pp UU UU CC CC HH HH UU UU pp pp UU UU CC CC HHHHHHHHH UU UU pppppppp UU UU CC CC HHHHHHHHH UU UU pp UU UU CC CC HH HH UU UU pp UUUUUUUUUU CCCCCCCC CCCCCCCC HH HH UUUUUUUUUU */ #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; long wt; cin >> n >> wt; int v[n], w[n]; long maxv = 100000; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; long long dp[n + 1][maxv + 10]; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < maxv + 1; j++) dp[i][j] = 1000000001; } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < maxv + 1; j++) { if (dp[i][j] == 1000000001) continue; else { dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]); dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } } for (int i = maxv; i >= 0; i--) { if (dp[n][i] <= wt) { cout << i; return 0; } } cout << 0 << endl; return 0; }
[ "literal.number.change", "assignment.value.change", "control_flow.branch.if.condition.change" ]
971,300
971,301
u985702351
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define pqi priority_queue<int> #define pb push_back() #define INF 1000000000000000000 #define float long double #define pi acos(-1) const int modu = (1e9) + 7; void testCase(int ti) { cout << "Case " << ti << ": "; } int bigmod(int n, int p) { if (p == 0) return 1; int x = bigmod(n, p / 2) % modu; x = (x * x) % modu; if (p % 2) return (x * n) % modu; return x; } int modInverse(int a) { return bigmod(a, modu - 2) % modu; } void debug(string pr, vector<int> var, bool out = true) { #ifdef OFFLINE ofstream fl; fl.open("debug.txt"); fl << pr; for (int i = 0; i < var.size(); i++) fl << " " << var[i]; fl << endl; fl.close(); if (out) { cout << pr; for (int i = 0; i < var.size(); i++) cout << " " << var[i]; cout << endl; } #endif } void faster() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); } void defInit() { faster(); #ifdef OFFLINE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int add(int x, int y) { int z = (x % modu + y % modu) % modu; while (z < 0) z = (z + modu) % modu; return z; } int mul(int x, int y) { int z = (x % modu * y % modu) % modu; while (z < 0) z = (z + modu) % modu; return z; } // starts here int32_t main() { defInit(); // Now I will start writing codes and start preparation to get errors int n, W; cin >> n >> W; vector<int> weight(n), value(n); for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } int sum = accumulate(value.begin(), value.end(), 0); vector<int> dp(sum, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int vi = sum - value[i]; vi >= 0; vi--) { dp[vi + value[i]] = min(dp[vi + value[i]], dp[vi] + weight[i]); } } int ans = 0; for (int i = 0; i <= sum; i++) { if (dp[i] <= W) ans = i; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> #define pqi priority_queue<int> #define pb push_back() #define INF 1000000000000000000 #define float long double #define pi acos(-1) const int modu = (1e9) + 7; void testCase(int ti) { cout << "Case " << ti << ": "; } int bigmod(int n, int p) { if (p == 0) return 1; int x = bigmod(n, p / 2) % modu; x = (x * x) % modu; if (p % 2) return (x * n) % modu; return x; } int modInverse(int a) { return bigmod(a, modu - 2) % modu; } void debug(string pr, vector<int> var, bool out = true) { #ifdef OFFLINE ofstream fl; fl.open("debug.txt"); fl << pr; for (int i = 0; i < var.size(); i++) fl << " " << var[i]; fl << endl; fl.close(); if (out) { cout << pr; for (int i = 0; i < var.size(); i++) cout << " " << var[i]; cout << endl; } #endif } void faster() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); } void defInit() { faster(); #ifdef OFFLINE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int add(int x, int y) { int z = (x % modu + y % modu) % modu; while (z < 0) z = (z + modu) % modu; return z; } int mul(int x, int y) { int z = (x % modu * y % modu) % modu; while (z < 0) z = (z + modu) % modu; return z; } // starts here int32_t main() { defInit(); // Now I will start writing codes and start preparation to get errors int n, W; cin >> n >> W; vector<int> weight(n), value(n); for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } int sum = accumulate(value.begin(), value.end(), 0); vector<int> dp(sum + 1, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int vi = sum - value[i]; vi >= 0; vi--) { dp[vi + value[i]] = min(dp[vi + value[i]], dp[vi] + weight[i]); } } int ans = 0; for (int i = 0; i <= sum; i++) { if (dp[i] <= W) ans = i; } cout << ans; return 0; }
[ "assignment.change" ]
971,302
971,303
u595057879
cpp
p03164
/*###################################################### #########~~~~~####~~~~###~~##~~##~~##~~##~~##~~######### #########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~######### #~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~# #########~~######~~##~~##~~##~~##~~##~~##~~##~~######### #########~~######~~##~~##~~##~~##~~##~~###~~~~########## ######################################################*/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize("O3") #define rtn return #define endl '\n' #define F first #define S second #define mt make_tuple #define pb push_back #define int long long #define value_at find_by_order #define index_of order_of_key #define fill(a, v) memset(a, v, sizeof(a)) #define copy(a, b) memcpy(b, a, sizeof(a)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define per(i, n) for (int i = (int)n - 1; i >= 0; --i) #define rep1(i, n) for (int i = 1; i <= (int)n; ++i) #define per1(i, n) for (int i = (int)n; i >= 1; --i) #define loop(i, begin, end) \ for (int i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); \ i += 1 - 2 * ((begin) > (end))) #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " = " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " |"; __f(comma + 1, args...); } #else #define trace(...) #endif typedef string str; typedef long double db; typedef long long ll; typedef pair<int, int> pll; typedef vector<int> vll; typedef vector<pll> vpll; typedef vector<db> vdb; template <class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; } template <class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; } template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 1e18; const db EPS = 1e-15; const int MOD = 1e9 + 7; const int N = 1e5 + 7; int n, W; int w[105], v[105]; int dp[N]; int32_t main() { FAST_IO; cin >> n >> W; rep(i, n) cin >> w[i] >> v[i]; rep(i, N) dp[i] = INF; dp[0] = 0; rep(i, n) { for (int j = N - 1; j >= v[i]; j--) { remin(dp[j], w[i] + dp[j - v[i]]); } } int ans = 0; rep(i, n) if (dp[i] <= W) ans = i; cout << ans; rtn 0; }
/*###################################################### #########~~~~~####~~~~###~~##~~##~~##~~##~~##~~######### #########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~######### #~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~# #########~~######~~##~~##~~##~~##~~##~~##~~##~~######### #########~~######~~##~~##~~##~~##~~##~~###~~~~########## ######################################################*/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize("O3") #define rtn return #define endl '\n' #define F first #define S second #define mt make_tuple #define pb push_back #define int long long #define value_at find_by_order #define index_of order_of_key #define fill(a, v) memset(a, v, sizeof(a)) #define copy(a, b) memcpy(b, a, sizeof(a)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define per(i, n) for (int i = (int)n - 1; i >= 0; --i) #define rep1(i, n) for (int i = 1; i <= (int)n; ++i) #define per1(i, n) for (int i = (int)n; i >= 1; --i) #define loop(i, begin, end) \ for (int i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); \ i += 1 - 2 * ((begin) > (end))) #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " = " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " |"; __f(comma + 1, args...); } #else #define trace(...) #endif typedef string str; typedef long double db; typedef long long ll; typedef pair<int, int> pll; typedef vector<int> vll; typedef vector<pll> vpll; typedef vector<db> vdb; template <class T, class V> void remin(T &a, V b) { a > b ? a = b : a = a; } template <class T, class V> void remax(T &a, V b) { a < b ? a = b : a = a; } template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 1e18; const db EPS = 1e-15; const int MOD = 1e9 + 7; const int N = 1e5 + 7; int n, W; int w[105], v[105]; int dp[N]; int32_t main() { FAST_IO; cin >> n >> W; rep(i, n) cin >> w[i] >> v[i]; rep(i, N) dp[i] = INF; dp[0] = 0; rep(i, n) { for (int j = N - 1; j >= v[i]; j--) { remin(dp[j], w[i] + dp[j - v[i]]); } } int ans = 0; rep(i, N) if (dp[i] <= W) ans = i; cout << ans; rtn 0; }
[ "identifier.change", "call.arguments.change" ]
971,304
971,305
u640997954
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef map<int, int> M; typedef vector<int> V; typedef queue<int> Q; typedef pair<long, long> PLL; typedef map<long, long> MLL; typedef vector<long long> VLL; typedef vector<pair<int, int>> VP; typedef vector<vector<int>> VV; #define INF (int)(1e9) #define MAXX (int)1.1529215e+18 #define inf 999999 #define EPS (1e-7) #define MOD (ll)(1e9 + 7) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define RALL(a) a.begin(), a.end(), greater<int>() #define PRALL(a) a.begin(), a.end(), greater<pair<int, int>>() #define ROT(a) a.begin(), a.begin() + 1, a.end() #define RROT(a) a.begin(), a.end() - 1, a.end() #define PB push_back #define MP make_pair #define PI acos(-1.0) // printf("myco\n");//for debug /*--------------------------------------------*/ int main() { int n, W; cin >> n >> W; V w(n), v(n); rep(i, n) { cin >> w[i] >> v[i]; } const int Max = 100001; vector<vector<int>> dp(n + 1, vector<int>(Max)); rep(i, Max) { dp[0][i] = INF; } dp[0][0] = 0; REP(i, n) { // i-1番の商品を使うのか? rep(j, Max) { dp[i][j] = dp[i - 1][j]; if (j - v[i - 1] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); } } int ans; rep(i, Max) { if (W >= dp[n][i]) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef map<int, int> M; typedef vector<int> V; typedef queue<int> Q; typedef pair<long, long> PLL; typedef map<long, long> MLL; typedef vector<long long> VLL; typedef vector<pair<int, int>> VP; typedef vector<vector<int>> VV; #define INF (int)(1e9) #define MAXX (int)1.1529215e+18 #define inf 999999 #define EPS (1e-7) #define MOD (ll)(1e9 + 7) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define RALL(a) a.begin(), a.end(), greater<int>() #define PRALL(a) a.begin(), a.end(), greater<pair<int, int>>() #define ROT(a) a.begin(), a.begin() + 1, a.end() #define RROT(a) a.begin(), a.end() - 1, a.end() #define PB push_back #define MP make_pair #define PI acos(-1.0) // printf("myco\n");//for debug /*--------------------------------------------*/ int main() { int n, W; cin >> n >> W; V w(n), v(n); rep(i, n) { cin >> w[i] >> v[i]; } const int Max = 100001; vector<vector<int>> dp(n + 1, vector<int>(Max)); rep(i, Max) { dp[0][i] = INF + 1; } dp[0][0] = 0; REP(i, n) { // i-1番の商品を使うのか? rep(j, Max) { dp[i][j] = dp[i - 1][j]; if (j - v[i - 1] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]); } } int ans; rep(i, Max) { if (W >= dp[n][i]) ans = i; } cout << ans << endl; }
[ "assignment.change" ]
971,312
971,313
u745562814
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef map<int, int> M; typedef vector<int> V; typedef pair<long, long> PLL; typedef map<long, long> MLL; typedef vector<long> VLL; #define INF (int)(1e9) #define MAXX 999999 #define EPS (1e-7) #define MOD ((ll)1e9 + 7) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define RALL(a) a.begin(), a.end(), greater<int>() #define ROT(a) a.begin(), a.begin() + 1, a.end() #define RROT(a) a.begin(), a.end() - 1, a.end() #define PB push_back #define MP make_pair #define PI acos(-1.0) /*--------------------------------------------*/ /*--------------------------------------------*/ int main() { int N, W; cin >> N >> W; const int MAX_V = 100001; const int MAX_N = 110; V w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<vector<ll>> dp(MAX_N, vector<ll>(MAX_V)); // INFで初期化 rep(j, MAX_V) dp[0][j] = INF; // dp[i][sum_v]はi-1番目までの商品を使ってvalueがsum_v以上になるように選んだ時の重量の最小 dp[0][0] = 0; //初期条件 REP(i, N) { rep(sum_v, MAX_V) { dp[i][sum_v] = dp[i - 1][sum_v]; if (sum_v - v[i - 1] >= 0) dp[i][sum_v] = min(dp[i - 1][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); } } int ans = 0; for (int i = MAX_V - 1; i >= 0; i--) { // dpの値がW以下のうちでsum_vの最大を保存 if (dp[N][i] <= W) { ans = i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef map<int, int> M; typedef vector<int> V; typedef pair<long, long> PLL; typedef map<long, long> MLL; typedef vector<long> VLL; #define INF (int)(1e9) #define MAXX 999999 #define EPS (1e-7) #define MOD ((ll)1e9 + 7) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define RALL(a) a.begin(), a.end(), greater<int>() #define ROT(a) a.begin(), a.begin() + 1, a.end() #define RROT(a) a.begin(), a.end() - 1, a.end() #define PB push_back #define MP make_pair #define PI acos(-1.0) /*--------------------------------------------*/ /*--------------------------------------------*/ int main() { int N, W; cin >> N >> W; const int MAX_V = 100001; const int MAX_N = 110; V w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<vector<ll>> dp(MAX_N, vector<ll>(MAX_V)); // INFで初期化 rep(j, MAX_V) dp[0][j] = INF + 100; // dp[i][sum_v]はi-1番目までの商品を使ってvalueがsum_v以上になるように選んだ時の重量の最小 dp[0][0] = 0; //初期条件 REP(i, N) { rep(sum_v, MAX_V) { dp[i][sum_v] = dp[i - 1][sum_v]; if (sum_v - v[i - 1] >= 0) dp[i][sum_v] = min(dp[i - 1][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); } } int ans = 0; for (int i = MAX_V - 1; i >= 0; i--) { // dpの値がW以下のうちでsum_vの最大を保存 if (dp[N][i] <= W) { ans = i; break; } } cout << ans << endl; }
[ "assignment.change" ]
971,314
971,315
u745562814
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef map<int, int> M; typedef vector<int> V; typedef pair<long, long> PLL; typedef map<long, long> MLL; typedef vector<long> VLL; #define INF (int)(1e9) #define MAXX 999999 #define EPS (1e-7) #define MOD ((ll)1e9 + 7) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define RALL(a) a.begin(), a.end(), greater<int>() #define ROT(a) a.begin(), a.begin() + 1, a.end() #define RROT(a) a.begin(), a.end() - 1, a.end() #define PB push_back #define MP make_pair #define PI acos(-1.0) /*--------------------------------------------*/ /*--------------------------------------------*/ int main() { int N, W; cin >> N >> W; const int MAX_V = 100001; const int MAX_N = 101; V w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<vector<ll>> dp(MAX_N, vector<ll>(MAX_V)); // INFで初期化 rep(j, MAX_V) dp[0][j] = INF; // dp[i][sum_v]はi-1番目までの商品を使ってvalueがsum_v以上になるように選んだ時の重量の最小 dp[0][0] = 0; //初期条件 REP(i, N) { rep(sum_v, MAX_V) { dp[i][sum_v] = dp[i - 1][sum_v]; if (sum_v - v[i - 1] >= 0) dp[i][sum_v] = min(dp[i - 1][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); } } int ans = 0; for (int i = MAX_V - 1; i >= 0; i--) { // dpの値がW以下のうちでsum_vの最大を保存 if (dp[N][i] <= W) { ans = i; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef map<int, int> M; typedef vector<int> V; typedef pair<long, long> PLL; typedef map<long, long> MLL; typedef vector<long> VLL; #define INF (int)(1e9) #define MAXX 999999 #define EPS (1e-7) #define MOD ((ll)1e9 + 7) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define FOR(i, k, n) for (int i = (k); i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define RALL(a) a.begin(), a.end(), greater<int>() #define ROT(a) a.begin(), a.begin() + 1, a.end() #define RROT(a) a.begin(), a.end() - 1, a.end() #define PB push_back #define MP make_pair #define PI acos(-1.0) /*--------------------------------------------*/ /*--------------------------------------------*/ int main() { int N, W; cin >> N >> W; const int MAX_V = 100001; const int MAX_N = 110; V w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<vector<ll>> dp(MAX_N, vector<ll>(MAX_V)); // INFで初期化 rep(j, MAX_V) dp[0][j] = INF + 100; // dp[i][sum_v]はi-1番目までの商品を使ってvalueがsum_v以上になるように選んだ時の重量の最小 dp[0][0] = 0; //初期条件 REP(i, N) { rep(sum_v, MAX_V) { dp[i][sum_v] = dp[i - 1][sum_v]; if (sum_v - v[i - 1] >= 0) dp[i][sum_v] = min(dp[i - 1][sum_v], dp[i - 1][sum_v - v[i - 1]] + w[i - 1]); } } int ans = 0; for (int i = MAX_V - 1; i >= 0; i--) { // dpの値がW以下のうちでsum_vの最大を保存 if (dp[N][i] <= W) { ans = i; break; } } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "assignment.change" ]
971,316
971,315
u745562814
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define REP(i, a, n) for (int i = a; i < n; ++i) #define REPR(i, a, n) for (int i = a; i > n; --i) #define RUP(a, b) ((a + b - 1) / (b)) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define mp make_pair #define mt make_tuple #define MOD 1000000007 #define INF LLONG_MAX / 2 typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> Tiii; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef vector<Pii> VPii; typedef vector<string> Vs; 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; } template <class T> void YesNo(T a) { cout << (a ? "Yes" : "No") << endl; } template <class T> void YESNO(T a) { cout << (a ? "YES" : "NO") << endl; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } void uniq(Vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } bool comp(Pii a, Pii b) { if (a.second != b.second) return a.second < b.second; else return a.first < b.first; } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n, W; cin >> n >> W; Vi w(n), v(n); REP(i, 0, n) cin >> w[i] >> v[i]; const int nmax = 100, vmax = 100000; VVi dp(nmax + 1, Vi(vmax + 1, INF)); dp[0][0] = 0; REP(i, 0, n) { REP(j, 0, vmax) { chmin(dp[i + 1][j], dp[i][j]); if (j + v[i] <= W) chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } int ans = 0; REP(i, 0, vmax) if (dp[n][i] <= W) ans = i; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" #define REP(i, a, n) for (int i = a; i < n; ++i) #define REPR(i, a, n) for (int i = a; i > n; --i) #define RUP(a, b) ((a + b - 1) / (b)) #define ALL(v) (v).begin(), (v).end() #define pb push_back #define mp make_pair #define mt make_tuple #define MOD 1000000007 #define INF LLONG_MAX / 2 typedef long long ll; typedef pair<int, int> Pii; typedef tuple<int, int, int> Tiii; typedef vector<int> Vi; typedef vector<Vi> VVi; typedef vector<Pii> VPii; typedef vector<string> Vs; 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; } template <class T> void YesNo(T a) { cout << (a ? "Yes" : "No") << endl; } template <class T> void YESNO(T a) { cout << (a ? "YES" : "NO") << endl; } int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } void uniq(Vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } bool comp(Pii a, Pii b) { if (a.second != b.second) return a.second < b.second; else return a.first < b.first; } signed main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n, W; cin >> n >> W; Vi w(n), v(n); REP(i, 0, n) cin >> w[i] >> v[i]; const int nmax = 110, vmax = 101000; VVi dp(nmax + 1, Vi(vmax + 1, INF)); dp[0][0] = 0; REP(i, 0, n) { REP(j, 0, vmax) { chmin(dp[i + 1][j], dp[i][j]); if (j + v[i] <= vmax) chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } int ans = 0; REP(i, 0, vmax) if (dp[n][i] <= W) ans = i; cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "identifier.change", "control_flow.branch.if.condition.change" ]
971,341
971,340
u635484372
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; const int inf = 1e9; const ll linf = 1e18; const ll mod = 1e9 + 7; ll dp[101][100001]; int main() { int n, maxw; cin >> n >> maxw; for (int i = 0; i <= n; i++) { for (int j = 0; j < 1001; j++) { dp[i][j] = linf; } } dp[0][0] = 0; int w[n], v[n]; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (int i = 1; i <= n; i++) { for (int j = 0; j < 100001; 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]); } } } ll ans = 0; for (ll i = 0; i < 100001; i++) { if (dp[n][i] <= maxw) ans = max(ans, i); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; const int inf = 1e9; const ll linf = 1e18; const ll mod = 1e9 + 7; ll dp[101][100001]; int main() { int n, maxw; cin >> n >> maxw; for (int i = 0; i <= n; i++) { for (int j = 0; j < 100001; j++) { dp[i][j] = linf; } } dp[0][0] = 0; int w[n], v[n]; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } for (int i = 1; i <= n; i++) { for (int j = 0; j < 100001; 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]); } } } ll ans = 0; for (ll i = 0; i < 100001; i++) { if (dp[n][i] <= maxw) ans = max(ans, i); } cout << ans << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
971,344
971,345
u057866967
cpp
p03164
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using ld = long double; using Vl = vector<ll>; using pll = pair<ll, ll>; using vb = vector<bool>; using vs = vector<string>; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, m, n) for (int i = m; i < n; ++i) ll N, W; Vl w(N), v(N); ll dp[101][100001]; // 0 int main() { cin >> N >> W; w.resize(N); v.resize(N); ll maxValue = 0; REP(i, N) { cin >> w[i] >> v[i]; maxValue += v[i]; } REP(i, N) REP(vi, maxValue + 1) dp[i][vi] = ll(1e18); //クソ重くしとく dp[0][0] = 0; REP(i, N) REP(vi, maxValue + 1) { if (vi >= v[i]) { //同価値で軽い人を入れる。 dp[i + 1][vi] = min(dp[i][vi], dp[i][vi - v[i]] + w[i]); } else { // 同価値のものが見つからないばやい dp[i + 1][vi] = dp[i][vi]; } } int ans = 0; for (int vi = 0; vi < maxValue; vi++) { if (dp[N][vi] <= W) ans = vi; // viのときの重さ } cout << ans; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using ld = long double; using Vl = vector<ll>; using pll = pair<ll, ll>; using vb = vector<bool>; using vs = vector<string>; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, m, n) for (int i = m; i < n; ++i) ll N, W; Vl w(N), v(N); ll dp[101][100001]; // 0 int main() { cin >> N >> W; w.resize(N); v.resize(N); ll maxValue = 0; REP(i, N) { cin >> w[i] >> v[i]; maxValue += v[i]; } REP(i, N) REP(vi, maxValue + 1) dp[i][vi] = ll(1e18); //クソ重くしとく dp[0][0] = 0; REP(i, N) REP(vi, maxValue + 1) { if (vi >= v[i]) { //同価値で軽い人を入れる。 dp[i + 1][vi] = min(dp[i][vi], dp[i][vi - v[i]] + w[i]); } else { // 同価値のものが見つからないばやい dp[i + 1][vi] = dp[i][vi]; } } int ans = 0; for (int vi = 0; vi <= maxValue; vi++) { if (dp[N][vi] <= W) ans = vi; // viのときの重さ } cout << ans; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,366
971,367
u997308904
cpp
p03164
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 0; i <= n; i++) ll dp[105][100005]; int main() { ll n, W; cin >> n >> W; ll v[n], w[n], sum = 0; rep(i, n) { cin >> w[i] >> v[i]; sum += v[i]; } ll dp[sum]; rep(i, sum) dp[i] = INF; dp[0] = 0; rep(i, n) { for (int j = sum - v[i]; j >= 0; j--) { dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]); } } ll ans = 0; for (int i = sum; i >= 0; i--) { if (dp[i] <= W) { ans = max((ll)i, ans); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1000000000; typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 0; i <= n; i++) ll dp[105][100005]; int main() { ll n, W; cin >> n >> W; ll v[n], w[n], sum = 0; rep(i, n) { cin >> w[i] >> v[i]; sum += v[i]; } ll dp[sum + 1]; REP(i, sum) dp[i] = INF; dp[0] = 0; rep(i, n) { for (int j = sum - v[i]; j >= 0; j--) { dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]); } } ll ans = 0; for (int i = sum; i >= 0; i--) { if (dp[i] <= W) { ans = max((ll)i, ans); } } cout << ans << endl; return 0; }
[ "assignment.variable.change", "identifier.change", "call.function.change" ]
971,368
971,369
u160036974
cpp
p03164
#include <algorithm> #include <iostream> #include <vector> using namespace std; long long weights[101]; long long values[101]; const int vMax = 100 * 1000 + 10; long long dp[101][vMax]; long long const INF = 1LL << 60; int main() { int n; long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } for (int i = 0; i <= n; i++) { for (int v = 0; v <= vMax; v++) { dp[i][v] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int v = 0; v <= vMax; v++) { if (v >= values[i]) { dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i]] + weights[i]); } else { dp[i + 1][v] = dp[i][v]; } } } int ret = 0; for (int v = 0; v <= vMax; v++) { if (dp[n][v] <= W) { ret = v; } } cout << ret; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; long long weights[101]; long long values[101]; const int vMax = 100 * 1000 + 1; long long dp[101][vMax + 1]; long long const INF = 1LL << 60; int main() { int n; long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } for (int i = 0; i <= n; i++) { for (int v = 0; v <= vMax; v++) { dp[i][v] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int v = 0; v <= vMax; v++) { if (v >= values[i]) { dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i]] + weights[i]); } else { dp[i + 1][v] = dp[i][v]; } } } int ret = 0; for (int v = 0; v <= vMax; v++) { if (dp[n][v] <= W) { ret = v; } } cout << ret; }
[ "literal.number.change", "expression.operation.binary.change" ]
971,375
971,376
u100757865
cpp
p03164
#include <algorithm> #include <iostream> #include <vector> using namespace std; long long weights[101]; long long values[101]; const long long vMax = 100 * 1000 + 1; long long dp[101][vMax]; long long const INF = 1LL << 60; int main() { int n; long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } for (int i = 0; i <= n; i++) { for (long long v = 0; v <= vMax; v++) { dp[i][v] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (long long v = 0; v <= vMax; v++) { if (v >= values[i]) { dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i]] + weights[i]); } else { dp[i + 1][v] = dp[i][v]; } } } long long ret = 0; for (long long v = 0; v <= vMax; v++) { if (dp[n][v] <= W) { ret = v; } } cout << ret; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; long long weights[101]; long long values[101]; const long long vMax = 100 * 1000 + 10; long long dp[101][vMax]; long long const INF = 1LL << 60; int main() { int n; long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } for (int i = 0; i <= n; i++) { for (long long v = 0; v < vMax; v++) { dp[i][v] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (long long v = 0; v < vMax; v++) { if (v >= values[i]) { dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i]] + weights[i]); } else { dp[i + 1][v] = dp[i][v]; } } } long long ret = 0; for (long long v = 0; v < vMax; v++) { if (dp[n][v] <= W) { ret = v; } } cout << ret; }
[ "literal.number.change", "expression.operation.binary.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one" ]
971,377
971,378
u100757865
cpp
p03164
#include <algorithm> #include <iostream> #include <vector> using namespace std; long long weights[101]; long long values[101]; const long long vMax = 100 * 1000 + 1; long long dp[101][vMax]; long long const INF = 1LL << 60; int main() { int n; long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } for (int i = 0; i <= n; i++) { for (long long v = 0; v <= vMax; v++) { dp[i][v] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (long long v = 0; v <= vMax; v++) { if (v >= values[i]) { dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i]] + weights[i]); } else { dp[i + 1][v] = dp[i][v]; } } } long long ret = 0; for (long long v = 0; v <= vMax; v++) { if (dp[n][v] <= W) { ret = v; } } cout << ret; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; long long weights[101]; long long values[101]; const long long vMax = 100 * 1000 + 1; long long dp[101][vMax]; long long const INF = 1LL << 60; int main() { int n; long long W; cin >> n >> W; for (int i = 0; i < n; i++) { cin >> weights[i] >> values[i]; } for (int i = 0; i <= n; i++) { for (long long v = 0; v < vMax; v++) { dp[i][v] = INF; } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (long long v = 0; v < vMax; v++) { if (v >= values[i]) { dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i]] + weights[i]); } else { dp[i + 1][v] = dp[i][v]; } } } long long ret = 0; for (long long v = 0; v < vMax; v++) { if (dp[n][v] <= W) { ret = v; } } cout << ret; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,377
971,379
u100757865
cpp
p03164
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e2 + 2; const int MAXV = 1e5 + 5; const int INF = 1e9 + 7; int val[MAXN], w[MAXN]; int dp[MAXN][MAXV]; int main() { int n, W; cin >> n >> W; int V = 0; for (int i = 1; i <= n; i++) { cin >> w[i] >> val[i]; V += val[i]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= V; j++) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= V; j++) { if (val[i] <= j) { dp[i][j] = min(dp[i - 1][j - val[i]] + w[i], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } int ans = 0; for (int i = 0; i <= V; i++) { if (dp[n][i] <= W) { ans = max(ans, i); } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e2 + 2; const int MAXV = 1e5 + 5; const int INF = 1e9 + 7; int val[MAXN], w[MAXN]; int dp[MAXN][MAXV]; int main() { int n, W; cin >> n >> W; int V = 0; for (int i = 1; i <= n; i++) { cin >> w[i] >> val[i]; V += val[i]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= V; j++) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= V; j++) { if (val[i] <= j) { dp[i][j] = min(dp[i - 1][j - val[i]] + w[i], dp[i - 1][j]); } else { dp[i][j] = dp[i - 1][j]; } } } int ans = 0; for (int i = 0; i <= V; i++) { if (dp[n][i] <= W) { ans = max(ans, i); } } cout << ans << '\n'; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
971,380
971,381
u786670922
cpp
p03164
#include <bits/stdc++.h> using namespace std; /*### FAST-IO ###*/ #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); /*### DEBUGGGGGGG ###*/ #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define testcases \ int testcases; \ cin >> testcases; \ while (testcases--) #define queries \ int queries; \ cin >> queries; \ while (queries--) /*### TO PRINT ###*/ #define pp1(a) cout << a << endl; #define pp2(a, b) cout << a << " " << b << endl; #define pp3(a, b, c) cout << a << " " << b << " " << c << endl; #define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl; #define pp5(a, b, c, d, e) \ cout << a << " " << b << " " << c << " " << d << " " << e << endl; /*### SSSSSSS ###*/ #define INF INT_MAX #define endl "\n" #define ll long long #define int long long ll mod = 1e9 + 7; #define pb push_back #define mp make_pair #define pii pair<int, int> #define msi map<string, int> #define vi vector<int> #define vpii vector<pair<int, int>> #define ff first #define ss second #define sz size() #define REP(i, a, b) for (int i = a; i <= b; i++) #define REP1(i, a, b) for (int i = a; i < b; i++) #define f0(n) for (ll i = 0; i < n; i++) #define f(n) for (ll i = 1; i <= n; i++) #define fn(a, n) for (ll a = 0; a < n; a++) #define flr(a, l, r) for (ll a = l; a <= r; a++) #define sorta(a) sort(a.begin(), a.end()); #define sortd(a) sort(a.begin(), a.end(), greater<ll>()); #define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>()); #define blb(a, b) lower_bound(all(a), b) - a.begin(); #define bub(a, b) upper_bound(all(a), b) - a.begin(); #define stop return 0 /*### COMPARATOR ###*/ bool rev(int x, int y) { return x > y; } /*### PAIR_SORT_IN_DESCENDING_ORDER ###*/ bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } /*### MODULO ###*/ int modulo(int x, int N) { return (x % N + N) % N; } /*### MAX & MIN ###*/ int max(int a, int b) { if (a >= b) return a; else return b; } int min(int a, int b) { if (a <= b) return a; else return b; } /*### MOD-DIFFERENCE ###*/ ll diff(ll a, ll b) { if (a >= b) return a - b; else return b - a; } /*### PAIR-SORTING ###*/ void pairsort(int a[], int b[], ll n) { pair<int, int> pairt[n]; for (int i = 0; i < n; i++) { pairt[i].first = a[i]; pairt[i].second = b[i]; } sort(pairt, pairt + n); for (int i = 0; i < n; i++) { a[i] = pairt[i].first; b[i] = pairt[i].second; } } /*### GCD && LCM ###*/ ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } /*### PRIME OR NOT ###*/ int isPrime(int n) { if (n < 2) return 0; if (n < 4) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; return 1; } /*### nCr ###*/ long long C(int n, int r) { if (r > n - r) r = n - r; long long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } /*### MODULAR-EXPONENTIATION ###*/ ll modexpo(ll x, ll p) { ll res = 1; x = x % mod; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % mod; res %= mod; } return res; } uint64_t mul_mod(uint64_t a, uint64_t b, uint64_t m) { long double x; uint64_t c; int64_t r; if (a >= m) a %= m; if (b >= m) b %= m; x = a; c = x * b / m; r = (int64_t)(a * b - c * m) % (int64_t)m; return r < 0 ? r + m : r; } /*### STRING TO INT ###*/ int sti(string s) { int ans = 0; int p = 1; for (int i = s.size() - 1; i >= 0; i--) { ans = (ans + ((ll)(s[i] - '0') * p) % mod) % mod; p = (p * 10) % mod; } return ans; } /*### TIMER ###*/ void time() { #ifndef ONLINE_JUDGE cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; #endif } /*************************** END OF TEMPLATE ****************************/ const int N = 1e6 + 5; void maxself(int &a, int b) { a = max(a, b); } int32_t main() { IOS // 1st solution int n, W; cin >> n >> W; vi dp(W + 1); // dp[i]-the max total value of items with total weight exatly i for (int i = 0; i < n; ++i) { int weight, value; cin >> weight >> value; for (int j = W - weight; j >= 0; --j) { // for(int j=0; j<=W-weight ; j++){ maxself(dp[j + weight], dp[j] + value); } } int ans = 0; flr(i, 0, W) { maxself(ans, dp[i]); } cout << ans << endl; // time(); stop; }
#include <bits/stdc++.h> using namespace std; /*### FAST-IO ###*/ #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); /*### DEBUGGGGGGG ###*/ #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define testcases \ int testcases; \ cin >> testcases; \ while (testcases--) #define queries \ int queries; \ cin >> queries; \ while (queries--) /*### TO PRINT ###*/ #define pp1(a) cout << a << endl; #define pp2(a, b) cout << a << " " << b << endl; #define pp3(a, b, c) cout << a << " " << b << " " << c << endl; #define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl; #define pp5(a, b, c, d, e) \ cout << a << " " << b << " " << c << " " << d << " " << e << endl; /*### SSSSSSS ###*/ #define INF INT_MAX #define endl "\n" #define ll long long #define int long long ll mod = 1e18L + 5; #define pb push_back #define mp make_pair #define pii pair<int, int> #define msi map<string, int> #define vi vector<int> #define vpii vector<pair<int, int>> #define ff first #define ss second #define sz size() #define REP(i, a, b) for (int i = a; i <= b; i++) #define REP1(i, a, b) for (int i = a; i < b; i++) #define f0(n) for (ll i = 0; i < n; i++) #define f(n) for (ll i = 1; i <= n; i++) #define fn(a, n) for (ll a = 0; a < n; a++) #define flr(a, l, r) for (ll a = l; a <= r; a++) #define sorta(a) sort(a.begin(), a.end()); #define sortd(a) sort(a.begin(), a.end(), greater<ll>()); #define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>()); #define blb(a, b) lower_bound(all(a), b) - a.begin(); #define bub(a, b) upper_bound(all(a), b) - a.begin(); #define stop return 0 /*### COMPARATOR ###*/ bool rev(int x, int y) { return x > y; } /*### PAIR_SORT_IN_DESCENDING_ORDER ###*/ bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } /*### MODULO ###*/ int modulo(int x, int N) { return (x % N + N) % N; } /*### MAX & MIN ###*/ int max(int a, int b) { if (a >= b) return a; else return b; } int min(int a, int b) { if (a <= b) return a; else return b; } /*### MOD-DIFFERENCE ###*/ ll diff(ll a, ll b) { if (a >= b) return a - b; else return b - a; } /*### PAIR-SORTING ###*/ void pairsort(int a[], int b[], ll n) { pair<int, int> pairt[n]; for (int i = 0; i < n; i++) { pairt[i].first = a[i]; pairt[i].second = b[i]; } sort(pairt, pairt + n); for (int i = 0; i < n; i++) { a[i] = pairt[i].first; b[i] = pairt[i].second; } } /*### GCD && LCM ###*/ ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } /*### PRIME OR NOT ###*/ int isPrime(int n) { if (n < 2) return 0; if (n < 4) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; return 1; } /*### nCr ###*/ long long C(int n, int r) { if (r > n - r) r = n - r; long long ans = 1; int i; for (i = 1; i <= r; i++) { ans *= n - r + i; ans /= i; } return ans; } /*### MODULAR-EXPONENTIATION ###*/ ll modexpo(ll x, ll p) { ll res = 1; x = x % mod; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % mod; res %= mod; } return res; } uint64_t mul_mod(uint64_t a, uint64_t b, uint64_t m) { long double x; uint64_t c; int64_t r; if (a >= m) a %= m; if (b >= m) b %= m; x = a; c = x * b / m; r = (int64_t)(a * b - c * m) % (int64_t)m; return r < 0 ? r + m : r; } /*### STRING TO INT ###*/ int sti(string s) { int ans = 0; int p = 1; for (int i = s.size() - 1; i >= 0; i--) { ans = (ans + ((ll)(s[i] - '0') * p) % mod) % mod; p = (p * 10) % mod; } return ans; } /*### TIMER ###*/ void time() { #ifndef ONLINE_JUDGE cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; #endif } /*************************** END OF TEMPLATE ****************************/ const int N = 1e6 + 5; void minself(int &a, int b) { a = min(a, b); } int32_t main() { IOS // 1st solution int n, W; cin >> n >> W; vi weight(n), value(n); for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } int sum_value = 0; for (int x : value) { sum_value += x; } vi dp(sum_value + 1, INF); dp[0] = 0; // dp[i]-the minn total value of items with total value exatly i for (int i = 0; i < n; ++i) { for (int j = sum_value - value[i]; j >= 0; --j) { // for(int j=0; j<=W-weight ; j++){ minself(dp[j + value[i]], dp[j] + weight[i]); } } int ans = 0; flr(i, 0, sum_value) { if (dp[i] <= W) { ans = max(ans, i); } // minself(ans,dp[i]); } cout << ans << endl; // time(); stop; }
[ "literal.number.change", "expression.operation.binary.change", "literal.number.type.widen.change" ]
971,382
971,383
u470689998
cpp
p03164
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; #ifdef _debug #define dout(i) cout << #i << ' ' << i << ' ' #else #define dout(i) // #endif using ll = long long; using ull = unsigned long long; using ul = unsigned; using db = double; const int maxn = 101; const int maxw = 100001; const int inf = 1000000001; ll dp[maxw]; int n, lim; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> lim; fill(dp + 1, dp + lim + 1, inf); for (int w, v, i = 0; i < n; ++i) { cin >> w >> v; for (int j = maxw - 1; j >= v; --j) dp[j] = min(dp[j], dp[j - v] + w); } for (int i = maxw - 1; i >= 0; --i) if (dp[i] <= lim) return cout << i << '\n', 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; #ifdef _debug #define dout(i) cout << #i << ' ' << i << ' ' #else #define dout(i) // #endif using ll = long long; using ull = unsigned long long; using ul = unsigned; using db = double; const int maxn = 101; const int maxw = 100001; const int inf = 1000000001; ll dp[maxw]; int n, lim; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> lim; fill(dp + 1, dp + maxw, inf); for (int w, v, i = 0; i < n; ++i) { cin >> w >> v; for (int j = maxw - 1; j >= v; --j) dp[j] = min(dp[j], dp[j - v] + w); } for (int i = maxw - 1; i >= 0; --i) if (dp[i] <= lim) return cout << i << '\n', 0; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
971,410
971,411
u233690053
cpp
p03164
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (ll i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001 #define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010 #define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100 #define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000 #define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000 #define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000 #define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000 #define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll LLINF = 1LL << 60; const int INTINF = 1 << 30; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long 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] % MOD) % MOD; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } ll root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } ll size(ll x) { return -par[root(x)]; } }; template <typename T> vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) { const T INF = numeric_limits<T>::max(); using P = pair<T, int>; int n = G.size(); vector<T> d(n, INF); vector<int> b(n, -1); priority_queue<P, vector<P>, greater<P>> q; d[s] = 0; q.emplace(d[s], s); while (!q.empty()) { P p = q.top(); q.pop(); int v = p.second; if (d[v] < p.first) continue; for (auto &e : G[v]) { int u = e.first; T c = e.second; if (d[u] > d[v] + c) { d[u] = d[v] + c; b[u] = v; q.emplace(d[u], u); } } } return d; } vector<vector<int>> bfs(vector<string> &s, int sy, int sx, char wall, int dir) { int h = s.size(), w = s.front().size(); vector<vector<int>> dp(h, vector<int>(w, -1)); using P = pair<int, int>; queue<P> q; dp[sy][sx] = 0; q.emplace(sy, sx); int dy[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; auto in = [&](int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; }; while (!q.empty()) { int y, x; tie(y, x) = q.front(); q.pop(); for (int k = 0; k < dir; k++) { int ny = y + dy[k], nx = x + dx[k]; if (!in(ny, nx) || s[ny][nx] == wall) continue; if (~dp[ny][nx]) continue; dp[ny][nx] = dp[y][x] + 1; q.emplace(ny, nx); } } return dp; } int64_t power(int64_t x, int64_t n, int64_t mod) { int64_t ret = 1; while (n > 0) { if (n & 1) (ret *= x) %= mod; (x *= x) %= mod; n >>= 1; } return ret; } vector<int> sieve_of_eratosthenes(int n) { vector<int> primes(n); for (int i = 2; i < n; ++i) primes[i] = i; for (int i = 2; i * i < n; ++i) if (primes[i]) for (int j = i * i; j < n; j += i) primes[j] = 0; return primes; } struct Dice { int s[6]; int &top() { return s[0]; } int &south() { return s[1]; } int &east() { return s[2]; } int &west() { return s[3]; } int &north() { return s[4]; } int &bottom() { return s[5]; } void roll(char c) { // the view from above // N // W E // S string b("EWNSRL"); int v[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4}, {0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}}; for (int k = 0; k < 6; k++) { if (b[k] != c) continue; int t = s[v[k][0]]; s[v[k][0]] = s[v[k][1]]; s[v[k][1]] = s[v[k][2]]; s[v[k][2]] = s[v[k][3]]; s[v[k][3]] = t; } } using ll = long long; ll hash() { ll res = 0; for (int i = 0; i < 6; i++) res = res * 256 + s[i]; return res; } bool operator==(const Dice &d) const { for (int i = 0; i < 6; i++) if (s[i] != d.s[i]) return 0; return 1; } }; vector<Dice> makeDices(Dice d) { vector<Dice> res; for (int i = 0; i < 6; i++) { Dice t(d); if (i == 1) t.roll('N'); if (i == 2) t.roll('S'); if (i == 3) t.roll('S'), t.roll('S'); if (i == 4) t.roll('L'); if (i == 5) t.roll('R'); for (int k = 0; k < 4; k++) { res.push_back(t); t.roll('E'); } } return res; } std::vector<ll> divisor(ll n) // nの約数を列挙 { std::vector<ll> ret; for (ll i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.push_back(i); if (i != 1 && i * i != n) { ret.push_back(n / i); } } } return ret; } // 多次元 vector 生成 template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } using Graph = vector<vector<int>>; // 深さ優先探索 vector<bool> seen; void gdfs(const Graph &G, int v) { seen[v] = true; // v を訪問済にする // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]) continue; // next_v が探索済だったらスルー gdfs(G, next_v); // 再帰的に探索 } } const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string MINUSINF = "-"; void Cmax(string &a, string b) { if (a == MINUSINF) a = b; else if (a.size() < b.size()) a = b; else if (a.size() == b.size()) { if (a < b) a = b; } } int N; ll dp[110][1100]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll N, W; cin >> N >> W; vector<ll> w(N); vector<ll> v(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(i, 110) rep(j, 1100) dp[i][j] = LLINF; ll ans = 0; dp[0][0] = 0; rep(i, N) { rep(j, 1010) { if (j >= v[i]) chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]); else chmin(dp[i + 1][j], dp[i][j]); } } rep(i, 1010) { if (dp[N][i] <= W) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> #define all(x) (x).begin(), (x).end() typedef long long ll; #define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i) #define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i) #define repprev(i, a, b) for (ll i = b - 1; i >= a; i--) #define reprev(i, n) repprev(i, 0, n) using namespace std; #define sz(x) ((int)(x).size()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMSET(v, h) memset((v), h, sizeof(v)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } #define pb push_back #define mp make_pair #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001 #define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010 #define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100 #define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000 #define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000 #define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000 #define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000 #define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000 ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } const ll LLINF = 1LL << 60; const int INTINF = 1 << 30; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long 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] % MOD) % MOD; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll n) : par(n, -1) {} void init(ll n) { par.assign(n, -1); } ll root(ll x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(ll x, ll y) { return root(x) == root(y); } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } ll size(ll x) { return -par[root(x)]; } }; template <typename T> vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) { const T INF = numeric_limits<T>::max(); using P = pair<T, int>; int n = G.size(); vector<T> d(n, INF); vector<int> b(n, -1); priority_queue<P, vector<P>, greater<P>> q; d[s] = 0; q.emplace(d[s], s); while (!q.empty()) { P p = q.top(); q.pop(); int v = p.second; if (d[v] < p.first) continue; for (auto &e : G[v]) { int u = e.first; T c = e.second; if (d[u] > d[v] + c) { d[u] = d[v] + c; b[u] = v; q.emplace(d[u], u); } } } return d; } vector<vector<int>> bfs(vector<string> &s, int sy, int sx, char wall, int dir) { int h = s.size(), w = s.front().size(); vector<vector<int>> dp(h, vector<int>(w, -1)); using P = pair<int, int>; queue<P> q; dp[sy][sx] = 0; q.emplace(sy, sx); int dy[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}; auto in = [&](int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; }; while (!q.empty()) { int y, x; tie(y, x) = q.front(); q.pop(); for (int k = 0; k < dir; k++) { int ny = y + dy[k], nx = x + dx[k]; if (!in(ny, nx) || s[ny][nx] == wall) continue; if (~dp[ny][nx]) continue; dp[ny][nx] = dp[y][x] + 1; q.emplace(ny, nx); } } return dp; } int64_t power(int64_t x, int64_t n, int64_t mod) { int64_t ret = 1; while (n > 0) { if (n & 1) (ret *= x) %= mod; (x *= x) %= mod; n >>= 1; } return ret; } vector<int> sieve_of_eratosthenes(int n) { vector<int> primes(n); for (int i = 2; i < n; ++i) primes[i] = i; for (int i = 2; i * i < n; ++i) if (primes[i]) for (int j = i * i; j < n; j += i) primes[j] = 0; return primes; } struct Dice { int s[6]; int &top() { return s[0]; } int &south() { return s[1]; } int &east() { return s[2]; } int &west() { return s[3]; } int &north() { return s[4]; } int &bottom() { return s[5]; } void roll(char c) { // the view from above // N // W E // S string b("EWNSRL"); int v[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4}, {0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}}; for (int k = 0; k < 6; k++) { if (b[k] != c) continue; int t = s[v[k][0]]; s[v[k][0]] = s[v[k][1]]; s[v[k][1]] = s[v[k][2]]; s[v[k][2]] = s[v[k][3]]; s[v[k][3]] = t; } } using ll = long long; ll hash() { ll res = 0; for (int i = 0; i < 6; i++) res = res * 256 + s[i]; return res; } bool operator==(const Dice &d) const { for (int i = 0; i < 6; i++) if (s[i] != d.s[i]) return 0; return 1; } }; vector<Dice> makeDices(Dice d) { vector<Dice> res; for (int i = 0; i < 6; i++) { Dice t(d); if (i == 1) t.roll('N'); if (i == 2) t.roll('S'); if (i == 3) t.roll('S'), t.roll('S'); if (i == 4) t.roll('L'); if (i == 5) t.roll('R'); for (int k = 0; k < 4; k++) { res.push_back(t); t.roll('E'); } } return res; } std::vector<ll> divisor(ll n) // nの約数を列挙 { std::vector<ll> ret; for (ll i = 1; i * i <= n; ++i) { if (n % i == 0) { ret.push_back(i); if (i != 1 && i * i != n) { ret.push_back(n / i); } } } return ret; } // 多次元 vector 生成 template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } using Graph = vector<vector<int>>; // 深さ優先探索 vector<bool> seen; void gdfs(const Graph &G, int v) { seen[v] = true; // v を訪問済にする // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]) continue; // next_v が探索済だったらスルー gdfs(G, next_v); // 再帰的に探索 } } const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const string MINUSINF = "-"; void Cmax(string &a, string b) { if (a == MINUSINF) a = b; else if (a.size() < b.size()) a = b; else if (a.size() == b.size()) { if (a < b) a = b; } } int N; ll dp[110][100100]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); ll N, W; cin >> N >> W; vector<ll> w(N); vector<ll> v(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(i, 110) rep(j, 100100) dp[i][j] = LLINF; ll ans = 0; dp[0][0] = 0; rep(i, N) { rep(j, 100100) { if (j >= v[i]) chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]); chmin(dp[i + 1][j], dp[i][j]); } } rep(i, 100100) { if (dp[N][i] <= W) ans = i; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "assignment.variable.change", "call.arguments.change", "control_flow.branch.else.remove" ]
971,417
971,416
u135572611
cpp
p03164
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; #define INF 1e9 + 1 #define rep(i, n) for (int i = 0; i < n; i++) int N, W; int w[101], v[101]; int dp[101][100100]; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> w[i] >> v[i]; } rep(i, N) { rep(j, 100001) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= 100000; j++) { dp[i + 1][j] = dp[i][j]; if (j >= v[i]) { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i + 1]] + w[i + 1]); } } } int min = INF; int i; int temp = 0; for (i = 0; i <= 100000; i++) { if (dp[N][i] <= W) { temp = i; } } cout << temp << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; #define INF 1e9 + 1 #define rep(i, n) for (int i = 0; i < n; i++) int N, W; int w[101], v[101]; int dp[101][100100]; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> w[i] >> v[i]; } rep(i, N) { rep(j, 100001) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= 100000; j++) { dp[i + 1][j] = dp[i][j]; if (j >= v[i + 1]) { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i + 1]] + w[i + 1]); } } } int min = INF; int i; int temp = 0; for (i = 0; i <= 100000; i++) { if (dp[N][i] <= W) { temp = i; } } cout << temp << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one" ]
971,420
971,421
u942850310
cpp
p03164
#include <bits/stdc++.h> #define MAXN 100005 #define inf 1000000000001 using namespace std; int main() { // freopen("t.txt","r",stdin); int n, W; long long w[111], v[111], maxv = 0; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; maxv += v[i]; } long long dp[maxv]; for (int i = 1; i <= maxv; i++) { dp[i] = inf; } for (int j = 1; j <= n; j++) { for (int i = maxv; i >= v[j]; i--) { dp[i] = min(dp[i], dp[i - v[j]] + w[j]); } } for (int i = maxv; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> #define MAXN 100005 #define inf 1000000000001 using namespace std; int main() { // freopen("t.txt","r",stdin); int n, W; long long w[111], v[111], maxv = 0; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; maxv += v[i]; } long long dp[100001]; for (int i = 1; i <= maxv; i++) { dp[i] = inf; } for (int j = 1; j <= n; j++) { for (int i = maxv; i >= v[j]; i--) { dp[i] = min(dp[i], dp[i - v[j]] + w[j]); } } for (int i = maxv; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; return 0; } } }
[ "identifier.replace.remove", "literal.replace.add", "variable_declaration.array_dimensions.change" ]
971,422
971,423
u386321778
cpp
p03164
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__) #else #define show(...) 42 #endif #define ff first #define ss second #define endl "\n" #define pb push_back #define two pair<int, int> #define ll long long int #define int long long int #define mod(x, m) ((x % m + m) % m) #define oo 1e15 #define all(v) v.begin(), v.end() #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #define rep(a1, b1, c1) for (int a1 = b1; a1 < c1; a1++) #define repb(a2, b2, c2) for (int a2 = b2; a2 >= c2; a2--) #define speedforces std::ios::sync_with_stdio(false) #define watch(x) cerr << (#x) << " is " << (x) << "\n" #define input_from_file freopen("input.txt", "r", stdin); #define output_to_file freopen("output.txt", "w", stdout); const int N = 200005; int dp[105][N]; signed main() { // input_from_file; speedforces; int n, W; cin >> n >> W; int w[n + 1], v[n + 1]; memset(dp, 0, sizeof dp); rep(i, 1, n + 1) cin >> w[i] >> v[i]; rep(i, 1, N) dp[0][i] = oo; rep(i, 1, n + 1) rep(j, 1, 100) { dp[i][j] = dp[i - 1][j]; if (v[i] <= j) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } int ans = 0; rep(i, 1, n + 1) rep(j, 1, 100) if (dp[i][j] <= W) ans = max(ans, j); cout << ans << endl; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifndef ONLINE_JUDGE #define show(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__) #else #define show(...) 42 #endif #define ff first #define ss second #define endl "\n" #define pb push_back #define two pair<int, int> #define ll long long int #define int long long int #define mod(x, m) ((x % m + m) % m) #define oo 1e15 #define all(v) v.begin(), v.end() #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #define rep(a1, b1, c1) for (int a1 = b1; a1 < c1; a1++) #define repb(a2, b2, c2) for (int a2 = b2; a2 >= c2; a2--) #define speedforces std::ios::sync_with_stdio(false) #define watch(x) cerr << (#x) << " is " << (x) << "\n" #define input_from_file freopen("input.txt", "r", stdin); #define output_to_file freopen("output.txt", "w", stdout); const int N = 200005; int dp[105][N]; signed main() { // input_from_file; speedforces; int n, W; cin >> n >> W; int w[n + 1], v[n + 1]; memset(dp, 0, sizeof dp); rep(i, 1, n + 1) cin >> w[i] >> v[i]; rep(i, 1, N) dp[0][i] = oo; rep(i, 1, n + 1) rep(j, 1, N) { dp[i][j] = dp[i - 1][j]; if (v[i] <= j) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } int ans = 0; rep(i, 1, n + 1) rep(j, 1, N) if (dp[i][j] <= W) ans = max(ans, j); cout << ans << endl; }
[ "identifier.replace.add", "literal.replace.remove", "call.arguments.change" ]
971,428
971,429
u520002141
cpp
p03164
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[110][100100]; void chmin(ll &a, ll b) { if (a > b) { a = b; } return; } const ll inf = 1LL << 60; int main() { ll max_v = 0; for (ll i = 0; i < 110; i++) { for (ll j = 0; j < 100100; j++) { dp[i][j] = inf; } } ll N, W; cin >> N >> W; vector<ll> w(N); vector<ll> v(N); for (ll i = 0; i < N; i++) { cin >> w[i] >> v[i]; max_v += v[i]; } dp[0][v[0]] = w[0]; dp[0][0] = 0; for (ll i = 0; i < N - 1; i++) { for (ll j = 0; j < 100100; j++) { chmin(dp[i + 1][j], dp[i][j]); if (j - v[j + 1] >= 0) { chmin(dp[i + 1][j], dp[i][j - v[i + 1]] + w[i + 1]); } } } ll res = 0; for (ll i = 0; i <= max_v; i++) { if (dp[N - 1][i] <= W) { res = i; } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll dp[110][100100]; void chmin(ll &a, ll b) { if (a > b) { a = b; } return; } const ll inf = 1LL << 60; int main() { ll max_v = 0; for (ll i = 0; i < 110; i++) { for (ll j = 0; j < 100100; j++) { dp[i][j] = inf; } } ll N, W; cin >> N >> W; vector<ll> w(N); vector<ll> v(N); for (ll i = 0; i < N; i++) { cin >> w[i] >> v[i]; max_v += v[i]; } dp[0][v[0]] = w[0]; dp[0][0] = 0; for (ll i = 0; i < N - 1; i++) { for (ll j = 0; j < 100100; j++) { chmin(dp[i + 1][j], dp[i][j]); if (j - v[i + 1] >= 0) { chmin(dp[i + 1][j], dp[i][j - v[i + 1]] + w[i + 1]); } } } ll res = 0; for (ll i = 0; i <= max_v; i++) { if (dp[N - 1][i] <= W) { res = i; } } cout << res << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
971,430
971,431
u904123392
cpp
p03164
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; #define INF (1e9) #define MOD (1e9 + 7) #define LINF (1e18) #define REP(i, n) for (int i = 0; i < (n); ++i) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() int main() { cin.tie(0); ios::sync_with_stdio(false); int n, max_w; cin >> n >> max_w; ll w[n], v[n]; REP(i, n) cin >> w[i] >> v[i]; ll max_v = 100000; // dp[i] : 価値iを作れるときの重さの最小値 vector<ll> dp(max_v + 1, INF); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = max_v; j >= 0; j--) { if (j - v[i - 1] >= 0) dp[j] = min(dp[j], dp[j - v[i - 1]] + w[i - 1]); } } ll ans = 0; for (int i = 0; i <= max_v; i++) { if (dp[i] <= max_w) ans = max(ans, (ll)i); } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; #define INF (1e9) #define MOD (1e9 + 7) #define LINF (1e18) #define REP(i, n) for (int i = 0; i < (n); ++i) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() int main() { cin.tie(0); ios::sync_with_stdio(false); int n, max_w; cin >> n >> max_w; ll w[n], v[n]; REP(i, n) cin >> w[i] >> v[i]; ll max_v = 100000; // dp[i] : 価値iを作れるときの重さの最小値 vector<ll> dp(max_v + 1, LINF); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = max_v; j >= 0; j--) { if (j - v[i - 1] >= 0) dp[j] = min(dp[j], dp[j - v[i - 1]] + w[i - 1]); } } ll ans = 0; for (int i = 0; i <= max_v; i++) { if (dp[i] <= max_w) ans = max(ans, (ll)i); } cout << ans << endl; }
[ "identifier.change", "call.arguments.change" ]
971,450
971,451
u858107870
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18L; int main() { ll n, w, sum_value = 0; cin >> n >> w; vector<ll> value(n), weight(n); for (int i = 0; i < n; i++) scanf("%lld %lld", &weight[i], &value[i]), sum_value += value[i]; vector<ll> dp(sum_value + 1, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int k = sum_value - value[i]; k >= 0; k--) dp[k + value[i]] = min(dp[k + value[i]], weight[i] + dp[k]); } ll ans = 0; for (int i = 0; i < sum_value; i++) if (dp[i] <= w) ans = max(ans, (ll)i); cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll INF = 1e18L; int main() { ll n, w, sum_value = 0; cin >> n >> w; vector<ll> value(n), weight(n); for (int i = 0; i < n; i++) scanf("%lld %lld", &weight[i], &value[i]), sum_value += value[i]; vector<ll> dp(sum_value + 1, INF); dp[0] = 0; for (int i = 0; i < n; i++) { for (int k = sum_value - value[i]; k >= 0; k--) dp[k + value[i]] = min(dp[k + value[i]], weight[i] + dp[k]); } ll ans = 0; for (int i = 0; i <= sum_value; i++) if (dp[i] <= w) ans = max(ans, (ll)i); cout << ans << "\n"; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,497
971,498
u234130745
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long int ll dp[1001][100]; bool vis[1001][100]; ll solve(ll y, ll i, ll n, ll w[], ll v[]) { if (y <= 0) return 0; if (i == n) return 1000000001; if (vis[y][i]) return dp[y][i]; vis[y][i] = 1; return dp[y][i] = min(solve(y, i + 1, n, w, v), w[i] + solve(y - v[i], i + 1, n, w, v)); } int main() { ll n, c; cin >> n >> c; ll w[n], v[n]; for (ll i = 0; i < n; i++) cin >> w[i] >> v[i]; for (ll j = 100; j >= 0; j--) { if (solve(j, 0, n, w, v) <= c) { cout << j; break; } } return 0; }
// LARGE WEIGHTS . #include <bits/stdc++.h> using namespace std; #define ll long long int ll dp[100001][100]; bool vis[100001][100]; ll solve(ll y, ll i, ll n, ll w[], ll v[]) { if (y <= 0) return 0; if (i == n) return 1000000001; if (vis[y][i]) return dp[y][i]; vis[y][i] = 1; return dp[y][i] = min(solve(y, i + 1, n, w, v), w[i] + solve(y - v[i], i + 1, n, w, v)); } int main() { ll n, c; cin >> n >> c; ll w[n], v[n]; for (ll i = 0; i < n; i++) cin >> w[i] >> v[i]; for (ll j = 100001; j >= 0; j--) { if (solve(j, 0, n, w, v) <= c) { cout << j; break; } } return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
971,499
971,500
u333958848
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define endl "\n"; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef pair<long long, long long> pll; typedef pair<pair<long long, long long>, bool> pllb; typedef pair<pair<ll, ll>, ll> plll; const ll N = 110; const ll INF = 1e17; const ll N2 = 1e5 + 10; const int MOD = 1e9 + 7; ll n, w; ll weight[N], val[N]; ll memo[N][N2]; ll dp(int idx, int v) { if (idx == n) { if (v == 0) return 0; else return 1e14; } ll &ret = memo[idx][v]; if (~ret) return ret; ret = dp(idx + 1, v); if (val[idx] <= v) ret = min(ret, dp(idx + 1, v - val[idx]) + weight[idx]); } int main() { fastio #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("out.txt","w",stdout); #endif memset(memo, -1, sizeof memo); cin >> n >> w; int sum = 0; for (int i = 0; i < n; i++) { cin >> weight[i] >> val[i]; sum += val[i]; } ll ans = 0; for (int i = 0; i <= sum; i++) { ll temp = dp(0, i); if (temp <= w) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define endl "\n"; #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef pair<long long, long long> pll; typedef pair<pair<long long, long long>, bool> pllb; typedef pair<pair<ll, ll>, ll> plll; const ll N = 110; const ll INF = 1e17; const ll N2 = 1e5 + 10; const int MOD = 1e9 + 7; ll n, w; ll weight[N], val[N]; ll memo[N][N2]; ll dp(int idx, int v) { if (idx == n) { if (v == 0) return 0; else return 1e14; } ll &ret = memo[idx][v]; if (~ret) return ret; ret = dp(idx + 1, v); if (val[idx] <= v) ret = min(ret, dp(idx + 1, v - val[idx]) + weight[idx]); return ret; } int main() { fastio #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("out.txt","w",stdout); #endif memset(memo, -1, sizeof memo); cin >> n >> w; int sum = 0; for (int i = 0; i < n; i++) { cin >> weight[i] >> val[i]; sum += val[i]; } ll ans = 0; for (int i = 0; i <= sum; i++) { ll temp = dp(0, i); if (temp <= w) ans = i; } cout << ans << endl; }
[ "control_flow.return.add" ]
971,534
971,535
u271163543
cpp
p03164
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 62; int main() { int N, W; cin >> N >> W; int w[N], v[N]; for (int i = 0; i < N; ++i) cin >> w[i] >> v[i]; long long dp[100001]; // dp[j] = 価値がちょうど j // となるように選んだときの重さの最小値(配列再利用をするので // i 番目という情報は入っていない) for (int j = 0; j < 100001; ++j) dp[j] = INF; dp[0] = 0; for (int i = 1; i <= N; ++i) { for (int j = 0; j < 100001; ++j) { if (j - v[i - 1] >= 0) dp[j] = min(dp[j], dp[j - v[i - 1]] + w[i - 1]); // i 番目の商品を入れるか入れないか } } long long ans; for (int j = 0; j < 100001; ++j) { if (dp[j] <= W) ans = j; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 62; int main() { int N, W; cin >> N >> W; int w[N], v[N]; for (int i = 0; i < N; ++i) cin >> w[i] >> v[i]; long long dp[100001]; // dp[j] = 価値がちょうど j // となるように選んだときの重さの最小値(配列再利用をするので // i 番目という情報は入っていない) for (int j = 0; j < 100001; ++j) dp[j] = INF; dp[0] = 0; for (int i = 1; i <= N; ++i) { for (int j = 100000; j >= 0; --j) { if (j - v[i - 1] >= 0) dp[j] = min(dp[j], dp[j - v[i - 1]] + w[i - 1]); // i 番目の商品を入れるか入れないか } } long long ans; for (int j = 0; j < 100001; ++j) { if (dp[j] <= W) ans = j; } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "control_flow.loop.for.condition.change" ]
971,547
971,548
u657901243
cpp
p03164
#include <bits/stdc++.h> using namespace std; long long dp[110][100100]; int main() { long long n, w; cin >> n >> w; vector<long long> weight(n), value(n); long long v = 100100; for (long long i = 0; i < n; ++i) { cin >> weight[i] >> value[i]; } for (long long i = 0; i < 110; ++i) { for (long long j = 0; j < 100100; ++j) { dp[i][j] = 1LL << 60; } } dp[0][0] = 0; for (long long i = 0; i < n; ++i) { for (long long j = 0; j < v; ++j) { if (j >= value[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - value[i]] + weight[i]); else dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } long long cal = 0; for (long long i = 0; i < v; ++i) { if (dp[n][i] <= w) cal = i; } cout << cal << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long dp[110][100100]; int main() { long long n, w; cin >> n >> w; vector<long long> weight(n), value(n); long long v = 100100; for (long long i = 0; i < n; ++i) { cin >> weight[i] >> value[i]; } for (long long i = 0; i < 110; ++i) { for (long long j = 0; j < 100100; ++j) { dp[i][j] = 1LL << 60; } } dp[0][0] = 0; for (long long i = 0; i < n; ++i) { for (long long j = 0; j < v; ++j) { if (j >= value[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - value[i]] + weight[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } long long cal = 0; for (long long i = 0; i < v; ++i) { if (dp[n][i] <= w) cal = i; } cout << cal << endl; return 0; }
[ "control_flow.branch.else.remove" ]
971,551
971,552
u144029820
cpp
p03164
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define repi(i, a, b) for (int i = a; i <= (b); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define mp make_pair #define to_s to_string #define sz(v) (int)v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define pr(x) cout << (x) << '\n' #define debug(x) cout << #x << ": " << (x) << '\n' #define yes "Yes" #define no "No" using namespace std; using ll = long long; using Edge = pair<int, long long>; using Graph = vector<vector<Edge>>; typedef pair<int, int> P; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int MOD = 1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll DP[105][100005]; int main() { int N, W; cin >> N >> W; vector<ll> w(N + 1), v(N + 1); rep1(i, N) cin >> w[i] >> v[i]; rep(j, 100005) DP[0][j] = 1e9; DP[0][0] = 0; rep1(i, N) rep(j, 100005) { 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]; } rrep(i, 100004) if (DP[N][i] <= W) { pr(i); return 0; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define repi(i, a, b) for (int i = a; i <= (b); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define mp make_pair #define to_s to_string #define sz(v) (int)v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define pr(x) cout << (x) << '\n' #define debug(x) cout << #x << ": " << (x) << '\n' #define yes "Yes" #define no "No" using namespace std; using ll = long long; using Edge = pair<int, long long>; using Graph = vector<vector<Edge>>; typedef pair<int, int> P; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int MOD = 1e9 + 7; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; ll DP[105][100005]; int main() { int N, W; cin >> N >> W; vector<ll> w(N + 1), v(N + 1); rep1(i, N) cin >> w[i] >> v[i]; rep(j, 100005) DP[0][j] = 1e12; DP[0][0] = 0; rep1(i, N) rep(j, 100005) { 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]; } rrep(i, 100004) if (DP[N][i] <= W) { pr(i); return 0; } }
[ "literal.number.change", "assignment.value.change" ]
971,577
971,578
u281168735
cpp
p03164
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define repi(i, a, b) for (int i = a; i <= (b); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define mp make_pair #define to_s to_string #define sz(v) (int)v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define pr(x) cout << (x) << '\n' #define debug(x) cout << #x << ": " << (x) << '\n' #define yes "Yes" #define no "No" using ll = long long; using namespace std; typedef pair<int, int> P; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int MOD = 1e9 + 7; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return (a * b) / gcd(a, b); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int N, W; ll dp[110][100005]; int main() { cin >> N >> W; vector<ll> w(N + 1), v(N + 1); rep1(i, N) cin >> w[i] >> v[i]; rep(i, 100005) dp[0][i] = 1e9; dp[0][0] = 0; rep1(i, N) rep(j, 100005) { 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]; } rrep(i, 100005) if (dp[N][i] <= W) { pr(i); return 0; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define repi(i, a, b) for (int i = a; i <= (b); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define mp make_pair #define to_s to_string #define sz(v) (int)v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define pr(x) cout << (x) << '\n' #define debug(x) cout << #x << ": " << (x) << '\n' #define yes "Yes" #define no "No" using ll = long long; using namespace std; typedef pair<int, int> P; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int MOD = 1e9 + 7; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return (a * b) / gcd(a, b); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int N, W; ll dp[110][100005]; int main() { cin >> N >> W; vector<ll> w(N + 1), v(N + 1); rep1(i, N) cin >> w[i] >> v[i]; rep(i, 100005) dp[0][i] = 1e9 + 100; dp[0][0] = 0; rep1(i, N) rep(j, 100005) { 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]; } rrep(i, 100004) if (dp[N][i] <= W) { pr(i); return 0; } }
[ "assignment.change", "literal.number.change", "call.arguments.change" ]
971,581
971,580
u281168735
cpp
p03164
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define repi(i, a, b) for (int i = a; i <= (b); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define mp make_pair #define to_s to_string #define sz(v) (int)v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define pr(x) cout << (x) << '\n' #define debug(x) cout << #x << ": " << (x) << '\n' #define yes "Yes" #define no "No" using ll = long long; using namespace std; typedef pair<int, int> P; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int MOD = 1e9 + 7; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return (a * b) / gcd(a, b); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int N, W; ll dp[110][100005]; int main() { cin >> N >> W; vector<ll> w(N + 1), v(N + 1); rep1(i, N) cin >> w[i] >> v[i]; rep(i, 100005) dp[0][i] = 1e9; dp[0][0] = 0; rep1(i, N) rep(j, 100006) { 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]; } rrep(i, 100005) if (dp[N][i] <= W) { pr(i); return 0; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define repi(i, a, b) for (int i = a; i <= (b); ++i) #define rrep(i, n) for (int i = (n - 1); i >= 0; --i) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define pb push_back #define mp make_pair #define to_s to_string #define sz(v) (int)v.size() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define pr(x) cout << (x) << '\n' #define debug(x) cout << #x << ": " << (x) << '\n' #define yes "Yes" #define no "No" using ll = long long; using namespace std; typedef pair<int, int> P; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); }; } aaaaaaa; int MOD = 1e9 + 7; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return (a * b) / gcd(a, b); } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; int N, W; ll dp[110][100005]; int main() { cin >> N >> W; vector<ll> w(N + 1), v(N + 1); rep1(i, N) cin >> w[i] >> v[i]; rep(i, 100005) dp[0][i] = 1e9 + 100; dp[0][0] = 0; rep1(i, N) rep(j, 100005) { 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]; } rrep(i, 100004) if (dp[N][i] <= W) { pr(i); return 0; } }
[ "assignment.change", "literal.number.change", "call.arguments.change" ]
971,582
971,580
u281168735
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll int n, w1; cin >> n >> w1; ll int w[n + 1], v[n + 1], sum = 0; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; sum += v[i]; } vector<ll int> dp(sum + 1); dp[0] = 0; for (int i = 1; i <= n; i++) { for (ll int j = sum - v[i]; j >= 0; j -= 1) { dp[j + v[i]] = min(dp[j + v[i]], w[i] + dp[j]); } } ll int ans = 0; for (ll int i = sum; i >= 0; i -= 1) { if (dp[i] <= w1) { ans = max(ans, i); } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ll int n, w1; cin >> n >> w1; ll int w[n + 1], v[n + 1], sum = 0; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; sum += v[i]; } vector<ll int> dp(sum + 1, 1000000000); dp[0] = 0; for (int i = 1; i <= n; i++) { for (ll int j = sum - v[i]; j >= 0; j -= 1) { dp[j + v[i]] = min(dp[j + v[i]], w[i] + dp[j]); } } ll int ans = 0; for (ll int i = sum; i >= 0; i -= 1) { if (dp[i] <= w1) { ans = max(ans, i); } } cout << ans; return 0; }
[ "call.arguments.add" ]
971,589
971,590
u452579095
cpp
p03164
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define MOD 1000000007 #define INF (1 << 29) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) Int dp[108000]; Int N, W, w, v; int main() { cin >> N >> W; fill(dp, dp + 108000, INF); dp[0] = 0; for (Int i = 0; i < N; i++) { cin >> w >> v; for (Int j = 108000; j - v >= 0; j--) { dp[j] = min(dp[j], dp[j - v] + w); } } Int ans; for (Int i = 0; i < 108000; i++) if (dp[i] <= W) ans = i; cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define MOD 1000000007 #define INF (1LL << 60) #define EPS (1e-10) typedef long long Int; typedef pair<Int, Int> P; #define max(x, y) ((x) > (y) ? (x) : (y)) #define min(x, y) ((x) < (y) ? (x) : (y)) Int dp[108000]; Int N, W, w, v; int main() { cin >> N >> W; fill(dp, dp + 108000, INF); dp[0] = 0; for (Int i = 0; i < N; i++) { cin >> w >> v; for (Int j = 108000; j - v >= 0; j--) { dp[j] = min(dp[j], dp[j - v] + w); } } Int ans; for (Int i = 0; i < 108000; i++) if (dp[i] <= W) ans = i; cout << ans << endl; return 0; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
971,591
971,592
u299869545
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MAX_N 100 #define MAX_V 1000 #define INF 1000000000 ll dp[MAX_N][MAX_V * MAX_N + 1]; // dp[n][v]: // n番目までの品物を用いて価値の総和をvとした時の重さの最小値(vとならない場合は十分大きな数INF) vector<ll> wei(MAX_N), val(MAX_N); void knapsack(int n, ll v) { if (v == 0) dp[n][v] = 0; else if (n >= 1) { if (v - val.at(n) >= 0) { dp[n][v] = min(dp[n - 1][v - val.at(n)] + wei.at(n), dp[n - 1][v]); } else dp[n][v] = dp[n - 1][v]; } else { if (v == val.at(n)) dp[n][v] = wei.at(n); else dp[n][v] = INF; } } int main() { int N, W; cin >> N >> W; for (int i = 0; i < N; i++) { cin >> wei.at(i) >> val.at(i); } for (int i = 0; i < N; i++) { for (ll j = 0; j <= MAX_N * MAX_V; j++) { knapsack(i, j); } } int res = 0; for (ll i = 0; i <= MAX_N * MAX_V; i++) { if (dp[N - 1][i] <= W) res = i; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MAX_N 100 #define MAX_V 1000 #define INF 10000000000 ll dp[MAX_N][MAX_V * MAX_N + 1]; // dp[n][v]: // n番目までの品物を用いて価値の総和をvとした時の重さの最小値(vとならない場合は十分大きな数INF) vector<ll> wei(MAX_N), val(MAX_N); void knapsack(int n, ll v) { if (v == 0) dp[n][v] = 0; else if (n >= 1) { if (v - val.at(n) >= 0) { dp[n][v] = min(dp[n - 1][v - val.at(n)] + wei.at(n), dp[n - 1][v]); } else dp[n][v] = dp[n - 1][v]; } else { if (v == val.at(n)) dp[n][v] = wei.at(n); else dp[n][v] = INF; } } int main() { int N, W; cin >> N >> W; for (int i = 0; i < N; i++) { cin >> wei.at(i) >> val.at(i); } for (int i = 0; i < N; i++) { for (ll j = 0; j <= MAX_N * MAX_V; j++) { knapsack(i, j); } } int res = 0; for (ll i = 0; i <= MAX_N * MAX_V; i++) { if (dp[N - 1][i] <= W) res = i; } cout << res << endl; }
[ "preprocessor.define.value.change", "literal.integer.change" ]
971,595
971,596
u044638697
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<pair<long long int, long long int>> v; long long int count = 0; for (long long int i = 0; i < n; i++) { long long int l, p; cin >> l >> p; v.push_back(make_pair(p, l)); count += p; } sort(v.begin(), v.end()); long long int arr[n + 1][count + 1]; long long int q = 0; for (long long int i = 0; i <= n; i++) { for (long long int j = 0; j <= count; j++) { if (j == 0 || i == 0) { arr[i][j] = 1e18; } else if (v[i - 1].first > j) { arr[i][j] = arr[i - 1][j]; } else if (v[i - 1].first == j) { arr[i][j] = min(v[i - 1].first, arr[i - 1][j]); } else { long long int x = v[i - 1].second + arr[i - 1][j - v[i - 1].first]; arr[i][j] = min(x, arr[i - 1][j]); } if (arr[i][j] <= k) { q = max(q, j); } } } cout << q; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<pair<long long int, long long int>> v; long long int count = 0; for (long long int i = 0; i < n; i++) { long long int l, p; cin >> l >> p; v.push_back(make_pair(p, l)); count += p; } sort(v.begin(), v.end()); long long int arr[n + 1][count + 1]; long long int q = 0; for (long long int i = 0; i <= n; i++) { for (long long int j = 0; j <= count; j++) { if (j == 0 || i == 0) { arr[i][j] = 1e18; } else if (v[i - 1].first > j) { arr[i][j] = arr[i - 1][j]; } else if (v[i - 1].first == j) { arr[i][j] = min(v[i - 1].second, arr[i - 1][j]); } else { long long int x = v[i - 1].second + arr[i - 1][j - v[i - 1].first]; arr[i][j] = min(x, arr[i - 1][j]); } if (arr[i][j] <= k) { q = max(q, j); } } } cout << q; return 0; }
[ "assignment.value.change", "call.arguments.change" ]
971,622
971,623
u483145617
cpp
p03164
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; //#include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> #define REVERSE(v) reverse(ALL(v)) #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl #define debug cerr << "bhau" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } //#define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } #define INF 1e11L int solve() { int n, W; cin >> n >> W; vi w(n), v(n); rep0(n) cin >> w[i] >> v[i]; int sum_value = 0; for (int i = 0; i < n; i++) sum_value += v[i]; vi dp(sum_value + 100, INF); // dp[i] contain minimum weight contained with total value i dp[0] = 0; for (int item = 0; item < n; item++) { for (int value = sum_value - v[item]; value >= 0; value--) { dp[value + v[item]] = min(dp[value + v[item]], dp[value] + w[item]); } } int ans = 0; for (int i = 0; i <= sum_value; i++) { if (dp[i] <= W) ans = max(ans, i); } cout << ans; r0 } signed main() { asdf inputoutput int t = 1; // cin>>t; while (t--) { solve(); } }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse2") /* |||||||||||||||||||||||||||||||||||||||||||||||| | ||| | |||| |||| | | | | | | | | | | | | | | | | | | | | | | | | ||||||| | | ||||||| ||| ||| ||||| | | | | | | | | | | | | | ||| | | | || |||| | | |||||||||||||||||||||||||||||||||||||||||||||||| */ using namespace std; //#include "testlib.h" #define ff first #define ss second #define mp make_pair #define all(v) v.begin(), v.end() #define int long long #define ll long long #define M 1000000007 #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define mii map<ll, ll> #define msi map<string, ll> #define mis map<ll int, string> #define rep(a, b) for (ll i = a; i < b; i++) #define rep0(n) for (ll i = 0; i < n; i++) #define repi(i, a, b) for (ll i = a; i < b; i++) #define pb push_back #define vi vector<ll> #define mp make_pair #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i) #define FORE(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define inputoutput \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); #define input freopen("input.txt", "r", stdin); #define Set(a, s) 4(a, s, sizeof(a)) #define FOR repi #define pii pair<int, int> #define REVERSE(v) reverse(ALL(v)) #define display(x) \ trav(a, x) cout << a << " "; \ cout << endl #define debug cerr << "bhau" << endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); std::cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } //#define float long double ll max(ll a, ll b) { return (a > b) ? a : b; } int min(int a, int b) { return (a < b) ? a : b; } #define INF 1e11L int solve() { int n, W; cin >> n >> W; vi w(n), v(n); rep0(n) cin >> w[i] >> v[i]; int sum_value = 0; for (int i = 0; i < n; i++) sum_value += v[i]; vi dp(sum_value + 100, INF); // dp[i] contain minimum weight contained with total value i dp[0] = 0; for (int item = 0; item < n; item++) { for (int value = sum_value - v[item]; value >= 0; value--) { dp[value + v[item]] = min(dp[value + v[item]], dp[value] + w[item]); } } int ans = 0; for (int i = 0; i <= sum_value; i++) { if (dp[i] <= W) ans = max(ans, i); } cout << ans; r0 } signed main() { asdf // inputoutput int t = 1; // cin>>t; while (t--) { solve(); } }
[]
971,626
971,627
u980932400
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0, sum = 0; int n, W; int sumV = 0, maxV = 0; cin >> n >> W; int w[n + 1], v[n + 1]; w[0] = 0; v[0] = 0; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; sumV += v[i]; } int dp[sumV + 1][n + 1]; for (int i = 0; i < sumV; i++) { for (int j = 0; j < n + 1; j++) { dp[i][j] = W + 1; } } dp[0][0] = 0; for (int i = 0; i < sumV; i++) { for (int j = 1; j < n + 1; j++) { if (i - v[j] >= 0) { dp[i][j] = min(dp[i - v[j]][j - 1] + w[j], dp[i][j - 1]); } else { dp[i][j] = dp[i][j - 1]; } if (dp[i][j] <= W) { maxV = max(i, maxV); } } } // cout <<fixed<<setprecision(16)<< << endl; cout << maxV << endl; // if(flag==1)cout << "Yes" <<endl; // else cout << "No" <<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int ans = 0, sum = 0; int n, W; int sumV = 0, maxV = 0; cin >> n >> W; int w[n + 1], v[n + 1]; w[0] = 0; v[0] = 0; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; sumV += v[i]; } int dp[sumV + 1][n + 1]; for (int i = 0; i < sumV + 1; i++) { for (int j = 0; j < n + 1; j++) { dp[i][j] = W + 1; } } dp[0][0] = 0; for (int i = 0; i < sumV + 1; i++) { for (int j = 1; j < n + 1; j++) { if (i - v[j] >= 0) { dp[i][j] = min(dp[i - v[j]][j - 1] + w[j], dp[i][j - 1]); } else { dp[i][j] = dp[i][j - 1]; } if (dp[i][j] <= W) { maxV = max(i, maxV); } } } // cout <<fixed<<setprecision(16)<< << endl; cout << maxV << endl; // if(flag==1)cout << "Yes" <<endl; // else cout << "No" <<endl; return 0; }
[ "control_flow.loop.for.condition.change", "misc.off_by_one" ]
971,632
971,633
u355424600
cpp
p03164
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i]; } for (int i = 0; i < 105; i++) for (int j = 0; j < 100005; j++) dp[i][j] = 1e12; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i + 1]; } for (int i = 0; i < 105; i++) for (int j = 0; j < 100005; j++) dp[0][j] = 1e12; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
[ "assignment.change", "assignment.variable.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change" ]
971,634
971,635
u961439650
cpp
p03164
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i]; } for (int j = 0; j <= v; j++) dp[0][j] = 2e10; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i + 1]; } for (int j = 0; j <= v; j++) dp[0][j] = 2e10; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
[ "assignment.change" ]
971,636
971,637
u961439650
cpp
p03164
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i]; } for (int j = 0; j <= v; j++) dp[0][j] = 1e12; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i + 1]; } for (int j = 0; j <= v; j++) dp[0][j] = 2e10; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
[ "assignment.change", "literal.number.change", "assignment.value.change" ]
971,638
971,637
u961439650
cpp
p03164
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i]; } for (int j = 0; j < 100005; j++) dp[0][j] = 1e12; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
// This code is solely the property of StarnyC #include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define hell 1000000007 #define hellx 998244353 #define pb push_back #define mp make_pair #define reset(a, b) memset(a, b, sizeof(a)) #define Go_Baby_Go \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); \ cerr.tie(0); #define deb(x) cout << (#x) << " is " << (x) << endl; #define F first #define S second #define pii pair<ll, ll> #define all(c) (c).begin(), (c).end() bool secsort(const pii &a, const pii &b) { return a < b; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll binexp(ll x, ll n, ll m) { if (!n) return 1; else if (n & 1) return (x % m) * binexp((x % m) * (x % m), n / 2, m) % m; else if (!(n & 1)) return binexp((x % m) * (x % m), n / 2, m) % m; return 0; } int val[105]; int weight[105]; int dp[105][100005]; int32_t solve(ll _, ll _t) { int n, W, v = 0; cin >> n >> W; for (int i = 0; i < n; ++i) { cin >> weight[i + 1] >> val[i + 1]; v += val[i + 1]; } for (int j = 0; j <= v; j++) dp[0][j] = 2e10; dp[0][0] = 0; ll ans = 0; // cout<<fun(n-1,0,W)<<endl; for (int i = 1; i <= n; i++) for (int j = 1; j <= v; j++) { if (j - val[i] >= 0) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - val[i]] + weight[i]); else dp[i][j] = dp[i - 1][j]; if (ans < j && dp[i][j] <= W) ans = j; } // for(int i=0;i<n;i++) // { for(int j=0;j<20;j++) // cout<<dp[i][j]<<" "; // cout<<endl;} cout << ans; return 0; } int32_t main() { Go_Baby_Go // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << // " ms" ; ll _ = 1; // cin>>_; ll _t = _; while (_--) solve(_, _t); }
[ "assignment.change", "control_flow.loop.for.condition.change", "literal.number.change", "assignment.value.change" ]
971,639
971,637
u961439650
cpp
p03164
#include "bits/stdc++.h" #define int long long #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (a); i < (b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) using namespace std; const int MAX_N = 100, MAX_V = 100000; int N, W; vector<int> w, v; int dp[MAX_N + 1][MAX_V + 1]; signed main() { cin >> N >> W; w.resize(N); v.resize(N); rep(i, N) cin >> w[i] >> v[i]; rep(i, N + 1) rep(j, MAX_V) { dp[i][j] = INT_MAX; } dp[N][0] = 0; int ans = 0; for (int i = N - 1; i >= 0; --i) rep(j, MAX_V + 1) { if (j - v[i] >= 0) dp[i][j] = min(dp[i + 1][j - v[i]] + w[i], dp[i + 1][j]); else dp[i][j] = dp[i + 1][j]; if (i == 0 && dp[i][j] <= W) ans = max(ans, j); } cout << ans << endl; }
#include "bits/stdc++.h" #define int long long #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (a); i < (b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) using namespace std; const int MAX_N = 100, MAX_V = 100000; int N, W; vector<int> w, v; int dp[MAX_N + 1][MAX_V + 1]; signed main() { cin >> N >> W; w.resize(N); v.resize(N); rep(i, N) cin >> w[i] >> v[i]; rep(i, N + 1) rep(j, MAX_V + 1) { dp[i][j] = INT_MAX; } dp[N][0] = 0; int ans = 0; for (int i = N - 1; i >= 0; --i) rep(j, MAX_V + 1) { if (j - v[i] >= 0) dp[i][j] = min(dp[i + 1][j - v[i]] + w[i], dp[i + 1][j]); else dp[i][j] = dp[i + 1][j]; if (i == 0 && dp[i][j] <= W) ans = max(ans, j); } cout << ans << endl; }
[ "expression.operation.binary.add" ]
971,640
971,641
u203033720
cpp
p03164
#include <bits/stdc++.h> using namespace std; // repetition #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) // container util #define all(x) (x).begin(), (x).end() // typedef typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline ll toLL(string s) { ll v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const ll INF = 1e10; ll dp[110][100100]; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, W; cin >> N >> W; VI w(N), v(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(i, N + 1) rep(j, 100100) dp[i][j] = INF; dp[0][0] = 0; rep(i, N) { rep(j, 100100) { if (dp[i][j] + w[i] <= W) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } } // rep(i,N+1){ // rep(j,100){ // if(dp[i][j] == INF) cout << "- "; // else cout << dp[i][j] << ' '; // } // cout << endl; // } for (int i = 100010; i >= 0; i--) { if (dp[N][i] != INF) { cout << i << endl; return 0; } } cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // repetition #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) // container util #define all(x) (x).begin(), (x).end() // typedef typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline ll toLL(string s) { ll v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const ll INF = 1e10; ll dp[110][100100]; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, W; cin >> N >> W; VI w(N), v(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(i, N + 1) rep(j, 100100) dp[i][j] = INF; dp[0][0] = 0; rep(i, N) { rep(j, 100100) { if (dp[i][j] + w[i] <= W) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } // rep(i,N+1){ // rep(j,100){ // if(dp[i][j] == INF) cout << "- "; // else cout << dp[i][j] << ' '; // } // cout << endl; // } for (int i = 100010; i >= 0; i--) { if (dp[N][i] != INF) { cout << i << endl; return 0; } } cout << 0 << endl; return 0; }
[]
971,643
971,644
u336011173
cpp
p03164
#include <bits/stdc++.h> using namespace std; // repetition #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) // container util #define all(x) (x).begin(), (x).end() // typedef typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline ll toLL(string s) { ll v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const ll INF = 1e10; ll dp[100][100100]; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, W; cin >> N >> W; VI w(N), v(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(i, N + 1) rep(j, 100100) dp[i][j] = INF; dp[0][0] = 0; rep(i, N) { rep(j, 100100) { if (dp[i][j] + w[i] <= W) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } } // rep(i,N+1){ // rep(j,100){ // if(dp[i][j] == INF) cout << "- "; // else cout << dp[i][j] << ' '; // } // cout << endl; // } for (int i = 100010; i >= 0; i--) { if (dp[N][i] != INF) { cout << i << endl; return 0; } } cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // repetition #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) // container util #define all(x) (x).begin(), (x).end() // typedef typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; // conversion inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline ll toLL(string s) { ll v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const ll INF = 1e10; ll dp[110][100100]; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, W; cin >> N >> W; VI w(N), v(N); rep(i, N) { cin >> w[i] >> v[i]; } rep(i, N + 1) rep(j, 100100) dp[i][j] = INF; dp[0][0] = 0; rep(i, N) { rep(j, 100100) { if (dp[i][j] + w[i] <= W) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } // rep(i,N+1){ // rep(j,100){ // if(dp[i][j] == INF) cout << "- "; // else cout << dp[i][j] << ' '; // } // cout << endl; // } for (int i = 100010; i >= 0; i--) { if (dp[N][i] != INF) { cout << i << endl; return 0; } } cout << 0 << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
971,645
971,644
u336011173
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll maxn = 100005; ll dp[101][100000]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll n, W; cin >> n >> W; vector<pair<ll, ll>> v; for (int i = 0; i < n; i++) { ll w, va; cin >> w >> va; v.push_back({w, va}); } for (ll j = 1; j <= maxn; j++) { dp[0][j] = (ll)(1e18); } for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= maxn; j++) { if (j >= v[i - 1].second) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1].second] + v[i - 1].first); else dp[i][j] = dp[i - 1][j]; } } ll ans = 0; for (ll j = 1; j <= maxn; j++) { if (dp[n][j] <= W) ans = max(ans, j); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll maxn = 100005; ll dp[101][maxn + 1]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll n, W; cin >> n >> W; vector<pair<ll, ll>> v; for (int i = 0; i < n; i++) { ll w, va; cin >> w >> va; v.push_back({w, va}); } for (ll j = 1; j <= maxn; j++) { dp[0][j] = (ll)(1e18); } for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= maxn; j++) { if (j >= v[i - 1].second) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1].second] + v[i - 1].first); else dp[i][j] = dp[i - 1][j]; } } ll ans = 0; for (ll j = 1; j <= maxn; j++) { if (dp[n][j] <= W) ans = max(ans, j); } cout << ans << endl; }
[ "identifier.replace.add", "literal.replace.remove" ]
971,648
971,649
u673058289
cpp
p03164
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll maxn = 100005; ll dp[101][100000]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll n, W; cin >> n >> W; vector<pair<ll, ll>> v; for (int i = 0; i < n; i++) { ll w, va; cin >> w >> va; v.push_back({w, va}); } for (ll j = 1; j <= maxn; j++) { dp[0][j] = (ll)(1e18); } for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= maxn; j++) { if (j >= v[i - 1].second) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1].second] + v[i - 1].first); else dp[i][j] = dp[i - 1][j]; } } ll ans = 0; for (ll j = 1; j <= maxn; j++) { if (dp[n][j] <= W) ans = max(ans, j); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll maxn = 100005; ll dp[101][111111]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll n, W; cin >> n >> W; vector<pair<ll, ll>> v; for (int i = 0; i < n; i++) { ll w, va; cin >> w >> va; v.push_back({w, va}); } for (ll j = 1; j <= maxn; j++) { dp[0][j] = (ll)(1e18); } for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= maxn; j++) { if (j >= v[i - 1].second) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1].second] + v[i - 1].first); else dp[i][j] = dp[i - 1][j]; } } ll ans = 0; for (ll j = 1; j <= maxn; j++) { if (dp[n][j] <= W) ans = max(ans, j); } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
971,648
971,650
u673058289
cpp
p03164
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n, W, w, v, ans = 0; cin >> n >> W; vector<long long int> v1, v2; for (i = 0; i < n; i++) { cin >> w >> v; v1.push_back(w); v2.push_back(v); } long long int dp[100010]; for (i = 0; i < 100000; i++) dp[i] = 1e10; dp[0] = 0; for (i = 0; i < n; i++) for (j = 100000; j >= v2[i]; j--) { dp[j] = min(dp[j], v1[i] + dp[j - v2[i]]); if (dp[j] <= W) ans = max(ans, j); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n, W, w, v, ans = 0; cin >> n >> W; vector<long long int> v1, v2; for (i = 0; i < n; i++) { cin >> w >> v; v1.push_back(w); v2.push_back(v); } long long int dp[100010]; for (i = 0; i <= 100000; i++) dp[i] = 1e10; dp[0] = 0; for (i = 0; i < n; i++) for (j = 100000; j >= v2[i]; j--) { dp[j] = min(dp[j], v1[i] + dp[j - v2[i]]); if (dp[j] <= W) ans = max(ans, j); } cout << ans << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
971,655
971,656
u815320324
cpp
p03164
#include <algorithm> #include <bits/stdc++.h> #include <deque> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define INF 1LL << 40; #define MOD 1000000007; #define ll long long #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define prique priority_queue typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<ll> vl; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; }; template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; }; struct edge { int to, cost; }; int dp[101][1001000]; int main() { int n, weight; cin >> n >> weight; vector<int> w(n), v(n); rep(i, n) cin >> w[i] >> v[i]; rep(i, n + 1) { rep(j, 100100) { dp[i][j] = 1000000000 * 2; } } dp[0][0] = 0; rep(i, n) { rep(j, 100010) { chmin(dp[i + 1][j], dp[i][j]); if (j + v[i] < 100100) { chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } } int ans = 0; rep(i, n + 1) { rep(j, 100010) { if (dp[i][j] <= weight) { chmax(ans, j); } } } cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <deque> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #define INF 1LL << 40; #define MOD 1000000007; #define ll long long #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) #define prique priority_queue typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<ll> vl; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; }; template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; }; struct edge { int to, cost; }; int dp[101][1001000]; int main() { int n, weight; cin >> n >> weight; vector<int> w(n), v(n); rep(i, n) cin >> w[i] >> v[i]; rep(i, n + 1) { rep(j, 100100) { dp[i][j] = 1000010000; } } dp[0][0] = 0; rep(i, n) { rep(j, 100010) { chmin(dp[i + 1][j], dp[i][j]); if (j + v[i] < 100100) { chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } } int ans = 0; rep(i, n + 1) { rep(j, 100010) { if (dp[i][j] <= weight) { chmax(ans, j); } } } cout << ans << endl; }
[ "literal.number.change", "assignment.value.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
971,659
971,660
u143509139
cpp
p03164
#include <algorithm> #include <bitset> #include <cassert> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <vector> using namespace std; typedef unsigned int uint; typedef long long llong; typedef unsigned long long ullong; typedef long double ldouble; typedef vector<llong> vecllong; typedef vector<vecllong> vvecllong; template <class T> inline bool chmin(T &to, T compare) { if (to > compare) { to = compare; return true; } return false; }; template <class T> inline bool chmax(T &to, T compare) { if (to < compare) { to = compare; return true; } return false; }; const llong MOD = 1e9 + 7; const llong INF = 1e18; #define FOR(i, n) for (llong i = 0; i < n; i++) #define FORS(i, a, b) for (llong i = a; i < b; i++) #define FORR(i, n) for (llong i = n; i > 0; i++) int main(void) { cin.tie(0); ios::sync_with_stdio(false); llong N, W; cin >> N >> W; vecllong weight(N + 1, 0); vecllong value(N + 1, 0); llong maxValue = 0; FOR(i, N) { cin >> weight[i] >> value[i]; maxValue += weight[i]; } vvecllong dp(N + 1, vecllong(maxValue + 1, INF)); // dp[i][value] = minWeight dp[0][0] = 0; FOR(i, N) { FOR(v, maxValue + 1) { if (v - value[i] >= 0) { dp[i + 1][v] = min({dp[i][v - value[i]] + weight[i], dp[i][v], dp[i + 1][v]}); } else { dp[i + 1][v] = dp[i][v]; } } } llong ans = 0; for (llong v = maxValue; v >= 0; v--) { if (dp[N][v] <= W) { ans = v; break; } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <vector> using namespace std; typedef unsigned int uint; typedef long long llong; typedef unsigned long long ullong; typedef long double ldouble; typedef vector<llong> vecllong; typedef vector<vecllong> vvecllong; template <class T> inline bool chmin(T &to, T compare) { if (to > compare) { to = compare; return true; } return false; }; template <class T> inline bool chmax(T &to, T compare) { if (to < compare) { to = compare; return true; } return false; }; const llong MOD = 1e9 + 7; const llong INF = 1e18; #define FOR(i, n) for (llong i = 0; i < n; i++) #define FORS(i, a, b) for (llong i = a; i < b; i++) #define FORR(i, n) for (llong i = n; i > 0; i++) int main(void) { cin.tie(0); ios::sync_with_stdio(false); llong N, W; cin >> N >> W; vecllong weight(N + 1, 0); vecllong value(N + 1, 0); llong maxValue = 0; FOR(i, N) { cin >> weight[i] >> value[i]; maxValue += value[i]; } vvecllong dp(N + 1, vecllong(maxValue + 1, INF)); // dp[i][value] = minWeight dp[0][0] = 0; FOR(i, N) { FOR(v, maxValue + 1) { if (v - value[i] >= 0) { dp[i + 1][v] = min({dp[i][v - value[i]] + weight[i], dp[i][v], dp[i + 1][v]}); } else { dp[i + 1][v] = dp[i][v]; } } } llong ans = 0; for (llong v = maxValue; v >= 0; v--) { if (dp[N][v] <= W) { ans = v; break; } } cout << ans << endl; return 0; }
[ "assignment.value.change", "identifier.change" ]
971,671
971,672
u392319141
cpp
p03164
#include <bits/stdc++.h> using namespace std; long long dp[100005]; int v[105], w[105]; int main() { int n, W; scanf("%d %d", &n, &W); for (int i = 1; i <= n; i++) { scanf("%d %d", &w[i], &v[i]); } for (int j = 0; j <= 100000; j++) { dp[j] = 1e15; } dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 100000; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } for (int i = 100; i >= 0; i--) { if (dp[i] <= W) { printf("%d\n", i); return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long dp[100005]; int v[105], w[105]; int main() { int n, W; scanf("%d %d", &n, &W); for (int i = 1; i <= n; i++) { scanf("%d %d", &w[i], &v[i]); } for (int j = 0; j <= 100000; j++) { dp[j] = 1e15; } dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = 100000; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } for (int i = 100000; i >= 0; i--) { if (dp[i] <= W) { printf("%d\n", i); return 0; } } return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
971,675
971,676
u259039862
cpp
p03164
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cmath> #include <iostream> #include <string> #include <vector> #define INF ((1LL << 62) - (1LL << 31)) using namespace std; int main() { long long int a, b; cin >> a >> b; long long int W[a + 1], V[a + 1], DP[a + 1][1000001]; // DP[i][j] i番目までの品物を、価値がj以上になるように選んだ時の最小の重さ for (int i = 0; i <= a; ++i) { if (i > 0) cin >> W[i] >> V[i]; for (int j = 0; j < 1000001; ++j) { DP[i][j] = INF; } } DP[0][0] = 0; for (int i = 1; i <= a; ++i) { for (int j = 0; j < 1000001; ++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]; } } int ans = 1000000; while (DP[a][ans] > b) ans--; cout << ans << endl; }
#include <algorithm> #include <bits/stdc++.h> #include <bitset> #include <cmath> #include <iostream> #include <string> #include <vector> #define INF ((1LL << 62) - (1LL << 31)) using namespace std; int main() { long long int a, b; cin >> a >> b; long long int W[a + 1], V[a + 1], DP[a + 1][100001]; // DP[i][j] i番目までの品物を、価値がj以上になるように選んだ時の最小の重さ for (int i = 0; i <= a; ++i) { if (i > 0) cin >> W[i] >> V[i]; for (int j = 0; j < 100001; ++j) { DP[i][j] = INF; } } DP[0][0] = 0; for (int i = 1; i <= a; ++i) { for (int j = 0; j < 100001; ++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]; } } int ans = 100000; while (DP[a][ans] > b) ans--; cout << ans << endl; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "variable_declaration.value.change" ]
971,716
971,717
u041282550
cpp
p03164
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; // Self settings // clang-format off #define MAX_N 100 #define MAX_V 1000 #define INF 1000000001 #define REP(i, N) for (int i = 0; i < (int)(N); ++i) // clang-format on ll N, W; // ll dp[MAX_N + 1][MAX_V + 1]; ll dp[MAX_N + 1][MAX_N * MAX_V + 1]; ll w[MAX_N], v[MAX_N]; void solve() { REP(i, N + 1) REP(j, MAX_V + 1) dp[i][j] = INF; dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= MAX_N * MAX_V + 1; j++) { if (j < v[i] || dp[i][j - v[i]] == INF) { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } } } ll ans = 0; // REP(j, MAX_V + 1) cout << dp[N][j] << " "; REP(j, MAX_N * MAX_V + 1) if (dp[N][j] <= W) ans = j; cout << ans << endl; } int main(void) { cin >> N >> W; REP(i, N) cin >> w[i] >> v[i]; solve(); return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; // Self settings // clang-format off #define MAX_N 100 #define MAX_V 1000 #define INF 1000000001 #define REP(i, N) for (int i = 0; i < (int)(N); ++i) // clang-format on ll N, W; // ll dp[MAX_N + 1][MAX_V + 1]; ll dp[MAX_N + 1][MAX_N * MAX_V + 1]; ll w[MAX_N], v[MAX_N]; void solve() { REP(i, N + 1) REP(j, MAX_N * MAX_V + 1) dp[i][j] = INF; dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= MAX_N * MAX_V + 1; j++) { if (j < v[i] || dp[i][j - v[i]] == INF) { dp[i + 1][j] = dp[i][j]; } else { dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]); } } } ll ans = 0; // REP(j, MAX_V + 1) cout << dp[N][j] << " "; REP(j, MAX_N * MAX_V + 1) if (dp[N][j] <= W) ans = j; cout << ans << endl; } int main(void) { cin >> N >> W; REP(i, N) cin >> w[i] >> v[i]; solve(); return 0; }
[ "assignment.change" ]
971,718
971,719
u621104964
cpp
p03164
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 110; const int MAX_V = 100100; const ll INF = 2 << 62; ll dp[MAX_N][MAX_V]; int main() { int N, W; cin >> N >> W; vector<ll> w(N), v(N); for (int i = 0; i < N; i++) { 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; for (int i = 0; i < N; i++) { for (int j = 0; j < MAX_V; j++) { if (j - v[i] >= 0) { 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 res = 0; for (int i = 0; i < MAX_V; i++) { if (dp[N][i] <= W) { res = i; } } cout << res << endl; return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 110; const int MAX_V = 100100; const ll INF = 1LL << 62; ll dp[MAX_N][MAX_V]; int main() { int N, W; cin >> N >> W; vector<ll> w(N), v(N); for (int i = 0; i < N; i++) { 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; for (int i = 0; i < N; i++) { for (int j = 0; j < MAX_V; j++) { if (j - v[i] >= 0) { 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 res = 0; for (int i = 0; i < MAX_V; i++) { if (dp[N][i] <= W) { res = i; } } cout << res << endl; return 0; }
[ "literal.number.change", "expression.operation.binary.change", "literal.number.type.widen.change" ]
971,729
971,730
u146594935
cpp
p03164
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 110; const int MAX_V = 100100; const ll INF = 2 << 63 - 1; ll dp[MAX_N][MAX_V]; int main() { int N, W; cin >> N >> W; vector<ll> w(N), v(N); for (int i = 0; i < N; i++) { 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; for (int i = 0; i < N; i++) { for (int j = 0; j < MAX_V; j++) { if (j - v[i] >= 0) { 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 res = 0; for (int i = 0; i < MAX_V; i++) { if (dp[N][i] <= W) { res = i; } } cout << res << endl; return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string.h> #include <vector> using namespace std; typedef long long ll; const int MAX_N = 110; const int MAX_V = 100100; const ll INF = 1LL << 62; ll dp[MAX_N][MAX_V]; int main() { int N, W; cin >> N >> W; vector<ll> w(N), v(N); for (int i = 0; i < N; i++) { 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; for (int i = 0; i < N; i++) { for (int j = 0; j < MAX_V; j++) { if (j - v[i] >= 0) { 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 res = 0; for (int i = 0; i < MAX_V; i++) { if (dp[N][i] <= W) { res = i; } } cout << res << endl; return 0; }
[ "expression.operation.binary.remove" ]
971,731
971,730
u146594935
cpp
p03164
#include <bits/stdc++.h> using namespace std; #define SORT(x) sort(x.begin(), x.end()) #define ALL(x) x.begin(), x.end() #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(),x.end(),v)-x.begin() #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000000 #define mod 1000000007 typedef long long ll; const ll LINF = 1001002003004005006ll; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } //価値が小さくて重さがデカイKnapsack DP /* v[i]<10^3 w[i]<10^9 今回は重みがバカでかいのでdpが持つのが重みにしないと終わらない。 dp[v]がもつのはその価値を達成するのに必要最低限な重み v[i]をどう組み合わせてもvを達成できないならLINFがdpにずっとはいりっぱ なので、最後上から見ていって初めて重みが目標以下になったところが答え なんで上から走査するん?? →更新が無限に続いちゃうからだろバカか? →個数制限なしのときはそれで下まで埋めればいいのか天才じゃん */ int main() { ll N, W; cin >> N >> W; vector<ll> w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<ll> dp(100001, LINF); dp[0] = 0; rep(i, N) { for (int j = 100000; j >= 0; j--) { if (dp[j]) continue; dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]); } } ll ans = 0; for (ll i = 100000; i >= 0; i--) { if (dp[i] <= W) { ans = i; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define SORT(x) sort(x.begin(), x.end()) #define ALL(x) x.begin(), x.end() #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(),x.end(),v)-x.begin() #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000000 #define mod 1000000007 typedef long long ll; const ll LINF = 1001002003004005006ll; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } //価値が小さくて重さがデカイKnapsack DP /* v[i]<10^3 w[i]<10^9 今回は重みがバカでかいのでdpが持つのが重みにしないと終わらない。 dp[v]がもつのはその価値を達成するのに必要最低限な重み v[i]をどう組み合わせてもvを達成できないならLINFがdpにずっとはいりっぱ なので、最後上から見ていって初めて重みが目標以下になったところが答え なんで上から走査するん?? →更新が無限に続いちゃうからだろバカか? →個数制限なしのときはそれで下まで埋めればいいのか天才じゃん */ int main() { ll N, W; cin >> N >> W; vector<ll> w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<ll> dp(100001, LINF); dp[0] = 0; rep(i, N) { for (int j = 100000; j >= 0; j--) { if (dp[j] == LINF) continue; dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]); } } ll ans = 0; for (ll i = 100000; i >= 0; i--) { if (dp[i] <= W) { ans = i; break; } } cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
971,734
971,735
u022832318
cpp
p03164
#include <bits/stdc++.h> using LL = long long; const LL MOD = 1e9 + 9; using namespace std; int main() { int N, W; cin >> N >> W; vector<pair<int, int>> vec; for (int i = 0; i < N; i++) { int b; cin >> b; int c; cin >> c; vec.push_back({b, c}); } vector<vector<LL>> dp(N + 1, vector<LL>(1000000, 1e9)); for (int a = 0; a <= N; a++) dp.at(a).at(0) = 0; for (int a = 1; a <= N; a++) { for (int b = 1; b <= 1000000; b++) { if (b - vec.at(a - 1).second >= 0) { if (dp[a - 1][b - vec.at(a - 1).second] != 1e9) { dp[a][b] = min(dp[a - 1][b - vec.at(a - 1).second] + vec.at(a - 1).first, dp[a][b]); } } if (dp[a - 1][b] != 1e9) dp[a][b] = min(dp[a][b], dp[a - 1][b]); } } /* for(int a = 0;a <= N;a++){ for(int b = 0;b <= 30;b++){ if(dp[a][b] != 1e9)cout<<dp[a][b]<<" "; else cout<<"1e "; } cout<<endl; } */ int ans = 0; for (int a = 0; a < 1000000; a++) { if (dp.back()[a] != 1e9 && dp.back()[a] <= W) ans = a; } cout << ans << endl; }
#include <bits/stdc++.h> using LL = long long; const LL MOD = 1e9 + 9; using namespace std; int main() { int N, W; cin >> N >> W; vector<pair<int, int>> vec; for (int i = 0; i < N; i++) { int b; cin >> b; int c; cin >> c; vec.push_back({b, c}); } vector<vector<LL>> dp(N + 1, vector<LL>(1000000, 1e18)); for (int a = 0; a <= N; a++) dp.at(a).at(0) = 0; for (int a = 1; a <= N; a++) { for (int b = 1; b <= 1000000; b++) { if (b - vec.at(a - 1).second >= 0) { if (dp[a - 1][b - vec.at(a - 1).second] != 1e18) { dp[a][b] = min(dp[a - 1][b - vec.at(a - 1).second] + vec.at(a - 1).first, dp[a][b]); } } if (dp[a - 1][b] != 1e18) dp[a][b] = min(dp[a][b], dp[a - 1][b]); } } /* for(int a = 0;a <= N;a++){ for(int b = 0;b <= 30;b++){ if(dp[a][b] != 1e9)cout<<dp[a][b]<<" "; else cout<<"1e "; } cout<<endl; } */ int ans = 0; for (int a = 0; a < 1000000; a++) { if (dp.back()[a] != 1e18 && dp.back()[a] <= W) ans = a; } cout << ans << endl; }
[ "literal.number.change", "call.arguments.change", "control_flow.branch.if.condition.change" ]
971,745
971,746
u580402951
cpp
p03164
#include <bits/stdc++.h> #define MAX ((int)(2e9)) using namespace std; int dp[102][(int)(1e5) + 7], c[105], v[105]; int call(int n, int rem) { if (rem <= 0) return 0; if (n == 0) { return MAX; } if (dp[n][rem] != -1) return dp[n][rem]; dp[n][rem] = MAX; dp[n][rem] = min(dp[n][rem], call(n - 1, rem)); dp[n][rem] = min(dp[n][rem], call(n - 1, rem - v[n]) + c[n]); return dp[n][rem]; } int main() { int n, w; scanf("%d %d", &n, &w); for (int i = 1; i <= n; i++) scanf("%d %d", &c[i], &v[i]); memset(dp, -1, sizeof dp); for (int i = ((int)(1e5) + 2); i >= 0; i--) { if (call(n, i) <= w) { printf("%d\n", i); return 0; } } return 0; }
#include <bits/stdc++.h> #define MAX ((int)(1e9) + 2) using namespace std; int dp[102][(int)(1e5) + 2], c[105], v[105]; int call(int n, int rem) { if (rem <= 0) return 0; if (n == 0) { return MAX; } if (dp[n][rem] != -1) return dp[n][rem]; dp[n][rem] = MAX; dp[n][rem] = min(dp[n][rem], call(n - 1, rem)); dp[n][rem] = min(dp[n][rem], call(n - 1, rem - v[n]) + c[n]); return dp[n][rem]; } int main() { int n, w; scanf("%d %d", &n, &w); for (int i = 1; i <= n; i++) scanf("%d %d", &c[i], &v[i]); memset(dp, -1, sizeof dp); for (int i = ((int)(1e5) + 2); i >= 0; i--) { if (call(n, i) <= w) { printf("%d\n", i); return 0; } } return 0; }
[ "preprocessor.define.value.change", "literal.float.change", "literal.number.change", "expression.operation.binary.change" ]
971,749
971,750
u518630931
cpp
p03164
#include <bits/stdc++.h> #define MAX ((int)(2e9)) using namespace std; int dp[102][(int)(1e5) + 7], c[105], v[105]; int call(int n, int rem) { if (rem <= 0) return 0; if (n == 0) { return MAX; } if (dp[n][rem] != -1) return dp[n][rem]; dp[n][rem] = MAX; dp[n][rem] = min(dp[n][rem], call(n - 1, rem)); dp[n][rem] = min(dp[n][rem], call(n - 1, rem - v[n]) + c[n]); return dp[n][rem]; } int main() { int n, w; scanf("%d %d", &n, &w); for (int i = 1; i <= n; i++) scanf("%d %d", &c[i], &v[i]); memset(dp, -1, sizeof dp); for (int i = ((int)(1e5) + 2); i >= 0; i--) { if (call(n, i) <= w) { printf("%d\n", i); return 0; } } return 0; }
#include <bits/stdc++.h> #define MAX ((int)(1e9) + 2) using namespace std; int dp[102][(int)(1e5) + 7], c[105], v[105]; int call(int n, int rem) { if (rem <= 0) return 0; if (n == 0) { return MAX; } if (dp[n][rem] != -1) return dp[n][rem]; dp[n][rem] = MAX; dp[n][rem] = min(dp[n][rem], call(n - 1, rem)); dp[n][rem] = min(dp[n][rem], call(n - 1, rem - v[n]) + c[n]); return dp[n][rem]; } int main() { int n, w; scanf("%d %d", &n, &w); for (int i = 1; i <= n; i++) scanf("%d %d", &c[i], &v[i]); memset(dp, -1, sizeof dp); for (int i = ((int)(1e5) + 2); i >= 0; i--) { if (call(n, i) <= w) { printf("%d\n", i); return 0; } } return 0; }
[ "preprocessor.define.value.change", "literal.float.change" ]
971,749
971,751
u518630931
cpp