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
#define _GLIBCXX_DEBUG #include <algorithm> #include <climits> #include <cmath> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; #define omajinai \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #pragma region typedef typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> P; #pragma endregion #pragma region define #define endl '\n' #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; (i) < (n); (i)++) #define pb push_back #define pf push_front #pragma endregion #pragma region const const ld PI = 3.141592653589793; const ll INF18 = 1e18; #pragma endregion #pragma region function 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; } #pragma endregion ll weight[110], value[110]; ll dp[110][100100]; int main() { omajinai; int n; ll w; cin >> n >> w; rep(i, n) cin >> weight[i] >> value[w]; rep(i, n) for (int sum_w = 0; sum_w <= w; sum_w++) { if (sum_w - weight[i] >= 0) chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]); chmax(dp[i + 1][sum_w], dp[i][sum_w]); } cout << dp[n][w] << endl; return 0; }
#define _GLIBCXX_DEBUG #include <algorithm> #include <climits> #include <cmath> #include <iostream> #include <string> #include <utility> #include <vector> using namespace std; #define omajinai \ ios::sync_with_stdio(false); \ cin.tie(nullptr); #pragma region typedef typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> P; #pragma endregion #pragma region define #define endl '\n' #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (int i = 0; (i) < (n); (i)++) #define pb push_back #define pf push_front #pragma endregion #pragma region const const ld PI = 3.141592653589793; const ll INF18 = 1e18; #pragma endregion #pragma region function 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; } #pragma endregion ll weight[110], value[110]; ll dp[110][100100]; int main() { omajinai; int n; ll w; cin >> n >> w; rep(i, n) cin >> weight[i] >> value[i]; rep(i, n) for (int sum_w = 0; sum_w <= w; sum_w++) { if (sum_w - weight[i] >= 0) chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]); chmax(dp[i + 1][sum_w], dp[i][sum_w]); } cout << dp[n][w] << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change" ]
967,748
967,749
u884476319
cpp
p03163
#include <bits/stdc++.h> #include <iostream> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define ll long long #define li long int #define pp pair<int, int> #define lb lower_bound #define ub upper_bound #define mk make_pair #define pb push_back #define llp(i, x, n) for (int i = x; i < n; i++) #define fr first #define ss second #define mod 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; vector<ll> dp(w + 1); for (int i = 0; i < n; ++i) { ll weight, value; cin >> weight >> value; for (int j = w - weight; j >= 0; --j) { dp[j + weight] = max(dp[j + weight], dp[j] + value); } } ll ans = 0; for (int i = 0; i <= n; i++) { ans = max(dp[i], ans); } cout << ans; }
#include <bits/stdc++.h> #include <iostream> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define ll long long #define li long int #define pp pair<int, int> #define lb lower_bound #define ub upper_bound #define mk make_pair #define pb push_back #define llp(i, x, n) for (int i = x; i < n; i++) #define fr first #define ss second #define mod 1000000007 using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, w; cin >> n >> w; vector<ll> dp(w + 1); for (int i = 0; i < n; ++i) { ll weight, value; cin >> weight >> value; for (int j = w - weight; j >= 0; j--) { dp[j + weight] = max(dp[j + weight], dp[j] + value); } } ll ans = 0; for (int i = 0; i <= w; i++) { ans = max(dp[i], ans); } cout << ans; }
[ "identifier.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
967,756
967,757
u350009995
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mxn 100005 #define mp make_pair #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); typedef long long int ll; int main() { int n, w; cin >> n >> w; int wt[n], val[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } int dp[n + 1][w + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else { if (j < wt[i - 1]) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]); } } } } cout << dp[n][w]; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mxn 100005 #define mp make_pair #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); typedef long long int ll; int main() { int n, w; cin >> n >> w; ll wt[n], val[n]; for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } ll dp[n + 1][w + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else { if (j < wt[i - 1]) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]); } } } } cout << dp[n][w]; }
[ "variable_declaration.type.change" ]
967,762
967,763
u737257203
cpp
p03163
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { int n, w; cin >> n >> w; vector<int> weight(n), value(n); rep(i, n) cin >> weight[i] >> value[i]; vector<vector<int>> dp(n + 1, vector<int>(w + 1)); for (int i = 0; i < n; i++) { for (int j = 1; j <= w; j++) { if (j - weight[i] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } cout << dp[n][w] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { int n, w; cin >> n >> w; vector<int> weight(n), value(n); rep(i, n) cin >> weight[i] >> value[i]; vector<vector<ll>> dp(n + 1, vector<ll>(w + 1)); for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j - weight[i] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } cout << dp[n][w] << endl; return 0; }
[ "call.arguments.change", "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
967,766
967,765
u883680855
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define fo(i, n) for (long long i = 0; i < n; i++) #define sc(x) cin >> x #define pr(x) cout << x << endl; #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define br cout << endl typedef long long int lli; typedef pair<int, int> pii; typedef pair<lli, lli> pll; typedef vector<int> vi; typedef vector<lli> vlli; typedef vector<pii> vpii; typedef vector<pll> vpll; lli max(lli a, lli b) { return (a > b) ? a : b; } lli min(lli a, lli b) { return (a < b) ? a : b; } lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a); } lli n; int a[100005], b[100005], c[100005]; int main() { // Fast Input/Output ios_base::sync_with_stdio(0); cin.tie(0); // Test Cases int t = 1; // cin >> t; while (t--) { int n, w; sc(n); sc(w); int weight[n + 1], val[n + 1]; for (int i = 1; i <= n; i++) { cin >> weight[i] >> val[i]; } int dp[n + 1][w + 1]; for (int i = 0; i <= w; i++) { dp[0][i] = 0; } for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (weight[i] <= j) { dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - weight[i]]); } else { dp[i][j] = dp[i - 1][j]; } } } pr(dp[n][w]); } return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(i, n) for (long long i = 0; i < n; i++) #define sc(x) cin >> x #define pr(x) cout << x << endl; #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define br cout << endl typedef long long int lli; typedef pair<int, int> pii; typedef pair<lli, lli> pll; typedef vector<int> vi; typedef vector<lli> vlli; typedef vector<pii> vpii; typedef vector<pll> vpll; lli max(lli a, lli b) { return (a > b) ? a : b; } lli min(lli a, lli b) { return (a < b) ? a : b; } lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a); } lli n; int a[100005], b[100005], c[100005]; int main() { // Fast Input/Output ios_base::sync_with_stdio(0); cin.tie(0); // Test Cases int t = 1; // cin >> t; while (t--) { lli n, w; sc(n); sc(w); lli weight[n + 1], val[n + 1]; for (int i = 1; i <= n; i++) { cin >> weight[i] >> val[i]; } lli dp[n + 1][w + 1]; for (int i = 0; i <= w; i++) { dp[0][i] = 0; } for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (weight[i] <= j) { dp[i][j] = max(dp[i - 1][j], val[i] + dp[i - 1][j - weight[i]]); } else { dp[i][j] = dp[i - 1][j]; } } } pr(dp[n][w]); } return 0; }
[ "variable_declaration.type.change" ]
967,769
967,770
u895928005
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef pair<int, string> PIS; typedef vector<int> vec; typedef priority_queue<int> PQ; #define endl '\n' #define pi 3.141592653589793 #define pb push_back #define mp make_pair #define ff first #define ss second #define fori(z, n) for (int i = z; i < n; i++) #define forii(z, n) for (int i = z; i <= n; i++) int maxElement(int arr[], int n) { int maxi = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] > maxi) maxi = arr[i]; } return maxi; } int minElement(int arr[], int n) { int mini = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < mini) mini = arr[i]; } return mini; } string trim(const string &str) { int first = str.find_first_not_of(' '); if (string::npos == first) { return str; } int last = str.find_last_not_of(' '); return str.substr(first, (last - first + 1)); } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, w; cin >> n >> w; vector<PII> v(n + 1); fori(1, n + 1) { ll a, b; cin >> a >> b; v[i] = {a, b}; } ll dp[w + 1][n + 1]; fori(1, n + 1) dp[0][i] = 0; fori(1, w + 1) dp[i][0] = 0; fori(1, w + 1) { for (int k = 1; k <= n; k++) { if (i - v[k].ff >= 0) dp[i][k] = max(v[k].ss + dp[i - v[k].ff][k - 1], dp[i][k - 1]); else dp[i][k] = dp[i][k - 1]; } } cout << dp[w][n] << endl; cerr << "Time elapsed" << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef pair<int, string> PIS; typedef vector<int> vec; typedef priority_queue<int> PQ; #define endl '\n' #define pi 3.141592653589793 #define pb push_back #define mp make_pair #define ff first #define ss second #define fori(z, n) for (int i = z; i < n; i++) #define forii(z, n) for (int i = z; i <= n; i++) int maxElement(int arr[], int n) { int maxi = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] > maxi) maxi = arr[i]; } return maxi; } int minElement(int arr[], int n) { int mini = arr[0]; for (int i = 1; i < n; i++) { if (arr[i] < mini) mini = arr[i]; } return mini; } string trim(const string &str) { int first = str.find_first_not_of(' '); if (string::npos == first) { return str; } int last = str.find_last_not_of(' '); return str.substr(first, (last - first + 1)); } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, w; cin >> n >> w; vector<PII> v(n + 1); fori(1, n + 1) { ll a, b; cin >> a >> b; v[i] = {a, b}; } ll dp[w + 1][n + 1]; fori(0, n + 1) dp[0][i] = 0; fori(0, w + 1) dp[i][0] = 0; fori(1, w + 1) { for (int k = 1; k <= n; k++) { if (i - v[k].ff >= 0) dp[i][k] = max(v[k].ss + dp[i - v[k].ff][k - 1], dp[i][k - 1]); else dp[i][k] = dp[i][k - 1]; } } cout << dp[w][n] << endl; cerr << "Time elapsed" << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"; return 0; }
[ "literal.number.change", "assignment.variable.change", "call.arguments.change" ]
967,773
967,774
u829019938
cpp
p03163
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; //#include <boost/multiprecision/cpp_int.hpp> // namespace mp = boost::multiprecision; //#define ln mp::cpp_int; #define ll long long #define ld long double #define ull unsigned long long #define endl "\n" #define all(vec) vec.begin(), vec.end() ll google_itr = 1; #define google(x) cout << "Case #" << x << ":" #define pi 3.14159265358979323846264338327950L const ll mod = 1e9 + 7; const ll inf = 1e18; void virus() { ll len, wt; cin >> len >> wt; vector<ll> w, val; for (auto i = 0; i < len; i++) { ll a, b; cin >> a >> b; w.push_back(a); val.push_back(b); } ll dp[len + 1][wt + 1]; for (auto i = 0; i <= len; i++) { for (auto j = 0; j <= wt; j++) { if (i == 0 or j == 0) dp[i][j] = 0; else if (w[i - 1] <= j) dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]); else dp[i][j] = dp[i - 1][j]; } } cout << (ll)dp[len][wt]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ ll t; cin >> t; while (t--) { auto start = high_resolution_clock::now(); virus(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<seconds>(stop - start); // cerr << "\nTime: "<<duration.count()<<endl; // your code goes here } return 0; }
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; //#include <boost/multiprecision/cpp_int.hpp> // namespace mp = boost::multiprecision; //#define ln mp::cpp_int; #define ll long long #define ld long double #define ull unsigned long long #define endl "\n" #define all(vec) vec.begin(), vec.end() ll google_itr = 1; #define google(x) cout << "Case #" << x << ":" #define pi 3.14159265358979323846264338327950L const ll mod = 1e9 + 7; const ll inf = 1e18; void virus() { ll len, wt; cin >> len >> wt; vector<ll> w, val; for (auto i = 0; i < len; i++) { ll a, b; cin >> a >> b; w.push_back(a); val.push_back(b); } ll dp[len + 1][wt + 1]; for (auto i = 0; i <= len; i++) { for (auto j = 0; j <= wt; j++) { if (i == 0 or j == 0) dp[i][j] = 0; else if (w[i - 1] <= j) dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]); else dp[i][j] = dp[i - 1][j]; } } cout << (ll)dp[len][wt]; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ ll t = 1; // cin>>t; while (t--) { auto start = high_resolution_clock::now(); virus(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<seconds>(stop - start); // cerr << "\nTime: "<<duration.count()<<endl; // your code goes here } return 0; }
[ "expression.operation.binary.remove" ]
967,779
967,780
u894812250
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = long long; main() { int n, we; cin >> n >> we; int w[n], v[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll dp[n + 1][we + 1] = {0}; for (int i = 1; i < n + 1; i++) { for (int i2 = 1; i2 < we + 1; i2++) { if (i2 < w[i - 1]) { dp[i][i2] = dp[i - 1][i2]; } else { dp[i][i2] = max(dp[i - 1][i2], dp[i - 1][i2 - w[i - 1]] + v[i - 1]); } } } cout << dp[n][we] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; main() { int n, we; cin >> n >> we; int w[n], v[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll dp[n + 1][we + 1] = {}; for (int i = 1; i < n + 1; i++) { for (int i2 = 1; i2 < we + 1; i2++) { if (i2 < w[i - 1]) { dp[i][i2] = dp[i - 1][i2]; } else { dp[i][i2] = max(dp[i - 1][i2], dp[i - 1][i2 - w[i - 1]] + v[i - 1]); } } } cout << dp[n][we] << endl; }
[]
967,785
967,786
u160321725
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = long long; int in() { int a; cin >> a; return a; } // int型関数の受け取り void forin(int *x, int y) { for (int i = 0; i < y; i++) { cin >> x[i]; } } //(x,y) int型配列x[y]の受け取り int fact(int x) { if (x == 1) return 1; return x * fact(x - 1); } //(x) x! int div1(ll x) { return x % 1000000007; } main() { int n = in(), we = in(), w[n], v[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll dp[n + 1][we + 1] = {0}; for (int i = 1; i < n + 1; i++) { for (int i2 = 1; i2 < we + 1; i2++) { if (i2 < w[i - 1]) { dp[i][i2] = dp[i - 1][i2]; } else { dp[i][i2] = max(dp[i - 1][i2], dp[i - 1][i2 - w[i - 1]] + v[i - 1]); } } } cout << dp[n][we] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int in() { int a; cin >> a; return a; } // int型関数の受け取り void forin(int *x, int y) { for (int i = 0; i < y; i++) { cin >> x[i]; } } //(x,y) int型配列x[y]の受け取り int fact(int x) { if (x == 1) return 1; return x * fact(x - 1); } //(x) x! int div1(ll x) { return x % 1000000007; } main() { int n = in(), we = in(), w[n], v[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; ll dp[n + 1][we + 1] = {}; for (int i = 1; i < n + 1; i++) { for (int i2 = 1; i2 < we + 1; i2++) { if (i2 < w[i - 1]) { dp[i][i2] = dp[i - 1][i2]; } else { dp[i][i2] = max(dp[i - 1][i2], dp[i - 1][i2 - w[i - 1]] + v[i - 1]); } } } cout << dp[n][we] << endl; }
[]
967,787
967,788
u160321725
cpp
p03163
#include <bits/stdc++.h> #define int long long using namespace std; #define deb(x) cout << #x << " = " << x << "\n"; void solve() { int n, w; cin >> n >> w; int val[n + 1], wt[n + 1]; for (int i = 0; i < n; i++) cin >> wt[i] >> val[i]; int dp[w + 1]; fill(dp, dp + w + 1, 0); for (int i = 0; i < n; i++) { for (int j = w; j >= wt[i]; j--) dp[j] = max(dp[j], val[i] + dp[j - wt[i]]); } cout << dp[w] << "\n"; } signed main() { // freopen("input.txt", "r", stdin); int t = 1; cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; #define deb(x) cout << #x << " = " << x << "\n"; void solve() { int n, w; cin >> n >> w; int val[n + 1], wt[n + 1]; for (int i = 0; i < n; i++) cin >> wt[i] >> val[i]; int dp[w + 1]; fill(dp, dp + w + 1, 0); for (int i = 0; i < n; i++) { for (int j = w; j >= wt[i]; j--) dp[j] = max(dp[j], val[i] + dp[j - wt[i]]); } cout << dp[w] << "\n"; } signed main() { // freopen("input.txt", "r", stdin); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
[]
967,791
967,792
u193862001
cpp
p03163
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define sz(x) ll(x.size()) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll n, W, ans = 0; cin >> n >> W; vector<vector<ll>> dp(n + 5, vector<ll>(W + 5, 0)); vector<ll> w(n); vector<ll> v(n); rep(i, n) cin >> w.at(i) >> v.at(i); rep(i, n) rep(j, W + 1) { if (j - w[i] >= 0) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); else chmax(dp[i + 1][j], dp[i][j]); } cout << dp[n][W] << endl; }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define sz(x) ll(x.size()) using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { ll n, W, ans = 0; cin >> n >> W; vector<vector<ll>> dp(n + 5, vector<ll>(W + 5, 0)); vector<ll> w(n); vector<ll> v(n); rep(i, n) cin >> w.at(i) >> v.at(i); rep(i, n) rep(j, W + 1) { if (j - w[i] >= 0) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } cout << dp[n][W] << endl; }
[ "control_flow.branch.else.remove" ]
967,798
967,799
u059207724
cpp
p03163
#include <iostream> #include <vector> using namespace std; long long int N, D; vector<long long int> W; vector<long long int> V; int main() { cin >> N >> D; W.assign(N, 0); V.assign(N, 0); for (int i = 0; i < N; i++) { cin >> W[i] >> V[i]; } vector<vector<long long int>> dp(N + 1, vector<long long int>(D + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 0; j <= D && j <= D; j++) { // the item we are in: i // the weight: j if (j - W[i - 1] > 0) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - W[i - 1]] + V[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[N][D] << endl; ; }
#include <iostream> #include <vector> using namespace std; long long int N, D; vector<long long int> W; vector<long long int> V; int main() { cin >> N >> D; W.assign(N, 0); V.assign(N, 0); for (int i = 0; i < N; i++) { cin >> W[i] >> V[i]; } vector<vector<long long int>> dp(N + 1, vector<long long int>(D + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 0; j <= D && j <= D; j++) { // the item we are in: i // the weight: j if (j - W[i - 1] >= 0) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - W[i - 1]] + V[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[N][D] << endl; ; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
967,826
967,827
u226528610
cpp
p03163
#include <bits/stdc++.h> using namespace std; const int N = 105, W = 100005; int n, g; int w, val, d[W]; int main() { cin >> n >> g; for (int i = 1; i <= n; i++) { cin >> w >> val; for (int j = g; j >= w; j--) d[j] = max(d[j], d[j - w] + val); } cout << d[g]; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 105, W = 100005; int n, g; int w, val; long long d[W]; int main() { cin >> n >> g; for (int i = 1; i <= n; i++) { cin >> w >> val; for (int j = g; j >= w; j--) d[j] = max(d[j], d[j - w] + val); } cout << d[g]; return 0; }
[ "variable_declaration.type.widen.change" ]
967,829
967,830
u843952236
cpp
p03163
#include <bits/stdc++.h> #define NMAX 100001 using namespace std; int N, W, v, w, maxx; int a[NMAX]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w >> v; for (int j = W - w; j >= 0; j--) { if (a[j] || !j) { a[j + w] = max(a[j + w], a[j] + v); maxx = max(a[j + w], maxx); } } } cout << maxx; return 0; }
#include <bits/stdc++.h> #define NMAX 100001 using namespace std; long long N, W, v, w, maxx; long long a[NMAX]; int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w >> v; for (int j = W - w; j >= 0; j--) { if (a[j] || !j) { a[j + w] = max(a[j + w], a[j] + v); maxx = max(a[j + w], maxx); } } } cout << maxx; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
967,834
967,835
u988262055
cpp
p03163
#include <iostream> using namespace std; int main() { int n, W; cin >> n >> W; int w[n]; int v[n]; int dp[W + 1]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; for (int i = 0; i <= W; i++) dp[i] = 0; for (int i = 0; i < n; i++) { for (int j = W; j >= w[i]; j--) { dp[j] = max(dp[j], dp[j - w[i]] + v[i]); } } cout << dp[W] << endl; }
#include <iostream> using namespace std; int main() { int n, W; cin >> n >> W; int w[n]; long v[n]; long dp[W + 1]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; for (int i = 0; i <= W; i++) dp[i] = 0; for (int i = 0; i < n; i++) { for (int j = W; j >= w[i]; j--) { dp[j] = max(dp[j], dp[j - w[i]] + v[i]); } } cout << dp[W] << endl; }
[ "variable_declaration.type.primitive.change" ]
967,840
967,841
u314470965
cpp
p03163
#define _USE_MATH_DEFINES #define rep(i, n) for (int i = 0; i < n; i++) #define repx(i, a, n) for (int i = a; i < n; i++) #define loop while (1) #define lli long long int #define aryout(ary) \ rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n"); #define arysort(v) sort(v.begin(), v.end()) #define aryreverse(v) reverse(v.begin(), v.end()) #define arysum(v) accumulate(v.begin(), v.end(), 0) #include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n, w; cin >> n >> w; vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0)); vector<pair<int, int>> trs(n); //{weight, value} rep(i, n) { pair<int, int> tmp; cin >> tmp.first >> tmp.second; trs[i] = tmp; } // rep(i, n) cout << trs[i].first << " " << trs[i].second << endl; repx(var, 1, n + 1) { repx(hor, 1, w + 1) { if (trs[var - 1].first > hor) { dp[var][hor] = dp[var - 1][hor]; } else { int tmp1 = dp[var - 1][hor - (trs[var - 1].first)] + trs[var - 1].second; int tmp2 = max(dp[var - 1][hor], dp[var][hor - 1]); dp[var][hor] = max(tmp1, tmp2); } // cout << "#####" << endl; // rep(i, n+1) rep(j, w+1) cout << dp[i][j] << (j == w ? "\n" : " "); } } cout << dp[n][w] << endl; return 0; }
#define _USE_MATH_DEFINES #define rep(i, n) for (int i = 0; i < n; i++) #define repx(i, a, n) for (int i = a; i < n; i++) #define loop while (1) #define lli long long int #define aryout(ary) \ rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n"); #define arysort(v) sort(v.begin(), v.end()) #define aryreverse(v) reverse(v.begin(), v.end()) #define arysum(v) accumulate(v.begin(), v.end(), 0) #include <algorithm> #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; int main() { int n, w; cin >> n >> w; vector<vector<lli>> dp(n + 1, vector<lli>(w + 1, 0)); vector<pair<int, int>> trs(n); //{weight, value} rep(i, n) { pair<int, int> tmp; cin >> tmp.first >> tmp.second; trs[i] = tmp; } // rep(i, n) cout << trs[i].first << " " << trs[i].second << endl; repx(var, 1, n + 1) { repx(hor, 1, w + 1) { if (trs[var - 1].first > hor) { dp[var][hor] = dp[var - 1][hor]; } else { lli tmp1 = dp[var - 1][hor - (trs[var - 1].first)] + trs[var - 1].second; lli tmp2 = max(dp[var - 1][hor], dp[var][hor - 1]); dp[var][hor] = max(tmp1, tmp2); } // cout << "#####" << endl; // rep(i, n+1) rep(j, w+1) cout << dp[i][j] << (j == w ? "\n" : " "); } } cout << dp[n][w] << endl; return 0; }
[ "call.arguments.change", "variable_declaration.type.change" ]
967,856
967,857
u785521224
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i <= b; i++) int main() { int n, W; cin >> n >> W; int v[n + 1], w[n + 1]; rep(i, 1, n) { cin >> w[i] >> v[i]; } vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0)); rep(i, 1, W) { rep(j, 1, n) { dp[j][i] = dp[j - 1][i]; if (i - w[j] >= 0) { dp[j][i] = max(dp[j][i], v[j] + dp[j - 1][i - w[j]]); } } } cout << dp[n][W] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i <= b; i++) int main() { int n, W; cin >> n >> W; long long int v[n + 1], w[n + 1]; rep(i, 1, n) { cin >> w[i] >> v[i]; } vector<vector<long long int>> dp(n + 1, vector<long long int>(W + 1, 0)); rep(i, 1, W) { rep(j, 1, n) { dp[j][i] = dp[j - 1][i]; if (i - w[j] >= 0) { dp[j][i] = max(dp[j][i], v[j] + dp[j - 1][i - w[j]]); } } } cout << dp[n][W] << "\n"; return 0; }
[ "variable_declaration.type.widen.change" ]
967,860
967,861
u650022504
cpp
p03163
#include <bits/stdc++.h> using namespace std; int knapsack(long long int W, long long int wt[], long long int val[], long long int n) { long long int i, w; long long int k[n + 1][W + 1] = {0}; for (i = 0; i <= n; i++) { for (w = 0; w <= W; w++) { if (i == 0 || w == 0) k[i][w] = 0; else if (wt[i - 1] <= w) k[i][w] = max(val[i - 1] + k[i - 1][w - wt[i - 1]], k[i - 1][w]); else k[i][w] = k[i - 1][w]; } } return (k[n][W]); } int main() { long long int i, n, W; cin >> n >> W; long long int wt[n + 2], val[n + 2]; for (i = 0; i < n; i++) cin >> wt[i] >> val[i]; cout << knapsack(W, wt, val, n); return (0); }
#include <bits/stdc++.h> using namespace std; long long int knapsack(long long int W, long long int wt[], long long int val[], long long int n) { long long int i, w; long long int k[n + 1][W + 1] = {0}; for (i = 0; i <= n; i++) { for (w = 0; w <= W; w++) { if (i == 0 || w == 0) k[i][w] = 0; else if (wt[i - 1] <= w) k[i][w] = max(val[i - 1] + k[i - 1][w - wt[i - 1]], k[i - 1][w]); else k[i][w] = k[i - 1][w]; } } return (k[n][W]); } int main() { long long int i, n, W; cin >> n >> W; long long int wt[n + 2], val[n + 2]; for (i = 0; i < n; i++) cin >> wt[i] >> val[i]; cout << knapsack(W, wt, val, n); return (0); }
[ "variable_declaration.type.widen.change" ]
967,862
967,863
u135798926
cpp
p03163
#include <bits/stdc++.h> using namespace std; /* long long int knapsack(long long int W, long long int wt[], long long int val[], long long int n) { long long int i, w; long long int k[n+1][W+1] = {0}; for (i = 0; i <= n; i++) { for (w = 0; w <= W; w++) { if (i==0 || w==0) k[i][w] = 0; else if (wt[i-1] <= w) k[i][w] = max(val[i-1] + k[i-1][w-wt[i-1]], k[i-1][w]); else k[i][w] = k[i-1][w]; } } return k[n][W]; } */ int knapsack(long long int W, long long int wt[], long long int val[], long long int n) { long long int i, w; long long int k[n + 1][W + 1] = {0}; for (i = 0; i <= n; i++) { for (w = 0; w <= W; w++) { if (i == 0 || w == 0) k[i][w] = 0; else if (wt[i - 1] <= w) k[i][w] = max(val[i - 1] + k[i - 1][w - wt[i - 1]], k[i - 1][w]); else k[i][w] = k[i - 1][w]; } } return (k[n][W]); } int main() { long long int i, n, W; cin >> n >> W; long long int wt[n + 2], val[n + 2]; for (i = 0; i < n; i++) cin >> wt[i] >> val[i]; cout << knapsack(W, wt, val, n); return (0); }
#include <bits/stdc++.h> using namespace std; long long int knapsack(long long int W, long long int wt[], long long int val[], long long int n) { long long int i, w; long long int k[n + 1][W + 1] = {0}; for (i = 0; i <= n; i++) { for (w = 0; w <= W; w++) { if (i == 0 || w == 0) k[i][w] = 0; else if (wt[i - 1] <= w) k[i][w] = max(val[i - 1] + k[i - 1][w - wt[i - 1]], k[i - 1][w]); else k[i][w] = k[i - 1][w]; } } return (k[n][W]); } int main() { long long int i, n, W; cin >> n >> W; long long int wt[n + 2], val[n + 2]; for (i = 0; i < n; i++) cin >> wt[i] >> val[i]; cout << knapsack(W, wt, val, n); return (0); }
[ "variable_declaration.type.widen.change" ]
967,864
967,863
u135798926
cpp
p03163
#include <algorithm> #include <cmath> // sqrt #include <iostream> #include <map> #include <numeric> // accumulate #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; const int INF = 1000000010; int dp[110][100010]; int main() { int N, W; cin >> N >> W; for (int i = 0; i < N; i++) { int w, v; cin >> w >> v; for (int weight = 0; weight <= W; weight++) { if (weight - w >= 0) dp[i + 1][weight] = max(dp[i][weight], dp[i][weight - w] + v); else dp[i + 1][weight] = dp[i][weight]; } } int ans = 0; for (int weight = 0; weight <= W; weight++) { ans = max(ans, dp[N][weight]); } cout << ans << endl; }
#include <algorithm> #include <cmath> // sqrt #include <iostream> #include <map> #include <numeric> // accumulate #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; const int INF = 1000000010; ll dp[110][100010]; int main() { int N, W; cin >> N >> W; for (int i = 0; i < N; i++) { int w, v; cin >> w >> v; for (int weight = 0; weight <= W; weight++) { if (weight - w >= 0) dp[i + 1][weight] = max(dp[i][weight], dp[i][weight - w] + v); else dp[i + 1][weight] = dp[i][weight]; } } ll ans = 0; for (int weight = 0; weight <= W; weight++) { ans = max(ans, dp[N][weight]); } cout << ans << endl; }
[ "variable_declaration.type.change" ]
967,865
967,866
u270681687
cpp
p03163
#include <iostream> #include <limits> using namespace std; struct item { int w; int v; }; int findMin(item items[], int n, int w) { int cost[n + 1][w + 1]; for (int i = 0; i < n; i++) cost[i][0] = 0; for (int i = 0; i <= w; i++) cost[0][i] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { cost[i][j] = cost[i - 1][j]; if (items[i - 1].w <= j) { cost[i][j] = max(cost[i - 1][j], cost[i - 1][j - items[i - 1].w] + items[i - 1].v); // cout<<cost[i][j]<<" "<<i<<" "<<j<<endl; } // cout<<cost[i][j]<<" "<<i<<" "<<j<<endl; } } // cout<<cost[1][3]<<" "<<cost[2][7]<<" "<<cost[3][8]<<endl; return cost[n][w]; } int main() { int n, w; cin >> n >> w; item items[n]; for (int i = 0; i < n; i++) cin >> items[i].w >> items[i].v; cout << findMin(items, n, w) << endl; }
#include <iostream> #include <limits> using namespace std; struct item { int w; int v; }; long long int findMin(item items[], int n, int w) { long long int cost[n + 1][w + 1]; for (int i = 0; i < n; i++) cost[i][0] = 0; for (int i = 0; i <= w; i++) cost[0][i] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { cost[i][j] = cost[i - 1][j]; if (items[i - 1].w <= j) cost[i][j] = max(cost[i - 1][j], cost[i - 1][j - items[i - 1].w] + items[i - 1].v); } } return cost[n][w]; } int main() { int n, w; cin >> n >> w; item items[n]; for (int i = 0; i < n; i++) cin >> items[i].w >> items[i].v; cout << findMin(items, n, w) << endl; }
[ "variable_declaration.type.widen.change" ]
967,892
967,893
u460700503
cpp
p03163
#include <bits/stdc++.h> using namespace std; long long n, w; long long wr[10005], ar[10005]; long long mem[10005][10005]; long long solve(long long ind, long long curw) { if (ind == n) { return 0; } if (mem[ind][curw] != -1) { return mem[ind][curw]; } long long ch1 = solve(ind + 1, curw), ch2 = 0; if (curw >= wr[ind]) { ch2 = solve(ind + 1, curw - wr[ind]) + ar[ind]; } return mem[ind][curw] = max(ch1, ch2); } int main() { // freopen("input.in", "r", stdin); // freopen("output.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> w; memset(mem, -1, sizeof mem); for (int i = 0; i < n; i++) { cin >> wr[i] >> ar[i]; } cout << solve(0, w) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, w; long long wr[105], ar[105]; long long mem[105][100005]; long long solve(long long ind, long long curw) { if (ind == n) { return 0; } if (mem[ind][curw] != -1) { return mem[ind][curw]; } long long ch1 = solve(ind + 1, curw), ch2 = 0; if (curw >= wr[ind]) { ch2 = solve(ind + 1, curw - wr[ind]) + ar[ind]; } return mem[ind][curw] = max(ch1, ch2); } int main() { // freopen("input.in", "r", stdin); // freopen("output.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> w; memset(mem, -1, sizeof mem); for (int i = 0; i < n; i++) { cin >> wr[i] >> ar[i]; } cout << solve(0, w) << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
967,909
967,908
u288989709
cpp
p03163
#include <iostream> using namespace std; typedef long long ll; ll max(ll a, ll b) { return a > b ? a : b; } int N, W; int main(void) { // Your code here! cin >> N >> W; ll w[N]; ll v[N]; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } ll dp[N + 1][W + 1]; dp[0][0] = 0; for (int i = 1; i < N; i++) { dp[i + 1][0] = 0; } for (int j = 1; j <= W; j++) { dp[0][j] = 0; } for (int i = 0; i < N; i++) { for (int j = 1; j <= W; j++) { if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); } else { dp[i + 1][j] = dp[i][j]; } } } cout << dp[N][W] << endl; return 0; }
#include <iostream> using namespace std; typedef long long ll; ll max(ll a, ll b) { return a > b ? a : b; } int N, W; int main(void) { // Your code here! cin >> N >> W; ll w[N]; ll v[N]; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } ll dp[N + 1][W + 1]; dp[0][0] = 0; for (int i = 0; i < N; i++) { dp[i + 1][0] = 0; } for (int j = 1; j <= W; j++) { dp[0][j] = 0; } for (int i = 0; i < N; i++) { for (int j = 1; j <= W; j++) { if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); } else { dp[i + 1][j] = dp[i][j]; } } } cout << dp[N][W] << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one" ]
967,911
967,912
u279137361
cpp
p03163
#include <bits/stdc++.h> #define ll long long #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mod 1000000007 #define f(i, n) for (int i = 0; i < n; i++) using namespace std; /************************BELIAL**********DEVIL*********BELIAL***********DEVIL*************************/ int main() { int n, w; cin >> n >> w; int wt[n], val[n]; f(i, n) { cin >> wt[i] >> val[i]; } int dp[n + 1][w + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { dp[i][j] = dp[i - 1][j]; if (j >= wt[i - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]); } } cout << dp[n][w]; }
#include <bits/stdc++.h> #define ll long long #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mod 1000000007 #define f(i, n) for (int i = 0; i < n; i++) using namespace std; /************************BELIAL**********DEVIL*********BELIAL***********DEVIL*************************/ int main() { int n, w; cin >> n >> w; ll wt[n], val[n]; f(i, n) { cin >> wt[i] >> val[i]; } ll dp[n + 1][w + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { dp[i][j] = dp[i - 1][j]; if (j >= wt[i - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]); } } cout << dp[n][w]; }
[ "variable_declaration.type.change" ]
967,917
967,918
u703899606
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define ff first #define ss second #define mp make_pair #define pb push_back #define si set<int> #define vi vector<int> #define pii pair<int, int> #define vpii vector<pii> #define vpp vector<pair<int, pii>> #define mii map<int, int> #define mpi map<pii, int> #define msi map<string, int> #define loop(i, s, e) for (int i = s; i < e; i++) #define rloop(i, e, s) for (int i = e; i >= s; i--) #define mset(a, f) memset(a, f, sizeof(a)) #define spi set<pii> #define endl "\n" #define sz(x) ((int)x.size()) #define all(p) p.begin(), p.end() #define que_max priority_queue<int> #define que_min priority_queue<int, vi, greater<int>> #define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define Print(a, x, y) \ for (int i = x; i < y; i++) \ cout << a[i] << " "; \ cout << endl inline int power(int a, int b) { int x = 1; while (b) { if (b & 1) x *= a; a *= a; b >>= 1; } return x; } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int N = 2000005; int v[N], w[N], n, maxwt; int dp[105][N]; int help(int i, int wt) { if (i >= n) return 0; if (dp[i][wt] != -1) return dp[i][wt]; int op1 = -1, op2 = -1; if (w[i] <= wt) op1 = v[i] + help(i + 1, wt - w[i]); op2 = help(i + 1, wt); return dp[i][wt] = max(op1, op2); } void solve() { cin >> n >> maxwt; loop(i, 0, n) cin >> w[i] >> v[i]; mset(dp, -1); cout << help(0, maxwt); return; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define ff first #define ss second #define mp make_pair #define pb push_back #define si set<int> #define vi vector<int> #define pii pair<int, int> #define vpii vector<pii> #define vpp vector<pair<int, pii>> #define mii map<int, int> #define mpi map<pii, int> #define msi map<string, int> #define loop(i, s, e) for (int i = s; i < e; i++) #define rloop(i, e, s) for (int i = e; i >= s; i--) #define mset(a, f) memset(a, f, sizeof(a)) #define spi set<pii> #define endl "\n" #define sz(x) ((int)x.size()) #define all(p) p.begin(), p.end() #define que_max priority_queue<int> #define que_min priority_queue<int, vi, greater<int>> #define bug(...) __f(#__VA_ARGS__, __VA_ARGS__) #define print(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define Print(a, x, y) \ for (int i = x; i < y; i++) \ cout << a[i] << " "; \ cout << endl inline int power(int a, int b) { int x = 1; while (b) { if (b & 1) x *= a; a *= a; b >>= 1; } return x; } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const int N = 2000005; int v[N], w[N], n, maxwt; int dp[105][100005]; int help(int i, int wt) { if (i >= n) return 0; if (dp[i][wt] != -1) return dp[i][wt]; int op1 = -1, op2 = -1; if (w[i] <= wt) op1 = v[i] + help(i + 1, wt - w[i]); op2 = help(i + 1, wt); return dp[i][wt] = max(op1, op2); } void solve() { cin >> n >> maxwt; loop(i, 0, n) cin >> w[i] >> v[i]; mset(dp, -1); cout << help(0, maxwt); return; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
[ "identifier.replace.remove", "literal.replace.add", "variable_declaration.array_dimensions.change" ]
967,919
967,920
u052025289
cpp
p03163
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; const int MOD = 1000000007; typedef long long ll; typedef pair<ll, ll> p; const int INF = (1 << 28); const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() int n; vector<int> w; vector<ll> v; int main() { cin.tie(0); ios::sync_with_stdio(false); ll W; cin >> n >> W; for (int i = 0; i < n; i++) { int tempw; ll tempv; cin >> tempw >> tempv; w.push_back(tempw); v.push_back(tempv); } ll dp[n + 1][W + 1]; for (int j = 0; j <= W; j++) { dp[0][j] = 0; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= W; j++) { if (j - w[i] >= 0) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[n][i]); } cout << ans << "\n"; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; const int MOD = 1000000007; typedef long long ll; typedef pair<ll, ll> p; const int INF = (1 << 28); const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() int n; vector<int> w; vector<ll> v; int main() { cin.tie(0); ios::sync_with_stdio(false); ll W; cin >> n >> W; for (int i = 0; i < n; i++) { int tempw; ll tempv; cin >> tempw >> tempv; w.push_back(tempw); v.push_back(tempv); } ll dp[n + 1][W + 1]; for (int j = 0; j <= W; j++) { dp[0][j] = 0; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= W; j++) { if (j - w[i - 1] >= 0) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]); } else { dp[i][j] = dp[i - 1][j]; } } } ll ans = 0; for (int i = 0; i <= W; i++) { ans = max(ans, dp[n][i]); } cout << ans << "\n"; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one", "assignment.change" ]
967,921
967,922
u155416173
cpp
p03163
// Example program #include <bits/stdc++.h> using namespace std; int n, w, a, b, value; int dp[101][100009]; vector<int> wt(101, 0); vector<int> val(101, 0); // vector<int> ans(100009,-1); // set<int> raand; int main() { cin >> n >> w; for (int i = 0; i < n; i++) { cin >> a >> b; wt[i] = a; val[i] = b; } for (int i = 0; i <= w; i++) { for (int j = 0; j < n; j++) { dp[j][i] = 0; } } for (int i = 0; i <= w; i++) { if (wt[0] <= i) { dp[0][i] = val[0]; } } for (int i = 0; i < n; i++) { dp[i][0] = 0; } for (int j = 1; j < n; j++) { for (int i = 1; i <= w; i++) { dp[j][i] = dp[j - 1][i]; if (i - wt[j] >= 0) { dp[j][i] = max(dp[j - 1][i], dp[j - 1][i - wt[j]] + val[j]); } } } // for(int i=0;i<=w;i++){ // for(int j=0;j<n;j++){ // cout<<j<<","<<i<<":"<<dp[j][i]<<endl; // } // } cout << dp[n - 1][w]; // ans[0]=0; // cin>>n>>w; // for (int i=0;i<n;i++){ // cin>>a>>b; // wt[i]=a; // val[i]=b; // } // for(int i=1;i<=w;i++){ // for(int j=0;j<n;j++){ // if(i-wt[j]>=0){ // if(raand.count(j) == 0 && ans[i-wt[j]]>-1 && i-wt[j] != // wt[j]){ raand.insert(j); value=ans[i-wt[j]]+val[j]; if(value>ans[i]){ // ans[i]=value; // } // } // } // } // raand.clear(); // cout<<i<<":"<<ans[i]<<endl; // } // cout<<ans[w]; // int n; // int b; // cin>>n; // vector<int> ar(n,0); // vector<int> a(n,0); // for (int k = 0; k < n ; k++){ // cin>>b; // ar[k]=b; // } // int i; // a[0]=0; // a[1]=abs(ar[0]-ar[1]); // i=2; // for (i; i < n; i++){ // if(abs(ar[i-1]-ar[i])+a[i-1]<abs(ar[i-2]-ar[i])+a[i-2]){ // a[i]=abs(ar[i-1]-ar[i])+a[i-1]; // } // else{ // a[i]=abs(ar[i-2]-ar[i])+a[i-2]; // } // } // cout<<a[n-1]; }
// Example program #include <bits/stdc++.h> using namespace std; int n, w, a, b, value; long long int dp[101][100009]; vector<long long int> wt(101, 0); vector<long long int> val(101, 0); // vector<int> ans(100009,-1); // set<int> raand; int main() { cin >> n >> w; for (int i = 0; i < n; i++) { cin >> a >> b; wt[i] = a; val[i] = b; } for (int i = 0; i <= w; i++) { for (int j = 0; j < n; j++) { dp[j][i] = 0; } } for (int i = 0; i <= w; i++) { if (wt[0] <= i) { dp[0][i] = val[0]; } } for (int i = 0; i < n; i++) { dp[i][0] = 0; } for (int j = 1; j < n; j++) { for (int i = 1; i <= w; i++) { dp[j][i] = dp[j - 1][i]; if (i - wt[j] >= 0) { dp[j][i] = max(dp[j - 1][i], dp[j - 1][i - wt[j]] + val[j]); } } } // for(int i=0;i<=w;i++){ // for(int j=0;j<n;j++){ // cout<<j<<","<<i<<":"<<dp[j][i]<<endl; // } // } cout << dp[n - 1][w]; // ans[0]=0; // cin>>n>>w; // for (int i=0;i<n;i++){ // cin>>a>>b; // wt[i]=a; // val[i]=b; // } // for(int i=1;i<=w;i++){ // for(int j=0;j<n;j++){ // if(i-wt[j]>=0){ // if(raand.count(j) == 0 && ans[i-wt[j]]>-1 && i-wt[j] != // wt[j]){ raand.insert(j); value=ans[i-wt[j]]+val[j]; if(value>ans[i]){ // ans[i]=value; // } // } // } // } // raand.clear(); // cout<<i<<":"<<ans[i]<<endl; // } // cout<<ans[w]; // int n; // int b; // cin>>n; // vector<int> ar(n,0); // vector<int> a(n,0); // for (int k = 0; k < n ; k++){ // cin>>b; // ar[k]=b; // } // int i; // a[0]=0; // a[1]=abs(ar[0]-ar[1]); // i=2; // for (i; i < n; i++){ // if(abs(ar[i-1]-ar[i])+a[i-1]<abs(ar[i-2]-ar[i])+a[i-2]){ // a[i]=abs(ar[i-1]-ar[i])+a[i-1]; // } // else{ // a[i]=abs(ar[i-2]-ar[i])+a[i-2]; // } // } // cout<<a[n-1]; }
[ "variable_declaration.type.widen.change" ]
967,931
967,932
u674113611
cpp
p03163
// // | | | ,---. o | //,---.,---.,---.,---.|---.|__/ ,---.,---.,---.' ,---. //`---.,---..,---.,---.,---.|--- //|---'| || | || || \ ,---|| |,---| `---. || ||| || //||---'| //`---'|---'`---'` '` '` ``---^|---'`---^ `---' `---'` //'`|---'|---'`---'`---' // | | | | // . , '| /| | //| | / | \ / | /__|_ // `' | o | // Version 1.4 patchnotes{ // New Feature: Dying for the river flowing // New defines: finding the max and min of three integers // New Poetry: Rose,violet // New quotes: Russian proverb // Bug fixes // } // // In the name of Allah the beneficent, the merciful // Here the Special Forces come // I know a thing and it is that I dont know nothing // One day all turks will be gone crazy, then god bless you // There's no ugly women, there's less vodka // Sub to Mcan // //█▀█─█──█──█▀█─█─█ //█▄█─█──█──█▄█─█▄█ //█─█─█▄─█▄─█─█─█─█ // //_______________%%%%%%%%%%%%%%__________________________________ //_____________%%%%%%%%%%%%%%%%%_________________________________ //____________%%%%%%%%%%%%%%%%%%%________________________________ //__________%%%%%%%%%%%%%%%%%%%%%%%______________________________ //__________%%%%%%%%%%%%%%%%%%%%%%%%_____________________________ //________%%%%%%%%%%%%%%%_____%%%%%%%____________________________ //________%%%%%%%%%%%%___________%%%%____________________________ //_______%%%%%%%%%%%%_____________%%%%___________________________ //_______%%%%%%%%%%%_______________%%%___________________________ //______%%%%%%%%%%%_________________%%%_____%%___________________ //______%%%%%%%%%%__________________________%%%__________________ //______%%%%%%%%%___________________________%%%__________________ //_____%%%%%%%%%%___________________________%%%%_________________ //_____%%%%%%%%%____________________________%%%%%%%%%%%%_________ //_____%%%%%%%%%___________________________%%%%%%%%%%%___________ //_____%%%%%%%%%_________________________%%%%%%%%%%%%____________ //_____%%%%%%%%%_______________________%%%%%%%%%%%%%_____________ //_____%%%%%%%%%_____________________%%%%%%%%%%%%%%%_____________ //_____%%%%%%%%%_________________________%%%%%%%%%%%_____________ //_____%%%%%%%%%___________________________%%%%%%%%%%____________ //_____%%%%%%%%%%___________________________%%%%%%%%%%___________ //______%%%%%%%%%___________________________%%%%%%%%%%___________ //______%%%%%%%%%___________________________%%%%____%%%__________ //_______%%%%%%%%%__________________________%%%_______%%_________ //_______%%%%%%%%%%_________________%_______%%__________%________ //________%%%%%%%%%%_______________%%_______%____________________ //________%%%%%%%%%%%_____________%%%____________________________ //_________%%%%%%%%%%%%%________%%%%_____________________________ //__________%%%%%%%%%%%%%%%%%%%%%%%______________________________ //___________%%%%%%%%%%%%%%%%%%%%%_______________________________ //____________%%%%%%%%%%%%%%%%%%%________________________________ //_____________%%%%%%%%%%%%%%%%%_________________________________ //______________%%%%%%%%%%%%%%%__________________________________ //_______________%%%%%%%%%%%%%___________________________________ //__________________%%%%%%%%_____________________________________ // _ __, _ __, __, _, __, , _ _, _,_ __, __, _ _,_ __, __, __, _, _, // _ _ _ _, _ _, | | \ | |_ |_ / \ |_) \ | / \ | | |_) |_) | | / |_ // |_) |_ | / \ | | | |\ | / _ | |_/ | |_ | \ / | \ \| \ / |_| | // \ | \ | |/ | | \ | | , \ / |/\| | | \| \ / ~ ~ ~ ~~~ ~ ~ ~ // ~ ) ~ `~' ~ ~ ~ ~ ~ ~ ~~~ ~ ~ ~ ~~~ ~ ~ ~ ~ ~ ~ ~ // ~' // // ⣠⣶⣾⣿⣿⢶⣶⡶⠦ //⠀⠀⠀⠀⠀⢀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢢ //⠀⠀⠀⠀⠀⢸⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡄ //⠀⠀⠀⠀⠀⢸⣿⠃⠀⢀⣠⣶⡆⢠⣶⣖⣻⣎⡇ //⠀⠀⠀⠀⠀⠁⡜⡄⠀⠉⠝⠋⠁⠘⣿⢿⡿⣳⠁ //⠀⠀⠀⠀⠀⠀⠀⣆⠀⠀⡠⠫⢤⣠⣿⡆⢘⡏ //⠀⠀⠀⠀⠀⠀⠀⣿⣦⡀⢧⣷⣬⢿⣽⣿⣾⠃ //⠀⠀⠀⢀⣴⣇⠙⣿⣿⣏⠚⠻⢿⣻⡿⠁ //⣤⣴⣶⣿⣿⣿⣿⣆⠈⠙⢿⣷⣾⣾⡿⣤⣤⣀ //⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠙⢿⠟⠁⣿⣿⣿⣿⣶⣄⡀ //⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⣠⣾⣦⡀⠸⣿⣿⣿⣿⣿⣿⣧ //⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠈⣿⣿⠃⠀⢿⣷⣿⣿⣿⣿⣿ // // __ // / | | //(___| ___ ___ ___ ___ ___ ___ ___ ___ ___ ___| //|\ | )|___ |___)|___ | )| )|___) | )|___)| ) //| \ |__/ __/ |__ __/ |__/|| |__ | |__ |__/ // // //| | / / / / //( ) ___ ( ___ (___ ___ ___ ___ ___ (___ ( ___ // \ /| | )| |___)| |___ | )| )|___) | )| | )|___) // \/ | |__/ | |__ |__ __/ |__/|| |__ |__/ | |__/ |__ // // // __ __ // /| / / / / | / //( | (___ ___ ___ ___ ___ ___ ( ___ ___ ___ ___ //(___| ___ ___ ___ // | | )|___)| )|___) |___ | )| | )| )\ )|___ | )| ) // | )|___ | | )| ) | | / |__ | |__ __/ |__/|| |/\/ |__/| // \_/ __/ |__/|| / | / __/ | |__/|| / // / // // __ //|/ | / / / / //|___| ___ (___ (___ ___ ___ (___ (___ ___ ___ ___ //| )|___)| | |___)| ) | | )| )| ) \ )| )| ) //|__/ |__ |__ |__ |__ | |__ | / |__/|| / \_/ |__/ |__/ // / //"Insert Problem name and code here" #include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define mp make_pair #define ii pair<int, int> #define nl '\n' #define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c) #define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c) #define fillar(x) \ for (int i = 0; i < x; i++) \ cin >> ar[i] #define qquery \ int query; \ cin >> query; \ while (query--) #define benfero \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); ll dp[101][100005]; ll ar[100005]; ll w[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // benfero int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> w[i] >> ar[i]; } dp[0][w[0] - 1] = ar[0]; for (int i = 0; i < n; i++) { if (i != 0) dp[i][w[i] - 1] = max(dp[i - 1][w[i]], ar[i]); for (int j = 0; j < m && i != 0; j++) { if (dp[i - 1][j]) { if (j + w[i] < m) dp[i][j + w[i]] = max(dp[i - 1][j], dp[i - 1][j] + ar[i]); } dp[i][j] = max(dp[i - 1][j], dp[i][j]); } } /*for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cout<<dp[i][j]<<' '; } cout<<nl; }*/ int max = 0; for (int i = 0; i < m; i++) { if (max < dp[n - 1][i]) max = dp[n - 1][i]; } cout << max; }
// // | | | ,---. o | //,---.,---.,---.,---.|---.|__/ ,---.,---.,---.' ,---. //`---.,---..,---.,---.,---.|--- //|---'| || | || || \ ,---|| |,---| `---. || ||| || //||---'| //`---'|---'`---'` '` '` ``---^|---'`---^ `---' `---'` //'`|---'|---'`---'`---' // | | | | // . , '| /| | //| | / | \ / | /__|_ // `' | o | // Version 1.4 patchnotes{ // New Feature: Dying for the river flowing // New defines: finding the max and min of three integers // New Poetry: Rose,violet // New quotes: Russian proverb // Bug fixes // } // // In the name of Allah the beneficent, the merciful // Here the Special Forces come // I know a thing and it is that I dont know nothing // One day all turks will be gone crazy, then god bless you // There's no ugly women, there's less vodka // Sub to Mcan // //█▀█─█──█──█▀█─█─█ //█▄█─█──█──█▄█─█▄█ //█─█─█▄─█▄─█─█─█─█ // //_______________%%%%%%%%%%%%%%__________________________________ //_____________%%%%%%%%%%%%%%%%%_________________________________ //____________%%%%%%%%%%%%%%%%%%%________________________________ //__________%%%%%%%%%%%%%%%%%%%%%%%______________________________ //__________%%%%%%%%%%%%%%%%%%%%%%%%_____________________________ //________%%%%%%%%%%%%%%%_____%%%%%%%____________________________ //________%%%%%%%%%%%%___________%%%%____________________________ //_______%%%%%%%%%%%%_____________%%%%___________________________ //_______%%%%%%%%%%%_______________%%%___________________________ //______%%%%%%%%%%%_________________%%%_____%%___________________ //______%%%%%%%%%%__________________________%%%__________________ //______%%%%%%%%%___________________________%%%__________________ //_____%%%%%%%%%%___________________________%%%%_________________ //_____%%%%%%%%%____________________________%%%%%%%%%%%%_________ //_____%%%%%%%%%___________________________%%%%%%%%%%%___________ //_____%%%%%%%%%_________________________%%%%%%%%%%%%____________ //_____%%%%%%%%%_______________________%%%%%%%%%%%%%_____________ //_____%%%%%%%%%_____________________%%%%%%%%%%%%%%%_____________ //_____%%%%%%%%%_________________________%%%%%%%%%%%_____________ //_____%%%%%%%%%___________________________%%%%%%%%%%____________ //_____%%%%%%%%%%___________________________%%%%%%%%%%___________ //______%%%%%%%%%___________________________%%%%%%%%%%___________ //______%%%%%%%%%___________________________%%%%____%%%__________ //_______%%%%%%%%%__________________________%%%_______%%_________ //_______%%%%%%%%%%_________________%_______%%__________%________ //________%%%%%%%%%%_______________%%_______%____________________ //________%%%%%%%%%%%_____________%%%____________________________ //_________%%%%%%%%%%%%%________%%%%_____________________________ //__________%%%%%%%%%%%%%%%%%%%%%%%______________________________ //___________%%%%%%%%%%%%%%%%%%%%%_______________________________ //____________%%%%%%%%%%%%%%%%%%%________________________________ //_____________%%%%%%%%%%%%%%%%%_________________________________ //______________%%%%%%%%%%%%%%%__________________________________ //_______________%%%%%%%%%%%%%___________________________________ //__________________%%%%%%%%_____________________________________ // _ __, _ __, __, _, __, , _ _, _,_ __, __, _ _,_ __, __, __, _, _, // _ _ _ _, _ _, | | \ | |_ |_ / \ |_) \ | / \ | | |_) |_) | | / |_ // |_) |_ | / \ | | | |\ | / _ | |_/ | |_ | \ / | \ \| \ / |_| | // \ | \ | |/ | | \ | | , \ / |/\| | | \| \ / ~ ~ ~ ~~~ ~ ~ ~ // ~ ) ~ `~' ~ ~ ~ ~ ~ ~ ~~~ ~ ~ ~ ~~~ ~ ~ ~ ~ ~ ~ ~ // ~' // // ⣠⣶⣾⣿⣿⢶⣶⡶⠦ //⠀⠀⠀⠀⠀⢀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢢ //⠀⠀⠀⠀⠀⢸⣿⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡄ //⠀⠀⠀⠀⠀⢸⣿⠃⠀⢀⣠⣶⡆⢠⣶⣖⣻⣎⡇ //⠀⠀⠀⠀⠀⠁⡜⡄⠀⠉⠝⠋⠁⠘⣿⢿⡿⣳⠁ //⠀⠀⠀⠀⠀⠀⠀⣆⠀⠀⡠⠫⢤⣠⣿⡆⢘⡏ //⠀⠀⠀⠀⠀⠀⠀⣿⣦⡀⢧⣷⣬⢿⣽⣿⣾⠃ //⠀⠀⠀⢀⣴⣇⠙⣿⣿⣏⠚⠻⢿⣻⡿⠁ //⣤⣴⣶⣿⣿⣿⣿⣆⠈⠙⢿⣷⣾⣾⡿⣤⣤⣀ //⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠙⢿⠟⠁⣿⣿⣿⣿⣶⣄⡀ //⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⣠⣾⣦⡀⠸⣿⣿⣿⣿⣿⣿⣧ //⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣆⠈⣿⣿⠃⠀⢿⣷⣿⣿⣿⣿⣿ // // __ // / | | //(___| ___ ___ ___ ___ ___ ___ ___ ___ ___ ___| //|\ | )|___ |___)|___ | )| )|___) | )|___)| ) //| \ |__/ __/ |__ __/ |__/|| |__ | |__ |__/ // // //| | / / / / //( ) ___ ( ___ (___ ___ ___ ___ ___ (___ ( ___ // \ /| | )| |___)| |___ | )| )|___) | )| | )|___) // \/ | |__/ | |__ |__ __/ |__/|| |__ |__/ | |__/ |__ // // // __ __ // /| / / / / | / //( | (___ ___ ___ ___ ___ ___ ( ___ ___ ___ ___ //(___| ___ ___ ___ // | | )|___)| )|___) |___ | )| | )| )\ )|___ | )| ) // | )|___ | | )| ) | | / |__ | |__ __/ |__/|| |/\/ |__/| // \_/ __/ |__/|| / | / __/ | |__/|| / // / // // __ //|/ | / / / / //|___| ___ (___ (___ ___ ___ (___ (___ ___ ___ ___ //| )|___)| | |___)| ) | | )| )| ) \ )| )| ) //|__/ |__ |__ |__ |__ | |__ | / |__/|| / \_/ |__/ |__/ // / //"Insert Problem name and code here" #include <algorithm> #include <cmath> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define mp make_pair #define ii pair<int, int> #define nl '\n' #define max3(a, b, c) max(a, b) > max(b, c) ? max(a, b) : max(b, c) #define min3(a, b, c) min(a, b) < min(b, c) ? min(a, b) : min(b, c) #define fillar(x) \ for (int i = 0; i < x; i++) \ cin >> ar[i] #define qquery \ int query; \ cin >> query; \ while (query--) #define benfero \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); ll dp[101][100005]; ll ar[100005]; ll w[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // benfero int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> w[i] >> ar[i]; } dp[0][w[0] - 1] = ar[0]; for (int i = 0; i < n; i++) { if (i != 0) dp[i][w[i] - 1] = max(dp[i - 1][w[i]], ar[i]); for (int j = 0; j < m && i != 0; j++) { if (dp[i - 1][j]) { if (j + w[i] < m) dp[i][j + w[i]] = max(dp[i - 1][j], dp[i - 1][j] + ar[i]); } dp[i][j] = max(dp[i - 1][j], dp[i][j]); } } /*for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cout<<dp[i][j]<<' '; } cout<<nl; }*/ ll max = 0; for (int i = 0; i < m; i++) { if (max < dp[n - 1][i]) max = dp[n - 1][i]; } cout << max; }
[ "variable_declaration.type.change" ]
967,935
967,936
u058612320
cpp
p03163
#include <bits/stdc++.h> using namespace std; long long memo[10005][10005]; long long w[1005], v[1005]; long long sum, pos; long long N, W; long long knap(long long pos, long long sum) { if (memo[pos][sum] != -1) return memo[pos][sum]; if (pos == N) { return 0; } else if (sum + w[pos] > W) { return memo[pos][sum] = knap(pos + 1, sum); } else { return memo[pos][sum] = max(knap(pos + 1, sum), knap(pos + 1, sum + w[pos]) + v[pos]); } } int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i]; cin >> v[i]; } memset(memo, -1, sizeof(memo)); sum = 0; pos = 0; cout << knap(pos, sum) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long memo[105][100005]; long long w[105], v[105]; long long sum, pos; long long N, W; long long knap(long long pos, long long sum) { if (memo[pos][sum] != -1) return memo[pos][sum]; if (pos == N) { return 0; } else if (sum + w[pos] > W) { return memo[pos][sum] = knap(pos + 1, sum); } else { return memo[pos][sum] = max(knap(pos + 1, sum), knap(pos + 1, sum + w[pos]) + v[pos]); } } int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i]; cin >> v[i]; } memset(memo, -1, sizeof(memo)); sum = 0; pos = 0; cout << knap(pos, sum) << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
967,946
967,947
u935028161
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define REP(i, a) for (int i = 0; i < (a); i++) #define ALL(a) (a).begin(), (a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 1e9 + 7; #define MAX_N 100 #define MAX_W 100000 int dp[MAX_N + 1][MAX_W + 1]; signed main() { int N, W; cin >> N >> W; int w[N], v[N]; REP(i, N) { cin >> w[i] >> v[i]; } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]); } } } cout << dp[N][W] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a) for (int i = 0; i < (a); i++) #define ALL(a) (a).begin(), (a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const int MOD = 1e9 + 7; #define MAX_N 100 #define MAX_W 100000 ll dp[MAX_N + 1][MAX_W + 1]; signed main() { int N, W; cin >> N >> W; int w[N]; ll v[N]; REP(i, N) { cin >> w[i] >> v[i]; } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]); } } } cout << dp[N][W] << endl; return 0; }
[ "variable_declaration.type.change" ]
967,948
967,949
u366398972
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { LL i, j, k, l, m, n, w; cin >> n >> w; LL cost[n + 10], wt[n + 10]; LL dp[n + 10][w + 10]; memset(dp, 0, sizeof dp); for (i = 1; i <= n; i++) cin >> wt[i] >> cost[i]; for (i = 1; i <= n; i++) { for (j = 1; j <= w; j++) { if (wt[i] <= j) { dp[i][j] = max(cost[i] + dp[i][j - wt[i]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { LL i, j, k, l, m, n, w; cin >> n >> w; LL cost[n + 10], wt[n + 10]; LL dp[n + 10][w + 10]; memset(dp, 0, sizeof dp); for (i = 1; i <= n; i++) cin >> wt[i] >> cost[i]; for (i = 1; i <= n; i++) { for (j = 1; j <= w; j++) { if (wt[i] <= j) { dp[i][j] = max(cost[i] + dp[i - 1][j - wt[i]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; // cout<<dp[i][j]<<" "; } // cout<<endl; } cout << dp[n][w] << endl; }
[]
967,952
967,953
u313897800
cpp
p03163
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int n, W; cin >> n >> W; vector<pair<int, int>> v; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; v.push_back({a, b}); } int dp[n + 1][W + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= W; ++j) { if (v[i].first > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], v[i].second + dp[i - 1][j - v[i].first]); } } cout << dp[n][W]; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { int n, W; cin >> n >> W; vector<pair<int, int>> v; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; v.push_back({a, b}); } int dp[n + 1][W + 1]; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= W; ++j) { if (v[i - 1].first > j) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], v[i - 1].second + dp[i - 1][j - v[i - 1].first]); } } cout << dp[n][W]; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one", "assignment.change" ]
967,954
967,955
u006970274
cpp
p03163
using namespace std; #include <iostream> #include <vector> int N, M; int ans = 1; const int maxW = 100001; const int maxN = 101; long DP[maxW][maxN]; long w[maxN]; long v[maxN]; int main() { int N, W; int a, b; cin >> N >> W; for (int i = 1; i < N; i++) { cin >> a >> b; w[i] = a; v[i] = b; } for (int wj = 0; wj <= W; wj++) { DP[wj][0] = 0; } for (int i = 1; i <= N; i++) { for (int wj = 0; wj <= W; wj++) { if (wj < w[i]) { DP[wj][i] = DP[wj][i - 1]; } else { DP[wj][i] = max(DP[wj][i - 1], DP[wj - w[i]][i - 1] + v[i]); } } } cout << DP[W][N] << endl; }
using namespace std; #include <iostream> #include <vector> int N, M; int ans = 1; const int maxW = 100001; const int maxN = 101; long DP[maxW][maxN]; long w[maxN]; long v[maxN]; int main() { int N, W; int a, b; cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> a >> b; w[i] = a; v[i] = b; } for (int wj = 0; wj <= W; wj++) { DP[wj][0] = 0; } for (int i = 1; i <= N; i++) { for (int wj = 0; wj <= W; wj++) { if (wj < w[i]) { DP[wj][i] = DP[wj][i - 1]; } else { DP[wj][i] = max(DP[wj][i - 1], DP[wj - w[i]][i - 1] + v[i]); } } } cout << DP[W][N] << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
967,963
967,964
u068692021
cpp
p03163
#include <bits/stdc++.h> using namespace std; long long dp[123][123456]; int main() { int N; int W; cin >> N >> W; vector<int> w(N); vector<long long> v(N); memset(dp, -1, sizeof dp); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0][w[0]] = v[0]; for (int i = 1; i < N; i++) { dp[i][w[i]] = v[i]; for (int u = 0; u < W; u++) { if (dp[i][u] == -1) dp[i][u] = dp[i - 1][u]; if (u > w[i] and dp[i - 1][u - w[i]] > 0) dp[i][u] = max(dp[i][u], dp[i - 1][u - w[i]] + v[i]); } } long long res = -1; for (int i = 0; i <= W; i++) { res = max(res, dp[N - 1][i]); } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; long long dp[123][123456]; int main() { int N; int W; cin >> N >> W; vector<int> w(N); vector<long long> v(N); memset(dp, -1, sizeof dp); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0][w[0]] = v[0]; for (int i = 1; i < N; i++) { dp[i][w[i]] = v[i]; for (int u = 0; u <= W; u++) { if (dp[i][u] == -1) dp[i][u] = dp[i - 1][u]; if (u > w[i] and dp[i - 1][u - w[i]] > 0) dp[i][u] = max(dp[i][u], dp[i - 1][u - w[i]] + v[i]); } } long long res = -1; for (int i = 0; i <= W; i++) { res = max(res, dp[N - 1][i]); } cout << res << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
967,972
967,973
u097325550
cpp
p03163
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define forr(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define ford(i, n) for (int i = n; i > 0; i--) #define forin(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair #define mt make_tuple #define debug(x) cerr << #x << " " << x << "\n"; #define yn \ { puts("YES"); } \ else { \ puts("NO"); \ } #define maxs(x, y) (x = max(x, y)) #define sz(x) (int)(x).size() #define mins(x, y) (x = min(x, y)) #define newline cout << "\n" using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef vector<ll> vl; int dp[12345] = {}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, W, w, v; cin >> n >> W; forn(i, n) { cin >> w >> v; forr(j, W - w + 1) { maxs(dp[j + w], dp[j] + v); } } cout << dp[W]; newline; return 0; }
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define forr(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define ford(i, n) for (int i = n; i > 0; i--) #define forin(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define all(a) a.begin(), a.end() #define pb push_back #define mp make_pair #define mt make_tuple #define debug(x) cerr << #x << " " << x << "\n"; #define yn \ { puts("YES"); } \ else { \ puts("NO"); \ } #define maxs(x, y) (x = max(x, y)) #define sz(x) (int)(x).size() #define mins(x, y) (x = min(x, y)) #define newline cout << "\n" using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef vector<ll> vl; ll dp[200005] = {}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, W, w, v; cin >> n >> W; forn(i, n) { cin >> w >> v; forr(j, W - w + 1) { maxs(dp[j + w], dp[j] + v); } } cout << dp[W]; return 0; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
967,980
967,979
u333759455
cpp
p03163
// knapsack 0-1 #include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; int main() { fastIO int test = 1; // cin >> test; while (test--) { int n; cin >> n; int W, weight[n], value[n]; cin >> W; int i; f(i, 0, n) cin >> weight[i] >> value[i]; int dp[n + 1][W + 1]; int j; f(i, 0, n + 1) { f(j, 0, W + 1) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= weight[i - 1]) dp[i][j] = max(dp[i - 1][j], value[i - 1] + dp[i - 1][j - weight[i - 1]]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][W]; } }
// knapsack 0-1 #include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; int main() { fastIO int test = 1; // cin >> test; while (test--) { int n; cin >> n; ll W, weight[n], value[n]; cin >> W; int i; f(i, 0, n) cin >> weight[i] >> value[i]; ll dp[n + 1][W + 1]; int j; f(i, 0, n + 1) { f(j, 0, W + 1) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= weight[i - 1]) dp[i][j] = max(dp[i - 1][j], value[i - 1] + dp[i - 1][j - weight[i - 1]]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][W]; } }
[ "variable_declaration.type.change" ]
967,981
967,982
u390664767
cpp
p03163
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; ll max(ll a, ll b) { return a < b ? b : a; } int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; ll weight[n], i, j; ll value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; int knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][j] = 0; else if (weight[i - 1] <= j) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; ll max(ll a, ll b) { return a < b ? b : a; } int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; ll weight[n], i, j; ll value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; ll knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][j] = 0; else if (weight[i - 1] <= j) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
[ "variable_declaration.type.change" ]
967,983
967,984
u390664767
cpp
p03163
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; ll max(ll a, ll b) { return a < b ? b : a; } int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; ll weight[n], i, j; ll value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; int knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][j] = 0; else if (weight[i] <= j) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; ll max(ll a, ll b) { return a < b ? b : a; } int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; ll weight[n], i, j; ll value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; ll knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][j] = 0; else if (weight[i - 1] <= j) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
[ "variable_declaration.type.change", "control_flow.branch.if.condition.change" ]
967,985
967,984
u390664767
cpp
p03163
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; int weight[n], i, j; long int value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; ll knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][j] = 0; else if (weight[i - 1] <= w) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; int weight[n], i, j; long int value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; ll knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][j] = 0; else if (weight[i - 1] <= j) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
967,986
967,987
u390664767
cpp
p03163
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; int weight[n], i, j; long int value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; ll knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][w] = 0; else if (weight[i - 1] <= w) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
#include <bits/stdc++.h> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); #define ll long long #define f(i, l, r) for (i = l; i < r; i++) #define fd(i, l, r) for (i = l; i > r; i--) #define mod 1000000007 #define pb push_back using namespace std; typedef pair<int, int> pi; int main() { fastIO int test = 1; // cin >> test; while (test--) { int n, w; cin >> n >> w; int weight[n], i, j; long int value[n]; f(i, 0, n) cin >> weight[i] >> value[i]; ll knapsack[n + 1][w + 1]; f(i, 0, n + 1) { f(j, 0, w + 1) { if (i == 0 || j == 0) knapsack[i][j] = 0; else if (weight[i - 1] <= j) knapsack[i][j] = max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]], knapsack[i - 1][j]); else knapsack[i][j] = knapsack[i - 1][j]; } } cout << knapsack[n][w]; } }
[ "assignment.variable.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
967,988
967,987
u390664767
cpp
p03163
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; #define PI 3.141592653589793 int main() { int N, W; cin >> N >> W; int A[N], V[N]; rep(i, N) { cin >> A[i] >> V[i]; } int dp[N + 1][W + 1] = {}; rep(i, N) { rep(j, W + 1) { if (j >= A[i]) dp[i + 1][j] = max(dp[i][j - A[i]] + V[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } } cout << dp[N][W] << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) using ll = long long; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; const ll mod = 1e9 + 7; #define PI 3.141592653589793 int main() { int N, W; cin >> N >> W; ll A[N], V[N]; rep(i, N) { cin >> A[i] >> V[i]; } ll dp[N + 1][W + 1] = {}; rep(i, N) { rep(j, W + 1) { if (j >= A[i]) dp[i + 1][j] = max(dp[i][j - A[i]] + V[i], dp[i][j]); else dp[i + 1][j] = dp[i][j]; } } cout << dp[N][W] << endl; }
[ "variable_declaration.type.change" ]
967,992
967,993
u841131859
cpp
p03163
#include <bits/stdc++.h> #include <iostream> #include <stdlib.h> #include <string> using namespace std; int memo[102][100002] = {-1}; long long compute(int n, int w, int item, int total, int weight[], long long value[]) { if (item >= n) { return 0; } if (memo[item][total] != -1) { return memo[item][total]; } if (weight[item] + total > w) { int answer = compute(n, w, item + 1, total, weight, value); memo[item][total] = answer; return answer; } int answer = max(compute(n, w, item + 1, total, weight, value), compute(n, w, item + 1, total + weight[item], weight, value) + value[item]); memo[item][total] = answer; return answer; } int main() { int n; int w; cin >> n >> w; int weight[n] = {0}; long long value[n] = {0}; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; for (int j = 0; j <= w; j++) { memo[i][j] = -1; } } cout << compute(n, w, 0, 0, weight, value) << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> #include <stdlib.h> #include <string> using namespace std; long long memo[102][100002] = {-1}; long long compute(int n, int w, int item, int total, int weight[], long long value[]) { if (item >= n) { return 0; } if (memo[item][total] != -1) { return memo[item][total]; } if (weight[item] + total > w) { long long answer = compute(n, w, item + 1, total, weight, value); memo[item][total] = answer; return answer; } long long answer = max(compute(n, w, item + 1, total, weight, value), compute(n, w, item + 1, total + weight[item], weight, value) + value[item]); memo[item][total] = answer; return answer; } int main() { int n; int w; cin >> n >> w; int weight[n] = {0}; long long value[n] = {0}; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; for (int j = 0; j <= w; j++) { memo[i][j] = -1; } } cout << compute(n, w, 0, 0, weight, value) << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
967,994
967,995
u058597183
cpp
p03163
#include <algorithm> #include <climits> #include <iostream> #define SIZE 100002 #define INF INT_MAX >> 1 using namespace std; typedef long long ll; ll dp[101][SIZE]; // dp[n][w] := max_value int main(void) { ll n, w; cin >> n >> w; pair<ll, ll> p[101]; //(w, v) for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } //配るDP for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j + p[i].first <= w) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + p[i].first] + p[i].second); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } ll ans = dp[n][w]; // for(int i=0; i<=w; i++){// <=であることに注意 // ans = max(ans, dp[n][i]); //} cout << ans << endl; }
#include <algorithm> #include <climits> #include <iostream> #define SIZE 100002 #define INF INT_MAX >> 1 using namespace std; typedef long long ll; ll dp[101][SIZE]; // dp[n][w] := max_value int main(void) { ll n, w; cin >> n >> w; pair<ll, ll> p[101]; //(w, v) for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j - p[i].first >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - p[i].first] + p[i].second); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } ll ans = dp[n][w]; // for(int i=0; i<=w; i++){// <=であることに注意 // ans = max(ans, dp[n][i]); //} cout << ans << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
968,000
968,001
u117734686
cpp
p03163
#include <algorithm> #include <climits> #include <iostream> #define SIZE 100002 #define INF INT_MAX >> 1 using namespace std; typedef long long ll; ll dp[101][SIZE]; // dp[n][w] := max_value int main(void) { ll n, w; cin >> n >> w; pair<ll, ll> p[101]; //(w, v) for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } //配るDP for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j - p[i].first >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + p[i].first] + p[i].second); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } ll ans = dp[n][w]; // for(int i=0; i<=w; i++){// <=であることに注意 // ans = max(ans, dp[n][i]); //} cout << ans << endl; }
#include <algorithm> #include <climits> #include <iostream> #define SIZE 100002 #define INF INT_MAX >> 1 using namespace std; typedef long long ll; ll dp[101][SIZE]; // dp[n][w] := max_value int main(void) { ll n, w; cin >> n >> w; pair<ll, ll> p[101]; //(w, v) for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j - p[i].first >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - p[i].first] + p[i].second); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } ll ans = dp[n][w]; // for(int i=0; i<=w; i++){// <=であることに注意 // ans = max(ans, dp[n][i]); //} cout << ans << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
968,002
968,001
u117734686
cpp
p03163
#include <algorithm> #include <climits> #include <iostream> #define SIZE 100002 #define INF INT_MAX >> 1 using namespace std; typedef long long ll; ll dp[101][SIZE]; // dp[n][w] := max_value int main(void) { ll n, w; cin >> n >> w; pair<ll, ll> p[101]; //(w, v) for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } //配るDP for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j - p[i].first >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + p[i].first] + p[i].second); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } ll ans = dp[n][w]; // for(int i=0; i<=w; i++){// <=であることに注意 // ans = max(ans, dp[n][i]); //} cout << ans << endl; }
#include <algorithm> #include <climits> #include <iostream> #define SIZE 100002 #define INF INT_MAX >> 1 using namespace std; typedef long long ll; ll dp[101][SIZE]; // dp[n][w] := max_value int main(void) { ll n, w; cin >> n >> w; pair<ll, ll> p[101]; //(w, v) for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } //配るDP for (int i = 0; i < n; i++) { for (int j = 0; j <= w; j++) { if (j - p[i].first >= 0) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - p[i].first] + p[i].second); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } ll ans = dp[n][w]; // for(int i=0; i<=w; i++){// <=であることに注意 // ans = max(ans, dp[n][i]); //} cout << ans << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
968,002
968,003
u117734686
cpp
p03163
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; // typedef vector<unsigned int>vec; typedef vector<ll> vec; typedef vector<vec> mat; typedef vector<vector<int>> Graph; 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 int INF = 1000000000; const ll LINF = 1000000000000000000; // 1e18 const ll MOD = 1000000007; const double PI = acos(-1.0); const double EPS = 1e-10; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void add(T &a, T b) { a = ((a + b) % MOD + MOD) % MOD; }; ll dp[111][101010]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector<ll> w(N), v(N); REP(i, N) cin >> w[i] >> v[i]; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j - w[i] >= 0) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); else dp[i + 1][j] = dp[i][j]; } } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; // typedef vector<unsigned int>vec; typedef vector<ll> vec; typedef vector<vec> mat; typedef vector<vector<int>> Graph; 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 int INF = 1000000000; const ll LINF = 1000000000000000000; // 1e18 const ll MOD = 1000000007; const double PI = acos(-1.0); const double EPS = 1e-10; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline void add(T &a, T b) { a = ((a + b) % MOD + MOD) % MOD; }; ll dp[111][101010]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector<ll> w(N), v(N); REP(i, N) cin >> w[i] >> v[i]; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j - w[i] >= 0) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
[ "call.arguments.change" ]
968,009
968,010
u493750228
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; int w[N + 1], v[N + 1], dp[N + 1][W + 1]; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int i = 0; i <= N; i++) dp[i][0] = 0; for (int i = 0; i <= W; i++) dp[0][i] = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (j - w[i] < 0) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]); } } cout << dp[N][W] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; long long w[N + 1], v[N + 1], dp[N + 1][W + 1]; for (int i = 1; i <= N; i++) cin >> w[i] >> v[i]; for (int i = 0; i <= N; i++) dp[i][0] = 0; for (int i = 0; i <= W; i++) dp[0][i] = 0; for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (j - w[i] < 0) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]); } } cout << dp[N][W] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,013
968,014
u122034453
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair const int N = 105; const int M = 100050; int dp[N][M], w[N], v[N]; int main() { int n, W; scanf("%i %i", &n, &W); for (int i = 1; i <= n; i++) scanf("%i %i", &w[i], &v[i]); for (int i = 1; i <= n; i++) for (int j = 1; j <= W; j++) dp[i][j] = max(dp[i - 1][j], j >= w[i] ? dp[i - 1][j - w[i]] + v[i] : 0); printf("%i", dp[n][W]); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair const int N = 105; const int M = 100050; ll dp[N][M], w[N], v[N]; int main() { int n, W; scanf("%i %i", &n, &W); for (int i = 1; i <= n; i++) scanf("%lld %lld", &w[i], &v[i]); for (int i = 1; i <= n; i++) for (int j = 1; j <= W; j++) dp[i][j] = max(dp[i - 1][j], j >= w[i] ? dp[i - 1][j - w[i]] + v[i] : 0); printf("%lld", dp[n][W]); return 0; }
[ "variable_declaration.type.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
968,022
968,023
u939096624
cpp
p03163
#include <climits> #include <cstring> #include <iostream> using namespace std; int n, m; long long a[105], b[100005], c[100005]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i] >> c[i]; for (int i = 1; i <= n; i++) { for (int j = m; j >= a[i]; j--) { b[j] = max(b[j - a[i]] + c[i], b[i]); } } cout << b[m]; return 0; }
#include <climits> #include <cstring> #include <iostream> using namespace std; int n, m; long long a[105], b[100005], c[105]; int main() { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i] >> c[i]; for (int i = 1; i <= n; i++) { for (int j = m; j >= a[i]; j--) { b[j] = max(b[j - a[i]] + c[i], b[j]); } } cout << b[m]; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change", "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change" ]
968,030
968,031
u798562499
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { int N, W; cin >> N >> W; vector<int> w(N); vector<int> v(N); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (w[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - w[i - 1]]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[N][W]; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { int N, W; cin >> N >> W; vector<ll> w(N); vector<ll> v(N); for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0)); for (int i = 1; i <= N; i++) { for (int j = 1; j <= W; j++) { if (w[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - w[i - 1]]); } else { dp[i][j] = dp[i - 1][j]; } } } cout << dp[N][W]; }
[ "call.arguments.change" ]
968,035
968,036
u741856489
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int w; cin >> w; vector<int> wt(n), val(n); for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int w; cin >> w; vector<int> wt(n), val(n); for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } vector<vector<long long>> dp(n + 1, vector<long long>(w + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,037
968,038
u415096441
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int w; cin >> w; vector<int> wt(n), val(n); for (int i = 0; i < n; i++) { cin >> val[i] >> wt[i]; } vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int w; cin >> w; vector<int> wt(n), val(n); for (int i = 0; i < n; i++) { cin >> wt[i] >> val[i]; } vector<vector<long long>> dp(n + 1, vector<long long>(w + 1, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= w; j++) { if (wt[i - 1] <= j) { dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - wt[i - 1]]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; }
[ "identifier.change", "expression.operation.binary.change", "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,039
968,038
u415096441
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int W; cin >> W; int w[n]; int v[n]; for (int i = 0; i < n; i++) { cin >> w[i]; cin >> v[i]; } int dp[n][W + 1]; for (int i = 0; i < n; i++) { dp[i][0] = 0; } for (int i = 0; i < W + 1; i++) { if (i < w[0]) dp[0][i] = 0; else dp[0][i] = v[0]; } for (int i = 1; i < n; i++) { for (int j = 1; j < W + 1; j++) { if (j < w[i]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(v[i] + dp[i - 1][j - w[i]], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i < W + 1; i++) { ans = max(ans, dp[n - 1][i]); } // for(int i =0 ; i<n ; i++) // { // for(int j = 0 ; j<W+1 ; j++) // cout<<dp[i][j]<<" "; // cout<<"\n"; // } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; int W; cin >> W; int w[n]; int v[n]; for (int i = 0; i < n; i++) { cin >> w[i]; cin >> v[i]; } int dp[n][W + 1]; for (int i = 0; i < n; i++) { dp[i][0] = 0; } for (int i = 0; i < W + 1; i++) { if (i < w[0]) dp[0][i] = 0; else dp[0][i] = v[0]; } for (int i = 1; i < n; i++) { for (int j = 1; j < W + 1; j++) { if (j < w[i]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(v[i] + dp[i - 1][j - w[i]], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i < W + 1; i++) { ans = max(ans, dp[n - 1][i]); } // for(int i =0 ; i<n ; i++) // { // for(int j = 0 ; j<W+1 ; j++) // cout<<dp[i][j]<<" "; // cout<<"\n"; // } cout << ans; return 0; }
[ "variable_declaration.type.widen.change" ]
968,055
968,056
u236295472
cpp
p03163
#include <fstream> #include <iostream> #include <utility> using namespace std; int n, w, f[109][100009]; pair<int, int> p[109]; int main() { // freopen("knapsack1.inp", "r", stdin); // freopen("knapsack1.out", "w", stdout); cin >> n >> w; for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second; for (int i = 1; i <= w; i++) { if (i >= p[1].first) f[1][i] = p[1].second; else f[1][i] = 0; } for (int i = 2; i <= n; i++) { for (int j = 1; j <= w; j++) { if (p[i].first > j) f[i][j] = f[i - 1][j]; else f[i][j] = max(f[i - 1][j], f[i - 1][j - p[i].first] + p[i].second); } } cout << f[n][w]; return 0; }
#include <fstream> #include <iostream> #include <utility> using namespace std; int n, w; long long f[109][100009]; pair<int, int> p[109]; int main() { // freopen("knapsack1.inp", "r", stdin); // freopen("knapsack1.out", "w", stdout); cin >> n >> w; for (int i = 1; i <= n; i++) cin >> p[i].first >> p[i].second; for (int i = 1; i <= w; i++) { if (i >= p[1].first) f[1][i] = p[1].second; else f[1][i] = 0; } for (int i = 2; i <= n; i++) { for (int j = 1; j <= w; j++) { if (p[i].first > j) f[i][j] = f[i - 1][j]; else f[i][j] = max(f[i - 1][j], f[i - 1][j - p[i].first] + p[i].second); } } cout << f[n][w]; return 0; }
[ "variable_declaration.type.widen.change" ]
968,057
968,058
u154608739
cpp
p03163
// be name khoda \\ // #define stream_enable // #define long_enable #define debug_enable #include <algorithm> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> using namespace std; #ifdef stream_enable #define cin sss #endif #ifdef long_enable typedef long long int ll; #else typedef int ll; #endif typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef pair<ll, pii> pip; typedef pair<pii, ll> ppi; typedef pair<pii, pii> ppp; typedef vector<vi> vii; typedef vector<vii> viii; typedef vector<bool> vb; typedef vector<vb> vbb; typedef vector<pii> vpii; typedef vector<pip> vpip; const ll MOD = 1000000007; const long long BIG = 1446803456761533460LL; const int Big = 336860180; #ifdef long_enable const ll INF = LONG_LONG_MAX; #else const ll INF = INT_MAX; #endif const ll adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const ll adj8[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; #define mp make_pair #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define pb push_back #define print(x) cout << (x) << '\n' #define print2(x, y) cout << (x) << ' ' << (y) << '\n' #define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n' #define print4(x, y, z, t) \ cout << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << '\n' #define printv(x) \ fori(j12345, (x).size()) { cout << (x)[j12345] << ' '; } \ cout << '\n' #define printvv(x) \ fori(i123456, (x).size()) { \ fori(j123456, (x)[i123456].size()) { \ cout << (x)[i123456][j123456] << ' '; \ } \ cout << '\n'; \ } #define printp(x) cout << "(" << x.ff << ", " << x.ss << ")" << '\n' #define printvp(x) \ fori(i1234567, (x).size()) { \ cout << "(" << x[i1234567].ff << ", " << x[i1234567].ss << ")" << '\n'; \ } #define printa(x, n) \ fori(ja12345, n) { cout << (x)[ja12345] << ' '; } \ cout << '\n' #define printap(x, n) \ fori(ia1234567, n) { \ cout << "(" << x[ia1234567].ff << ", " << x[ia1234567].ss << ")" << '\n'; \ } #define printaa(x, n, m) \ fori(iaa123456, n) { \ fori(jaa123456, m) { cout << (x)[iaa123456][jaa123456] << ' '; } \ cout << '\n'; \ } #define printav(x, n) \ fori(iaa123477, n) { printv(x[iaa123477]); } #define printia(x, n) \ fori(ja212345, n) { cout << ja212345 << " : " << (x)[ja212345] << '\n'; } #ifdef debug_enable #define debug(x) \ cout << #x << " -> "; \ print(x) #define debug2(x, y) \ cout << #x << ' ' << #y << " -> "; \ print2(x, y) #define debug3(x, y, z) \ cout << #x << ' ' << #y << ' ' << #z << " -> "; \ print3(x, y, z) #define debug4(x, y, z, t) \ cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> "; \ print4(x, y, z, t) #define debugv(x) \ cout << #x << " -> "; \ printv(x) #define debugvv(x) \ cout << #x << " ->\n"; \ printvv(x) #define debugp(x) \ cout << #x << " -> "; \ printp(x) #define debugvp(x) \ cout << #x << " ->\n"; \ printvp(x) #define debuga(x, n) \ cout << #x << " -> "; \ printa(x, n) #define debugap(x, n) \ cout << #x << " ->\n"; \ printap(x, n) #define debugaa(x, n, m) \ cout << #x << " ->\n"; \ printaa(x, n, m) #define debugav(x, n) \ cout << #x << " ->\n"; \ printav(x, n) #define debugia(x, n) \ cout << #x << " ->\n"; \ printia(x, n) ll clk_ar[10]; #define clk_s(i) clk_ar[i] = clock(); #define clk_e(i) \ cout << "Clock " << i << " : " \ << (double)(clock() - clk_ar[i]) / CLOCKS_PER_SEC << " sec\n"; #else #define debug(x) #define debug2(x, y) #define debug3(x, y, z) #define debug4(x, y, z, t) #define debugv(x) #define debugvv(x) #define debugp(x) #define debugvp(x) #define debuga(x, n) #define debugap(x, n) #define debugaa(x, n, m) #define debugav(x, n, m) #define debugia(x, n) #define clk_s(i) #define clk_e(i) #endif #define fori(i, n) for (ll i = 0; i < (n); ++i) #define forir(i, n) for (ll i = (n)-1; i >= 0; --i) #define forifrom(i, f, n) for (ll i = (f); i < (n); ++i) #define forirto(i, n, f) for (ll i = (n)-1; i >= (f); --i) #define smin(a, b) a = min(a, (b)) #define smax(a, b) a = max(a, (b)) #define inp(x) \ ll x; \ cin >> x #define inp2(x, y) \ ll x, y; \ cin >> x >> y #define inp3(x, y, z) \ ll x, y, z; \ cin >> x >> y >> z #define inp4(x, y, z, w) \ ll x, y, z, w; \ cin >> x >> y >> z >> w ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll powMod(ll a, ll b) { ll n = 1; ll p = a; while (b > 0) { if (b % 2 == 1) { n *= p; n %= MOD; } p *= p; p %= MOD; b /= 2; } return n; } ll modularInverse(ll a) { return powMod(a, MOD - 2); } stringstream sss; // ----------------------------------------------------------------------- const ll maxn = 110; const ll maxa = 100010; ll Ws[maxn]; ll Vs[maxn]; ll dp[maxa]; void MAIN() { inp2(n, W); fori(i, n) { cin >> Ws[i] >> Vs[i]; } fori(i, n) { forir(j, W + 1 - Ws[i]) { smax(dp[j + Ws[i]], dp[j] + Vs[i]); } } print(*max_element(dp, dp + W + 1)); } // ----------------------------------------------------------------------- int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); sss << R"( )"; MAIN(); return 0; }
// be name khoda \\ // #define stream_enable #define long_enable #define debug_enable #include <algorithm> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> using namespace std; #ifdef stream_enable #define cin sss #endif #ifdef long_enable typedef long long int ll; #else typedef int ll; #endif typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef pair<ll, pii> pip; typedef pair<pii, ll> ppi; typedef pair<pii, pii> ppp; typedef vector<vi> vii; typedef vector<vii> viii; typedef vector<bool> vb; typedef vector<vb> vbb; typedef vector<pii> vpii; typedef vector<pip> vpip; const ll MOD = 1000000007; const long long BIG = 1446803456761533460LL; const int Big = 336860180; #ifdef long_enable const ll INF = LONG_LONG_MAX; #else const ll INF = INT_MAX; #endif const ll adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; const ll adj8[8][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {-1, -1}, {1, -1}, {-1, 1}, {1, 1}}; #define mp make_pair #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define pb push_back #define print(x) cout << (x) << '\n' #define print2(x, y) cout << (x) << ' ' << (y) << '\n' #define print3(x, y, z) cout << (x) << ' ' << (y) << ' ' << (z) << '\n' #define print4(x, y, z, t) \ cout << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << '\n' #define printv(x) \ fori(j12345, (x).size()) { cout << (x)[j12345] << ' '; } \ cout << '\n' #define printvv(x) \ fori(i123456, (x).size()) { \ fori(j123456, (x)[i123456].size()) { \ cout << (x)[i123456][j123456] << ' '; \ } \ cout << '\n'; \ } #define printp(x) cout << "(" << x.ff << ", " << x.ss << ")" << '\n' #define printvp(x) \ fori(i1234567, (x).size()) { \ cout << "(" << x[i1234567].ff << ", " << x[i1234567].ss << ")" << '\n'; \ } #define printa(x, n) \ fori(ja12345, n) { cout << (x)[ja12345] << ' '; } \ cout << '\n' #define printap(x, n) \ fori(ia1234567, n) { \ cout << "(" << x[ia1234567].ff << ", " << x[ia1234567].ss << ")" << '\n'; \ } #define printaa(x, n, m) \ fori(iaa123456, n) { \ fori(jaa123456, m) { cout << (x)[iaa123456][jaa123456] << ' '; } \ cout << '\n'; \ } #define printav(x, n) \ fori(iaa123477, n) { printv(x[iaa123477]); } #define printia(x, n) \ fori(ja212345, n) { cout << ja212345 << " : " << (x)[ja212345] << '\n'; } #ifdef debug_enable #define debug(x) \ cout << #x << " -> "; \ print(x) #define debug2(x, y) \ cout << #x << ' ' << #y << " -> "; \ print2(x, y) #define debug3(x, y, z) \ cout << #x << ' ' << #y << ' ' << #z << " -> "; \ print3(x, y, z) #define debug4(x, y, z, t) \ cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> "; \ print4(x, y, z, t) #define debugv(x) \ cout << #x << " -> "; \ printv(x) #define debugvv(x) \ cout << #x << " ->\n"; \ printvv(x) #define debugp(x) \ cout << #x << " -> "; \ printp(x) #define debugvp(x) \ cout << #x << " ->\n"; \ printvp(x) #define debuga(x, n) \ cout << #x << " -> "; \ printa(x, n) #define debugap(x, n) \ cout << #x << " ->\n"; \ printap(x, n) #define debugaa(x, n, m) \ cout << #x << " ->\n"; \ printaa(x, n, m) #define debugav(x, n) \ cout << #x << " ->\n"; \ printav(x, n) #define debugia(x, n) \ cout << #x << " ->\n"; \ printia(x, n) ll clk_ar[10]; #define clk_s(i) clk_ar[i] = clock(); #define clk_e(i) \ cout << "Clock " << i << " : " \ << (double)(clock() - clk_ar[i]) / CLOCKS_PER_SEC << " sec\n"; #else #define debug(x) #define debug2(x, y) #define debug3(x, y, z) #define debug4(x, y, z, t) #define debugv(x) #define debugvv(x) #define debugp(x) #define debugvp(x) #define debuga(x, n) #define debugap(x, n) #define debugaa(x, n, m) #define debugav(x, n, m) #define debugia(x, n) #define clk_s(i) #define clk_e(i) #endif #define fori(i, n) for (ll i = 0; i < (n); ++i) #define forir(i, n) for (ll i = (n)-1; i >= 0; --i) #define forifrom(i, f, n) for (ll i = (f); i < (n); ++i) #define forirto(i, n, f) for (ll i = (n)-1; i >= (f); --i) #define smin(a, b) a = min(a, (b)) #define smax(a, b) a = max(a, (b)) #define inp(x) \ ll x; \ cin >> x #define inp2(x, y) \ ll x, y; \ cin >> x >> y #define inp3(x, y, z) \ ll x, y, z; \ cin >> x >> y >> z #define inp4(x, y, z, w) \ ll x, y, z, w; \ cin >> x >> y >> z >> w ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll powMod(ll a, ll b) { ll n = 1; ll p = a; while (b > 0) { if (b % 2 == 1) { n *= p; n %= MOD; } p *= p; p %= MOD; b /= 2; } return n; } ll modularInverse(ll a) { return powMod(a, MOD - 2); } stringstream sss; // ----------------------------------------------------------------------- const ll maxn = 110; const ll maxa = 100010; ll Ws[maxn]; ll Vs[maxn]; ll dp[maxa]; void MAIN() { inp2(n, W); fori(i, n) { cin >> Ws[i] >> Vs[i]; } fori(i, n) { forir(j, W + 1 - Ws[i]) { smax(dp[j + Ws[i]], dp[j] + Vs[i]); } } print(*max_element(dp, dp + W + 1)); } // ----------------------------------------------------------------------- int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); sss << R"( )"; MAIN(); return 0; }
[]
968,059
968,060
u780597450
cpp
p03163
#include <bits/stdc++.h> #define REP(i, s, e) for (int i = (s); i < (e); i++) #define rep(i, n) REP(i, 0, n) #define rep1(i, n) REP(i, 1, n) #define repe(i, n) for (auto &&i : n) #define all(v) (v).begin(), (v).end() #define decimal fixed << setprecision(20) #define fastcin() \ cin.tie(0); \ ios::sync_with_stdio(false) using namespace std; using LL = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const LL LLINF = 1e16; // i個目までの品物について考慮したとき // 重さjで得られる価値の最大値 // オーバーフローに注意 LL dp[110][100010]; int main() { int N, W; cin >> N >> W; vector<int> w(N), v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; for (int i = 0; i < N; i++) { for (int j = 0; j < W; j++) { if (j + w[i] <= W) { // ナップサックに入れる dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]); } // 入れない dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> #define REP(i, s, e) for (int i = (s); i < (e); i++) #define rep(i, n) REP(i, 0, n) #define rep1(i, n) REP(i, 1, n) #define repe(i, n) for (auto &&i : n) #define all(v) (v).begin(), (v).end() #define decimal fixed << setprecision(20) #define fastcin() \ cin.tie(0); \ ios::sync_with_stdio(false) using namespace std; using LL = long long; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const LL LLINF = 1e16; // i個目までの品物について考慮したとき // 重さjで得られる価値の最大値 // オーバーフローに注意 LL dp[110][100010]; int main() { int N, W; cin >> N >> W; vector<int> w(N), v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j + w[i] <= W) { // ナップサックに入れる dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]); } // 入れない dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
968,067
968,068
u996252264
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef vector<pii> vii; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long int LL; #define pb push_back #define mp make_pair #define scan(n) scanf("%d", &n) #define print(n) printf("%d\n", n) #define longscan(n) scanf("%lld", &n) #define longprint(n) printf("%lld\n", n) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) /*void sieve(int n) { for(int i=2;i*i<=100000;i++) for(int j=2*i;j<=100000;j+=i) if(!sie[j]) sie[j]=1; }*/ int main() { int n, W; cin >> n >> W; int dp[n + 1][W + 1]; memset(dp, 0, sizeof(dp)); int v[n + 1], w[n + 1]; for (int j = 0; j < n; j++) { cin >> w[j] >> v[j]; } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= W; j++) { dp[i][j] = dp[i - 1][j]; } for (int j = w[i - 1]; j <= W; j++) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]); } } cout << dp[n][W] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef vector<pii> vii; typedef vector<int> vi; typedef vector<vi> vvi; typedef long long int LL; #define pb push_back #define mp make_pair #define scan(n) scanf("%d", &n) #define print(n) printf("%d\n", n) #define longscan(n) scanf("%lld", &n) #define longprint(n) printf("%lld\n", n) #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) /*void sieve(int n) { for(int i=2;i*i<=100000;i++) for(int j=2*i;j<=100000;j+=i) if(!sie[j]) sie[j]=1; }*/ int main() { int n, W; cin >> n >> W; long long int dp[n + 1][W + 1]; memset(dp, 0, sizeof(dp)); long long int v[n + 1], w[n + 1]; for (int j = 0; j < n; j++) { cin >> w[j] >> v[j]; } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= W; j++) { dp[i][j] = dp[i - 1][j]; } for (int j = w[i - 1]; j <= W; j++) { dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]); } } cout << dp[n][W] << "\n"; return 0; }
[ "variable_declaration.type.widen.change" ]
968,073
968,074
u947521398
cpp
p03163
//$g++ -std=c++11 Template.cpp //#include <bits/stdc++.h> #include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i) #define ROF(i, j, k) for (int i = (int)(j); i >= (int)(k); --i) #define FORLL(i, n, m) for (long long i = n; i < (long long)(m); i++) #define SORT(v, n) sort(v, v + n) #define REVERSE(v) reverse((v).begin(), (v).end()) using namespace std; using ll = long long; const ll MOD = 1000000007LL; typedef pair<int, int> P; ll ADD(ll x, ll y) { return (x + y) % MOD; } ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } ll MUL(ll x, ll y) { return x * y % MOD; } ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD - 2)); } priority_queue<int> q_descending; priority_queue<int, vector<int>, greater<int>> q_ascending; int N, W; ll w[110], v[110]; ll dp[110][10010]; ll dfs(int i, int j) { if (dp[i][j] != -1) return dp[i][j]; int res; if (i == N) res = 0; else if (j < w[i]) res = dfs(i + 1, j); else res = max(dfs(i + 1, j), dfs(i + 1, j - w[i]) + v[i]); return dp[i][j] = res; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> W; REP(i, N) cin >> w[i] >> v[i]; /* // dp[i][j] := i番目までの重さW以下となる最大価値 dp[0][0] = 0; REP(i, N+1){ REP(j, W+1){ if(j-w[i] >= 0){ dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]); } else{ dp[i+1][j] = dp[i][j]; } } } cout << dp[N][W] << endl; */ memset(dp, -1, sizeof(dp)); cout << dfs(0, W) << endl; return 0; }
//$g++ -std=c++11 Template.cpp //#include <bits/stdc++.h> #include <algorithm> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i) #define ROF(i, j, k) for (int i = (int)(j); i >= (int)(k); --i) #define FORLL(i, n, m) for (long long i = n; i < (long long)(m); i++) #define SORT(v, n) sort(v, v + n) #define REVERSE(v) reverse((v).begin(), (v).end()) using namespace std; using ll = long long; const ll MOD = 1000000007LL; typedef pair<int, int> P; ll ADD(ll x, ll y) { return (x + y) % MOD; } ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } ll MUL(ll x, ll y) { return x * y % MOD; } ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD - 2)); } priority_queue<int> q_descending; priority_queue<int, vector<int>, greater<int>> q_ascending; ll N, W; ll w[110], v[110]; ll dp[110][100010]; ll dfs(ll i, ll j) { if (dp[i][j] != -1) return dp[i][j]; ll res; if (i == N) res = 0; else if (j < w[i]) res = dfs(i + 1, j); else res = max(dfs(i + 1, j), dfs(i + 1, j - w[i]) + v[i]); return dp[i][j] = res; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cin >> N >> W; REP(i, N) cin >> w[i] >> v[i]; /* // dp[i][j] := i番目までの重さW以下となる最大価値 dp[0][0] = 0; REP(i, N+1){ REP(j, W+1){ if(j-w[i] >= 0){ dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]]+v[i]); } else{ dp[i+1][j] = dp[i][j]; } } } cout << dp[N][W] << endl; */ memset(dp, -1, sizeof(dp)); cout << dfs(0, W) << endl; return 0; }
[ "variable_declaration.type.change", "literal.number.change", "variable_declaration.array_dimensions.change" ]
968,078
968,076
u783861517
cpp
p03163
#include <bits/stdc++.h> #define f(I, a, b) for (int I = a; I <= b; I++) using namespace std; int main() { int N, W; cin >> N >> W; int w[N], v[N]; f(i, 0, N - 1) cin >> w[i] >> v[i]; int dp[N + 1][W + 1] = {}; f(i, 0, N - 1) { f(j, 0, W) { if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); } else { dp[i + 1][j] = dp[i][j]; } } } int ans = 0; f(i, 0, W) { ans = max(ans, dp[N][i]); } cout << ans << endl; }
#include <bits/stdc++.h> #define f(I, a, b) for (int I = a; I <= b; I++) using namespace std; int main() { int N, W; cin >> N >> W; int w[N], v[N]; f(i, 0, N - 1) cin >> w[i] >> v[i]; long long dp[N + 1][W + 1] = {}; f(i, 0, N - 1) { f(j, 0, W) { if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); } else { dp[i + 1][j] = dp[i][j]; } } } long long int ans = 0; f(i, 0, W) { ans = max(ans, dp[N][i]); } cout << ans << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,079
968,080
u733608212
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; #define _ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define sll(x) scanf("%I64d", &x) #define sd(x) scanf("%d", &x) #define pll(x) printf("%I64d", x) #define pd(x) printf("%d", x) #define clr(x) memset(x, 0, sizeof x) #define sf .second.first #define ss .second.second #define mid ((l + r) >> 1) #define Pi acos(-1) #define EPS 1e-12 #define MOD 1000000007 #define MOD1 1000000009 #define INF 1000000000 #define N 100005 int n, w, a[200], v[200], dp[200][N]; int main() { memset(dp, 0, sizeof dp); cin >> n >> w; for (int i = 0; i < n; i++) cin >> a[i] >> v[i]; // cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j == 0 || i == 0) dp[i][j] = 0; else if (a[i - 1] <= j) dp[i][j] = max(v[i - 1] + dp[i - 1][j - a[i - 1]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; #define _ ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define sll(x) scanf("%I64d", &x) #define sd(x) scanf("%d", &x) #define pll(x) printf("%I64d", x) #define pd(x) printf("%d", x) #define clr(x) memset(x, 0, sizeof x) #define sf .second.first #define ss .second.second #define mid ((l + r) >> 1) #define Pi acos(-1) #define EPS 1e-12 #define MOD 1000000007 #define MOD1 1000000009 #define INF 1000000000 #define N 100005 ll n, w, a[200], v[200], dp[200][N]; int main() { memset(dp, 0, sizeof dp); cin >> n >> w; for (int i = 0; i < n; i++) cin >> a[i] >> v[i]; // cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j == 0 || i == 0) dp[i][j] = 0; else if (a[i - 1] <= j) dp[i][j] = max(v[i - 1] + dp[i - 1][j - a[i - 1]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << endl; return 0; }
[ "variable_declaration.type.change" ]
968,083
968,084
u113936857
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vs = vector<string>; using vvl = vector<vl>; using pll = pair<ll, ll>; using vb = vector<bool>; const ll oo = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define mp make_pair #define mt make_tuple #define pb push_back #define xx first #define yy second #define has(c, i) ((c).find(i) != end(c)) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORD(i, a, b) for (int i = int(b) - 1; i >= (a); i--) #define rv(type, name, count) \ vector<type> name(count); \ FOR(_i, 0, count) cin >> name[_i]; #define grid(type, name, c1, c2) \ vector<vector<type>> name(c1, vector<type>(c2)); \ FOR(_i, 0, c1) FOR(_j, 0, c2) cin >> name[_i][_j]; int main() { ll n, w; cin >> n >> w; vvl v(2, vl(w + 1)); FOR(i, 0, n) { ll wei, val; cin >> wei >> val; FOR(ww, 0, w + 1) { v[i % 2][ww] = v[(i + 1) % 2][ww]; if (wei <= ww) v[i % 2][ww] = max(v[i % 2][ww], val + v[(i + 1) % 2][ww - wei]); } } cout << v[n % 2][w] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vs = vector<string>; using vvl = vector<vl>; using pll = pair<ll, ll>; using vb = vector<bool>; const ll oo = 0x3f3f3f3f3f3f3f3fLL; const double eps = 1e-9; #define sz(c) ll((c).size()) #define all(c) begin(c), end(c) #define mp make_pair #define mt make_tuple #define pb push_back #define xx first #define yy second #define has(c, i) ((c).find(i) != end(c)) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORD(i, a, b) for (int i = int(b) - 1; i >= (a); i--) #define rv(type, name, count) \ vector<type> name(count); \ FOR(_i, 0, count) cin >> name[_i]; #define grid(type, name, c1, c2) \ vector<vector<type>> name(c1, vector<type>(c2)); \ FOR(_i, 0, c1) FOR(_j, 0, c2) cin >> name[_i][_j]; int main() { ll n, w; cin >> n >> w; vvl v(2, vl(w + 1)); FOR(i, 0, n) { ll wei, val; cin >> wei >> val; FOR(ww, 0, w + 1) { v[i % 2][ww] = v[(i + 1) % 2][ww]; if (wei <= ww) v[i % 2][ww] = max(v[i % 2][ww], val + v[(i + 1) % 2][ww - wei]); } } cout << v[(n + 1) % 2][w] << endl; }
[]
968,087
968,088
u278566247
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define vi vector<int> #define vl vector<long> #define vll vector<long long int> #define vC vector<char> #define FastIO \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); int dp[101][100001]; int main() { FastIO int n, W, i, j; cin >> n >> W; vi v(n + 1), w(n + 1); for (i = 1; i < n + 1; i++) { cin >> w[i] >> v[i]; } for (i = 0; i < n + 1; i++) dp[i][0] = 0; for (i = 0; i < W + 1; i++) dp[0][i] = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= W; j++) { if (w[i] <= j) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][W]; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define vi vector<int> #define vl vector<long> #define vll vector<long long int> #define vC vector<char> #define FastIO \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll dp[101][100001]; int main() { FastIO int n, W, i, j; cin >> n >> W; vll v(n + 1), w(n + 1); for (i = 1; i < n + 1; i++) { cin >> w[i] >> v[i]; } for (i = 0; i < n + 1; i++) dp[i][0] = 0; for (i = 0; i < W + 1; i++) dp[0][i] = 0; for (i = 1; i <= n; i++) { for (j = 1; j <= W; j++) { if (w[i] <= j) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][W]; }
[ "variable_declaration.type.change" ]
968,094
968,095
u710527399
cpp
p03163
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #ifdef _DEBUG #define DMP(x) cerr << #x << ": " << x << "\n" #else #define DMP(x) ((void)0) #endif const int MOD = 1000000007, INF = 1111111111; using namespace std; typedef long long lint; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, W; cin >> N >> W; struct item { int w, val; }; vector<item> item(N); for (int i = 0; i < N; i++) cin >> item[i].w >> item[i].val; vector<vector<lint>> dp(N + 1, vector<lint>(W + 1)); for (int i = 1; i <= N; i++) { for (int j = 0; j <= W; j++) { if (j - item[i - 1].w >= 0) dp[i][j] = max(dp[i - 1][j - item[i - 1].w] + item[i - 1].val, dp[i][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #ifdef _DEBUG #define DMP(x) cerr << #x << ": " << x << "\n" #else #define DMP(x) ((void)0) #endif const int MOD = 1000000007, INF = 1111111111; using namespace std; typedef long long lint; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, W; cin >> N >> W; struct item { int w, val; }; vector<item> item(N); for (int i = 0; i < N; i++) cin >> item[i].w >> item[i].val; vector<vector<lint>> dp(N + 1, vector<lint>(W + 1)); for (int i = 1; i <= N; i++) { for (int j = 0; j <= W; j++) { if (j - item[i - 1].w >= 0) dp[i][j] = max(dp[i - 1][j - item[i - 1].w] + item[i - 1].val, dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; return 0; }
[ "assignment.change" ]
968,096
968,097
u532573979
cpp
p03163
#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 <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<long double> VD; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VD> VVD; typedef pair<int, int> P; typedef pair<ll, ll> PL; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } int main() { int n, U; cin >> n >> U; vector<int> w(n), v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; vector<vector<int>> dp(n, vector<int>(U + 1)); for (int u = w[0]; u <= U; u++) dp[0][u] = v[0]; for (int i = 1; i < n; i++) { for (int u = 0; u <= U; u++) { if (u >= w[i]) dp[i][u] = max(dp[i - 1][u - w[i]] + v[i], dp[i - 1][u]); else dp[i][u] = dp[i - 1][u]; } } cout << dp[n - 1][U] << endl; 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 <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<long double> VD; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<VD> VVD; typedef pair<int, int> P; typedef pair<ll, ll> PL; template <typename T> void chmin(T &a, T b) { if (a > b) a = b; } template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int in() { int x; scanf("%d", &x); return x; } ll lin() { ll x; scanf("%lld", &x); return x; } int main() { int n, U; cin >> n >> U; vector<ll> w(n), v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; vector<vector<ll>> dp(n, vector<ll>(U + 1)); for (int u = w[0]; u <= U; u++) dp[0][u] = v[0]; for (int i = 1; i < n; i++) { for (int u = 0; u <= U; u++) { if (u >= w[i]) dp[i][u] = max(dp[i - 1][u - w[i]] + v[i], dp[i - 1][u]); else dp[i][u] = dp[i - 1][u]; } } cout << dp[n - 1][U] << endl; return 0; }
[ "call.arguments.change" ]
968,102
968,103
u941028483
cpp
p03163
#include <bits/stdc++.h> #include <cmath> using namespace std; int dp[101][100001]; pair<int, int> c[101]; int main() { int n, W; cin >> n >> W; for (int i = 1; i <= n; i++) { int w, v; cin >> w >> v; c[i].first = w; c[i].second = v; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= W; j++) { if (i == 1) { if (j >= c[i].first) dp[i][j] = c[i].second; } else { if (j < c[i].first) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], c[i].second + dp[i - 1][j - c[i].first]); } } } } cout << dp[n][W]; }
#include <bits/stdc++.h> #include <cmath> using namespace std; long long dp[101][100001]; pair<int, long long> c[101]; int main() { int n, W; cin >> n >> W; for (int i = 1; i <= n; i++) { int w, v; cin >> w >> v; c[i].first = w; c[i].second = v; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= W; j++) { if (i == 1) { if (j >= c[i].first) dp[i][j] = c[i].second; } else { if (j < c[i].first) { dp[i][j] = dp[i - 1][j]; } else { dp[i][j] = max(dp[i - 1][j], c[i].second + dp[i - 1][j - c[i].first]); } } } } cout << dp[n][W]; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,104
968,105
u726841392
cpp
p03163
#include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> #define INF 1000000007 using namespace std; using P = pair<int, int>; using ll = long long; int main() { int n, m; cin >> n >> m; vector<ll> w(n); vector<ll> v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; vector<vector<ll>> dp(n + 1, vector<ll>(m, 0)); for (int i = n - 1; i >= 0; i--) { for (int j = 0; j <= m; j++) { if (w[i] > j) dp[i][j] = dp[i + 1][j]; else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]); } } cout << dp[0][m] << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <fstream> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <stack> #include <string> #include <utility> #include <vector> #define INF 1000000007 using namespace std; using P = pair<int, int>; using ll = long long; int main() { int n, m; cin >> n >> m; vector<ll> w(n); vector<ll> v(n); for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0)); for (int i = n - 1; i >= 0; i--) { for (int j = 0; j <= m; j++) { if (w[i] > j) dp[i][j] = dp[i + 1][j]; else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]); } } cout << dp[0][m] << endl; return 0; }
[ "assignment.change" ]
968,110
968,111
u033620890
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAX = 1e5 + 10; int N, W, A[MAX], B[MAX], C[MAX], dp[105][MAX]; int solve(int idx, int w) { if (idx > N) return 0; if (dp[idx][w] != -1) return dp[idx][w]; int res = 0; if (w + A[idx] <= W) res = max(res, solve(idx + 1, w + A[idx]) + B[idx]); res = max(res, solve(idx + 1, w)); return dp[idx][w] = res; } int main() { memset(dp, -1, sizeof dp); cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> A[i] >> B[i]; } cout << solve(1, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int MAX = 1e5 + 10; ll N, W, A[MAX], B[MAX], C[MAX], dp[105][MAX]; ll solve(int idx, int w) { if (idx > N) return 0; if (dp[idx][w] != -1) return dp[idx][w]; ll res = 0; if (w + A[idx] <= W) res = max(res, solve(idx + 1, w + A[idx]) + B[idx]); res = max(res, solve(idx + 1, w)); return dp[idx][w] = res; } int main() { memset(dp, -1, sizeof dp); cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> A[i] >> B[i]; } cout << solve(1, 0) << endl; return 0; }
[ "variable_declaration.type.change" ]
968,114
968,115
u205197147
cpp
p03163
#include <climits> #include <iostream> #include <vector> using namespace std; int main() { int n, W; cin >> n >> W; vector<int> w(n), v(n); for (int i = 0; i < n; ++i) { cin >> w[i]; cin >> v[i]; } vector<vector<int>> KS(n + 1, vector<int>(W + 1)); for (int i = 0; i <= n; ++i) { KS[i][0] = 0; } for (int j = 0; j <= W; ++j) { KS[0][j] = 0; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= W; ++j) { if (j >= w[i - 1]) KS[i][j] = max(KS[i - 1][j], KS[i - 1][j - w[i - 1]] + v[i - 1]); else KS[i][j] = KS[i - 1][j]; } } printf("%d", KS[n][W]); }
#include <climits> #include <iostream> #include <vector> using namespace std; int main() { long int n, W; cin >> n >> W; vector<int> w(n), v(n); for (int i = 0; i < n; ++i) { cin >> w[i]; cin >> v[i]; } vector<vector<long int>> KS(n + 1, vector<long int>(W + 1)); for (int i = 0; i <= n; ++i) { KS[i][0] = 0; } for (int j = 0; j <= W; ++j) { KS[0][j] = 0; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= W; ++j) { if (j >= w[i - 1]) KS[i][j] = max(KS[i - 1][j], KS[i - 1][j - w[i - 1]] + v[i - 1]); else KS[i][j] = KS[i - 1][j]; } } printf("%li", KS[n][W]); }
[ "variable_declaration.type.widen.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
968,116
968,117
u555640897
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n, w; cin >> n >> w; int a[n][2]; for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; int dp[n + 1][w + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= a[i - 1][0]) dp[i][j] = max(a[i - 1][1] + dp[i - 1][j - a[i - 1][0]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, w; cin >> n >> w; int a[n][2]; for (int i = 0; i < n; i++) cin >> a[i][0] >> a[i][1]; long long dp[n + 1][w + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= w; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= a[i - 1][0]) dp[i][j] = max(a[i - 1][1] + dp[i - 1][j - a[i - 1][0]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,120
968,121
u200439351
cpp
p03163
#include <algorithm> #include <iostream> template <class T> inline void chmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chmin(T &a, T b) { if (a > b) a = b; } const long long INF = 1LL << 60; using namespace std; int dp[110][100100] = {0}; int main() { int N, W; cin >> N >> W; int weight[110], value[100100]; for (int i = 0; i < N; i++) scanf("%d%d", &weight[i], &value[i]); for (int i = 0; i < N; i++) { for (int sum_w = 0; sum_w <= W; sum_w++) { if (sum_w - weight[i] >= 0) { chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]); } chmax(dp[i + 1][sum_w], dp[i][sum_w]); } } cout << dp[N][W] << endl; return 0; }
#include <algorithm> #include <iostream> template <class T> inline void chmax(T &a, T b) { if (a < b) a = b; } template <class T> inline void chmin(T &a, T b) { if (a > b) a = b; } const long long INF = 1LL << 60; using namespace std; long long dp[110][100100] = {0}; int main() { int N, W; cin >> N >> W; long long weight[110], value[100100]; for (int i = 0; i < N; i++) scanf("%lld%lld", &weight[i], &value[i]); for (int i = 0; i < N; i++) { for (int sum_w = 0; sum_w <= W; sum_w++) { if (sum_w - weight[i] >= 0) { chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]); } chmax(dp[i + 1][sum_w], dp[i][sum_w]); } } cout << dp[N][W] << endl; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "literal.string.change", "call.arguments.change" ]
968,122
968,123
u863957421
cpp
p03163
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000000 + 7; template <int Modulo = MOD> struct Mint { Int val; constexpr Mint(Int v = 0) noexcept : val(v % Modulo) { if (val < 0) v += Modulo; } constexpr int getmod() { return Modulo; } constexpr Mint operator-() const noexcept { return val ? Modulo - val : 0; } constexpr Mint operator+(const Mint &r) const noexcept { return Mint(*this) += r; } constexpr Mint operator-(const Mint &r) const noexcept { return Mint(*this) -= r; } constexpr Mint operator*(const Mint &r) const noexcept { return Mint(*this) *= r; } constexpr Mint operator/(const Mint &r) const noexcept { return Mint(*this) /= r; } constexpr Mint &operator+=(const Mint &r) noexcept { val += r.val; if (val >= Modulo) val -= Modulo; return *this; } constexpr Mint &operator-=(const Mint &r) noexcept { val -= r.val; if (val < 0) val += Modulo; return *this; } constexpr Mint &operator*=(const Mint &r) noexcept { val = val * r.val % Modulo; return *this; } constexpr Mint &operator/=(const Mint &r) noexcept { Int a = r.val, b = Modulo, u = 1, v = 0; while (b) { Int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % Modulo; if (val < 0) val += Modulo; return *this; } constexpr bool operator==(const Mint &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Mint &r) const noexcept { return this->val != r.val; } friend ostream &operator<<(ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; } friend istream &operator>>(istream &is, Mint<Modulo> &x) noexcept { Int tmp; is >> tmp; x = Mint<Modulo>(tmp); return is; } friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, Int n) noexcept { Mint res(1), tmp = a; while (n > 0) { if (n & 1) res *= tmp; tmp *= tmp; n >>= 1; } return res; } }; using mint = Mint<>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Int N, W; cin >> N >> W; vector<Int> w(N); vector<Int> v(N); for (Int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } vector<vector<Int>> dp(N + 10, vector<Int>(W + 10)); for (Int i = 1; i < W + 10; i++) { dp[0][i] = -INF; } for (Int i = 0; i < N; i++) { for (Int j = 0; j <= W; j++) { if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i + 1][j]); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } Int ans = 0; for (Int i = 0; i < N; i++) { ans = max(ans, dp[N][i]); } cout << ans << "\n"; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000000 + 7; template <int Modulo = MOD> struct Mint { Int val; constexpr Mint(Int v = 0) noexcept : val(v % Modulo) { if (val < 0) v += Modulo; } constexpr int getmod() { return Modulo; } constexpr Mint operator-() const noexcept { return val ? Modulo - val : 0; } constexpr Mint operator+(const Mint &r) const noexcept { return Mint(*this) += r; } constexpr Mint operator-(const Mint &r) const noexcept { return Mint(*this) -= r; } constexpr Mint operator*(const Mint &r) const noexcept { return Mint(*this) *= r; } constexpr Mint operator/(const Mint &r) const noexcept { return Mint(*this) /= r; } constexpr Mint &operator+=(const Mint &r) noexcept { val += r.val; if (val >= Modulo) val -= Modulo; return *this; } constexpr Mint &operator-=(const Mint &r) noexcept { val -= r.val; if (val < 0) val += Modulo; return *this; } constexpr Mint &operator*=(const Mint &r) noexcept { val = val * r.val % Modulo; return *this; } constexpr Mint &operator/=(const Mint &r) noexcept { Int a = r.val, b = Modulo, u = 1, v = 0; while (b) { Int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % Modulo; if (val < 0) val += Modulo; return *this; } constexpr bool operator==(const Mint &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Mint &r) const noexcept { return this->val != r.val; } friend ostream &operator<<(ostream &os, const Mint<Modulo> &x) noexcept { return os << x.val; } friend istream &operator>>(istream &is, Mint<Modulo> &x) noexcept { Int tmp; is >> tmp; x = Mint<Modulo>(tmp); return is; } friend constexpr Mint<Modulo> modpow(const Mint<Modulo> &a, Int n) noexcept { Mint res(1), tmp = a; while (n > 0) { if (n & 1) res *= tmp; tmp *= tmp; n >>= 1; } return res; } }; using mint = Mint<>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Int N, W; cin >> N >> W; vector<Int> w(N); vector<Int> v(N); for (Int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } vector<vector<Int>> dp(N + 10, vector<Int>(W + 10)); for (Int i = 1; i < W + 10; i++) { dp[0][i] = -INF; } for (Int i = 0; i < N; i++) { for (Int j = 0; j <= W; j++) { if (j - w[i] >= 0) { dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i + 1][j]); } dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]); } } Int ans = 0; for (Int i = 0; i <= W; i++) { ans = max(ans, dp[N][i]); } cout << ans << "\n"; }
[ "control_flow.loop.for.condition.change" ]
968,131
968,132
u612271542
cpp
p03163
#include <algorithm> #include <climits> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_set> #include <vector> #define m7 1000000007 #define m9 1000000009 #define ll long long #define pii pair<int, int> #define F first #define S second using namespace std; int main() { int n, w; cin >> n >> w; map<int, ll> M; vector<int> wt(n + 1), vl(n + 1); M[0] = 0; for (int i = 1; i <= n; i++) { cin >> wt[i] >> vl[i]; } for (int i = 1; i <= n; i++) { map<int, ll> T = M; for (auto it : M) { if (it.first + wt[i] > w) continue; if (T.find(it.first + wt[i]) == T.end()) { T[M[it.first] + wt[i]] = it.second + vl[i]; } else { int y = M[it.first + wt[i]]; T[y] = max(T[y], it.second + vl[i]); } } M = T; } ll maxi = 0; for (auto it : M) { if (it.second > maxi) maxi = it.second; } cout << maxi; return 0; }
#include <algorithm> #include <climits> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_set> #include <vector> #define m7 1000000007 #define m9 1000000009 #define ll long long #define pii pair<int, int> #define F first #define S second using namespace std; int main() { int n, w; cin >> n >> w; map<int, ll> M; vector<int> wt(n + 1), vl(n + 1); M[0] = 0; for (int i = 1; i <= n; i++) { cin >> wt[i] >> vl[i]; } for (int i = 1; i <= n; i++) { map<int, ll> T = M; for (auto it : M) { if (it.first + wt[i] > w) continue; if (T.find(it.first + wt[i]) == T.end()) { T[it.first + wt[i]] = it.second + vl[i]; } else { int y = it.first + wt[i]; T[y] = max(T[y], it.second + vl[i]); } } M = T; } ll maxi = 0; for (auto it : M) { if (it.second > maxi) maxi = it.second; } cout << maxi; return 0; }
[]
968,133
968,134
u096424346
cpp
p03163
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <vector> using namespace std; int dp[100][100000]; long long solve(vector<int> &w, vector<int> &p, int i, int j) { if (i == w.size()) return 0; if (dp[i][j] != -1) return dp[i][j]; if (j - w[i] >= 0) dp[i][j] = max(solve(w, p, i + 1, j), p[i] + solve(w, p, i + 1, j - w[i])); else dp[i][j] = solve(w, p, i + 1, j); return dp[i][j]; } int main() { int n, t; cin >> n >> t; memset(dp, -1, sizeof(dp)); vector<int> w(n), p(n); for (int i = 0; i < n; i++) { cin >> w[i] >> p[i]; } cout << solve(w, p, 0, t); return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iostream> #include <vector> using namespace std; long long dp[100][100000]; long long solve(vector<int> &w, vector<int> &p, int i, int j) { if (i == w.size()) return 0; if (dp[i][j] != -1) return dp[i][j]; if (j - w[i] >= 0) dp[i][j] = max(solve(w, p, i + 1, j), p[i] + solve(w, p, i + 1, j - w[i])); else dp[i][j] = solve(w, p, i + 1, j); return dp[i][j]; } int main() { int n, t; cin >> n >> t; memset(dp, -1, sizeof(dp)); vector<int> w(n), p(n); for (int i = 0; i < n; i++) { cin >> w[i] >> p[i]; } cout << solve(w, p, 0, t); return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,135
968,136
u490032848
cpp
p03163
#include <algorithm> #include <cctype> #include <climits> #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; int main() { int N, W; cin >> N; cin >> W; int weight[N + 1]; int value[N + 1]; weight[0] = 0; value[0] = 0; for (int i = 1; i <= N; ++i) { cin >> weight[i]; cin >> value[i]; } int dp[N + 1][W + 1]; for (int i = 0; i <= N; ++i) { for (int j = 0; j <= W; ++j) { dp[i][j] = 0; } } for (int i = 1; i <= N; ++i) { for (int j = 1; j <= W; ++j) { if (j == weight[i]) { dp[i][j] = max(dp[i][j], value[i]); dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1])); } else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); if (j - weight[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]); } } } cout << dp[N][W]; return 0; }
#include <algorithm> #include <cctype> #include <climits> #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; int main() { int N, W; cin >> N; cin >> W; long long weight[N + 1]; long long value[N + 1]; weight[0] = 0; value[0] = 0; for (int i = 1; i <= N; ++i) { cin >> weight[i]; cin >> value[i]; } long long dp[N + 1][W + 1]; for (int i = 0; i <= N; ++i) { for (int j = 0; j <= W; ++j) { dp[i][j] = 0; } } for (int i = 1; i <= N; ++i) { for (int j = 1; j <= W; ++j) { if (j == weight[i]) { dp[i][j] = max(dp[i][j], value[i]); dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1])); } else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); if (j - weight[i] >= 0) dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]); } } } cout << dp[N][W]; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,137
968,138
u554989002
cpp
p03163
#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; int dp[maxw]; int n, lim; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> lim; for (int w, v, i = 0; i < n; ++i) { cin >> w >> v; for (int j = lim; j >= w; --j) dp[j] = max(dp[j], dp[j - w] + v); } cout << *max_element(dp, dp + lim + 1) << '\n'; }
#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; ll dp[maxw]; int n, lim; int main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> lim; for (int w, v, i = 0; i < n; ++i) { cin >> w >> v; for (int j = lim; j >= w; --j) dp[j] = max(dp[j], dp[j - w] + v); } cout << *max_element(dp, dp + lim + 1) << '\n'; }
[ "variable_declaration.type.change" ]
968,139
968,140
u233690053
cpp
p03163
#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 using P = pair<ll, ll>; using vl = vector<ll>; using vb = vector<bool>; using vs = vector<string>; using vd = vector<double>; using vc = vector<char>; using vp = vector<P>; #define V vector #define o_vvt(o1, o2, o3, o4, name, ...) name #define vvt0(t) V<V<t>> #define vvt1(t, a) V<V<t>> a #define vvt2(t, a, b) V<V<t>> a(b) #define vvt3(t, a, b, c) V<V<t>> a(b, V<t>(c)) #define vvt4(t, a, b, c, d) V<V<t>> a(b, V<t>(c, d)) #define vvl(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(ll, __VA_ARGS__) #define vvb(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(bool, __VA_ARGS__) #define vvs(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(string, __VA_ARGS__) #define vvd(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(double, __VA_ARGS__) #define vvc(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(char, __VA_ARGS__) #define vvp(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(P, __VA_ARGS__) template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } #define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__) #define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__) #define vns(name, ...) auto name = make_v<string>(__VA_ARGS__) #define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__) #define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__) #define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__) 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; } 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}; 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); vvl(dp, N + 1, W + 1); rep(i, N) cin >> w[i] >> v[i]; rep(i, N) { rep(j, W + 1) { if (j < w[i]) continue; chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << 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 using P = pair<ll, ll>; using vl = vector<ll>; using vb = vector<bool>; using vs = vector<string>; using vd = vector<double>; using vc = vector<char>; using vp = vector<P>; #define V vector #define o_vvt(o1, o2, o3, o4, name, ...) name #define vvt0(t) V<V<t>> #define vvt1(t, a) V<V<t>> a #define vvt2(t, a, b) V<V<t>> a(b) #define vvt3(t, a, b, c) V<V<t>> a(b, V<t>(c)) #define vvt4(t, a, b, c, d) V<V<t>> a(b, V<t>(c, d)) #define vvl(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(ll, __VA_ARGS__) #define vvb(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(bool, __VA_ARGS__) #define vvs(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(string, __VA_ARGS__) #define vvd(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(double, __VA_ARGS__) #define vvc(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(char, __VA_ARGS__) #define vvp(...) \ o_vvt(__VA_ARGS__, vvt4, vvt3, vvt2, vvt1, vvt0)(P, __VA_ARGS__) template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } #define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__) #define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__) #define vns(name, ...) auto name = make_v<string>(__VA_ARGS__) #define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__) #define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__) #define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__) 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; } 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}; 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); vvl(dp, N + 1, W + 1); rep(i, N) cin >> w[i] >> v[i]; rep(i, N) { rep(j, W + 1) { if (j >= w[i]) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
968,145
968,146
u135572611
cpp
p03163
#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]; } ll ans = 0; rep(i, N) { rep(j, W + 1) { if (j >= w[i]) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); else chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << 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]; } ll ans = 0; rep(i, N) { rep(j, W + 1) { if (j >= w[i]) chmax(dp[i + 1][j], dp[i][j - w[i]] + v[i]); chmax(dp[i + 1][j], dp[i][j]); } } cout << dp[N][W] << endl; }
[ "control_flow.branch.else.remove" ]
968,156
968,157
u135572611
cpp
p03163
#include <bits/stdc++.h> 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; } using namespace std; #define min_3(a, b, c) min(a, min(b, c)) #define max_3(a, b, c) max(a, max(b, c)) typedef long long ll; const long long INF = 1e9; int main() { int N, W; cin >> N >> W; vector<int> w(N), v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; // dp[i][w]i-1番目までの品物から重さがwを超えないように選んだ時の最大値 vector<vector<ll>> dp(N + 1, vector<ll>(100000, 0)); for (int i = 0; i < N; i++) { for (int sum_w = 0; sum_w < W; sum_w++) { if (sum_w - w[i] >= 0) { //選ぶとき chmax(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]); } //選ばなかったとき chmax(dp[i + 1][sum_w], dp[i][sum_w]); } } cout << dp[N][W] << endl; }
#include <bits/stdc++.h> 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; } using namespace std; #define min_3(a, b, c) min(a, min(b, c)) #define max_3(a, b, c) max(a, max(b, c)) typedef long long ll; const long long INF = 1e9; int main() { int N, W; cin >> N >> W; vector<int> w(N), v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; // dp[i][w]i-1番目までの品物から重さがwを超えないように選んだ時の最大値 vector<vector<ll>> dp(N + 1, vector<ll>(100000, 0)); for (int i = 0; i < N; i++) { for (int sum_w = 0; sum_w <= W; sum_w++) { if (sum_w - w[i] >= 0) { //選ぶとき chmax(dp[i + 1][sum_w], dp[i][sum_w - w[i]] + v[i]); } //選ばなかったとき chmax(dp[i + 1][sum_w], dp[i][sum_w]); } } cout << dp[N][W] << endl; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
968,160
968,161
u170650966
cpp
p03163
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define pb push_back #define mp make_pair #define ll long long int #define vi vector<int> #define vl vector<ll> #define v2i vector<vector<int>> #define v2l vector<vector<ll>> #define ppi pair<int, int> #define vpi vector<ppi> #define ppl pair<ll, ll> #define all(x) x.begin(), x.end() #define ii int, int #define ff first #define ss second #define forn(i, a, b) for (int i = a; i < b; i++) #define forr(i, a, b) for (int i = a; i >= b; i--) #define forv(i, m) for (auto i : m) #define imx INT_MAX #define imn INT_MIN #define inf LONG_MAX #define minf LONG_MIN #define endl "\n" #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define sze size() #define rvs reverse #define itr iterator #define pre cout << fixed << setprecision(10); #define umap unordered_map #define uset unordered_set /* #define MODM(a,b,md) ((a%md)*(b%md))%md #define MODA(a,b,md) ((a%md)+(b%md))%md #define ull unsigned long long int #define si short int */ /* bool compare(int a,int b) {return a > b;} bool compare1(ppi a,ppi b) {return a.ff > b.ff;} bool compare2(ppi a,ppi b) {return a.ss < b.ss;} ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;} ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;} ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);} ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; } */ int main() { fast int n, we; cin >> n >> we; vi v(n), w(n); forn(i, 0, n) { cin >> w[i] >> v[i]; } // v2l dp(n+1,vl(we+1,0)); vl dp(we + 1, 0); forn(i, 1, n + 1) { forr(j, we, w[i]) { dp[j] = max(dp[j], v[i] + dp[j - w[i]]); } } cout << dp[we]; return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define pb push_back #define mp make_pair #define ll long long int #define vi vector<int> #define vl vector<ll> #define v2i vector<vector<int>> #define v2l vector<vector<ll>> #define ppi pair<int, int> #define vpi vector<ppi> #define ppl pair<ll, ll> #define all(x) x.begin(), x.end() #define ii int, int #define ff first #define ss second #define forn(i, a, b) for (int i = a; i < b; i++) #define forr(i, a, b) for (int i = a; i >= b; i--) #define forv(i, m) for (auto i : m) #define imx INT_MAX #define imn INT_MIN #define inf LONG_MAX #define minf LONG_MIN #define endl "\n" #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define sze size() #define rvs reverse #define itr iterator #define pre cout << fixed << setprecision(10); #define umap unordered_map #define uset unordered_set /* #define MODM(a,b,md) ((a%md)*(b%md))%md #define MODA(a,b,md) ((a%md)+(b%md))%md #define ull unsigned long long int #define si short int */ /* bool compare(int a,int b) {return a > b;} bool compare1(ppi a,ppi b) {return a.ff > b.ff;} bool compare2(ppi a,ppi b) {return a.ss < b.ss;} ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;} ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;} ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);} ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; } */ int main() { fast int n, we; cin >> n >> we; vi v(n), w(n); forn(i, 0, n) { cin >> w[i] >> v[i]; } // v2l dp(n+1,vl(we+1,0)); vl dp(we + 1, 0); forn(i, 0, n) { forr(j, we, w[i]) { dp[j] = max(dp[j], v[i] + dp[j - w[i]]); } } cout << dp[we]; return 0; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.remove" ]
968,176
968,177
u460819600
cpp
p03163
#include <bits/stdc++.h> using namespace std; int dp[101][100005]; int main() { int n, w; cin >> n >> w; int weight[n], value[n]; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (int i = 0; i < n; i++) for (int j = 0; j <= w; j++) { if (i == 0) { if (weight[i] <= j) dp[i][j] = value[i]; continue; } if (j == 0) { dp[i][j] = 0; continue; } if (j - weight[i] >= 0) dp[i][j] = max(dp[i - 1][j - weight[i]] + value[i], max(dp[i - 1][j], dp[i][j - 1])); else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } cout << dp[n - 1][w] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long int dp[101][100005]; int main() { int n, w; cin >> n >> w; int weight[n], value[n]; for (int i = 0; i < n; i++) { cin >> weight[i] >> value[i]; } for (int i = 0; i < n; i++) for (int j = 0; j <= w; j++) { if (i == 0) { if (weight[i] <= j) dp[i][j] = value[i]; continue; } if (j == 0) { dp[i][j] = 0; continue; } if (j - weight[i] >= 0) dp[i][j] = max(dp[i - 1][j - weight[i]] + value[i], max(dp[i - 1][j], dp[i][j - 1])); else { dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]); } } cout << dp[n - 1][w] << endl; return 0; }
[ "variable_declaration.type.widen.change" ]
968,180
968,181
u316078299
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vec; #define vecc vector<vector<ll>> #define LM LLONG_MAX #define int long long int #define P pair<ll, ll> #define ff first #define ss second #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define N 200005 #define MOD (ll)1000000007 ll dp[105][N], a[105][3]; ll solve(ll n, ll w) { if (n < 1 && w < 1) return 0; ll &ans = dp[n][w]; if (ans != 0) return ans; ans = solve(n - 1, w); if (w >= a[n][1]) ans = max(ans, a[n][2] + solve(n - 1, w - a[n][1])); return ans; } signed main() { FAST; ll n, w; cin >> n >> w; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2]; cout << solve(n, w) << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vec; #define vecc vector<vector<ll>> #define LM LLONG_MAX #define int long long int #define P pair<ll, ll> #define ff first #define ss second #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define N 200005 #define MOD (ll)1000000007 ll dp[105][N], a[105][3]; ll solve(ll n, ll w) { if (n < 1 || w < 1) return 0; ll &ans = dp[n][w]; if (ans != 0) return ans; ans = solve(n - 1, w); if (w >= a[n][1]) ans = max(ans, a[n][2] + solve(n - 1, w - a[n][1])); return ans; } signed main() { FAST; ll n, w; cin >> n >> w; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2]; cout << solve(n, w) << "\n"; }
[ "misc.opposites", "control_flow.branch.if.condition.change" ]
968,188
968,189
u439272053
cpp
p03163
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vec; #define vecc vector<vector<ll>> #define LM LLONG_MAX #define int long long int #define P pair<ll, ll> #define ff first #define ss second #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define N 100005 #define MOD (ll)1000000007 ll dp[105][N], a[N][3]; ll solve(ll n, ll w) { if (n < 1 && w < 0) return 0; ll &ans = dp[n][w]; if (ans != 0) return ans; ans = solve(n - 1, w); if (w >= a[n][1]) ans = max(ans, a[n][2] + solve(n - 1, w - a[n][1])); return ans; } signed main() { FAST; ll n, w; cin >> n >> w; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2]; cout << solve(n, w) << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vec; #define vecc vector<vector<ll>> #define LM LLONG_MAX #define int long long int #define P pair<ll, ll> #define ff first #define ss second #define FAST \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define N 200005 #define MOD (ll)1000000007 ll dp[105][N], a[105][3]; ll solve(ll n, ll w) { if (n < 1 || w < 1) return 0; ll &ans = dp[n][w]; if (ans != 0) return ans; ans = solve(n - 1, w); if (w >= a[n][1]) ans = max(ans, a[n][2] + solve(n - 1, w - a[n][1])); return ans; } signed main() { FAST; ll n, w; cin >> n >> w; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) cin >> a[i][1] >> a[i][2]; cout << solve(n, w) << "\n"; }
[ "preprocessor.define.value.change", "literal.integer.change", "identifier.replace.remove", "literal.replace.add", "variable_declaration.array_dimensions.change", "misc.opposites", "control_flow.branch.if.condition.change", "literal.number.change" ]
968,190
968,189
u439272053
cpp
p03163
#include <algorithm> #include <cstdio> #include <vector> typedef long long int ll; struct state { ll aw; ll av; state(ll aw = 0, ll av = 0) : aw(aw), av(av) {} }; struct item { int w; int v; double d; item(int w, int v) : w(w), v(v), d((double)v / w) {} }; int n, w; ll lower; std::vector<item> is; std::vector<state> dp[2]; void add(const std::vector<state> &s, const item &k, std::vector<state> &u, ll uw) { auto i = s.cbegin(); auto j = s.cbegin(); while (i != s.cend() && j != s.cend()) { if (i->aw > uw) { i = s.cend(); break; } ll jav = j->av + k.v; ll jaw = j->aw + k.w; if (jaw > uw) { j = s.cend(); break; } if (i->aw <= jaw && i->av >= jav) { ++j; } else if (i->aw >= jaw && i->av <= jav) { ++i; } else if (i->aw < jaw) { u.push_back(*i++); } else { u.emplace_back(state(jaw, jav)); ++j; } } while (i != s.cend()) { if (i->aw > uw) return; u.push_back(*i++); } while (j != s.cend()) { ll jav = j->av + k.v; ll jaw = j->aw + k.w; if (jaw > uw) return; u.emplace_back(state(jaw, jav)); ++j; } } void remove(const std::vector<state> &s, const item &k, std::vector<state> &u, ll uw) { auto i = s.cbegin(); auto j = s.cbegin(); while (i != s.cend() && j != s.cend()) { if (i->aw > uw) { i = s.cend(); break; } ll jav = j->av - k.v; ll jaw = j->aw - k.w; if (jaw > uw) { j = s.cend(); break; } if (i->aw <= jaw && i->av >= jav) { ++j; } else if (i->aw >= jaw && i->av <= jav) { ++i; } else if (i->aw < jaw) { u.push_back(*i++); } else { u.emplace_back(state(jaw, jav)); ++j; } } while (i != s.cend()) { if (i->aw > uw) return; u.push_back(*i++); } while (j != s.cend()) { ll jav = j->av - k.v; ll jaw = j->aw - k.w; if (jaw > uw) return; u.emplace_back(state(jaw, jav)); ++j; } } ll upper; inline void shrink(const std::vector<state> &s, double d0, double d1, std::vector<state> &u) { for (auto x : s) { ll t = (x.aw > w) ? x.av - (x.aw - w) * d0 : x.av + (w - x.aw) * d1; if (t >= lower) u.push_back(x); if (t > upper) upper = t; } } int main() { scanf("%d%d", &n, &w); is.reserve(200); dp[0].reserve(300); dp[1].reserve(300); is.emplace_back(item(1, 0)); for (int i = 0; i < n; i++) { int ww, vv; scanf("%d%d", &vv, &ww); if (ww <= w) is.emplace_back(item(ww, vv)); } n = is.size() - 1; std::sort(is.begin() + 1, is.end(), [](const item &x, const item &y) { return x.d > y.d; }); is.emplace_back(item(1, 0)); ll aw = 0; ll av = 0; int ii; for (ii = 1; ii <= n; ii++) { const item &x = is[ii]; if (aw + x.w > w) break; aw += x.w; av += x.v; } dp[0].emplace_back(state(aw, av)); lower = av; ll sumw = w + aw; for (int i = ii - 1, j = ii; i > 0 || j <= n;) { if (i > 0) { sumw -= is[i].w; remove(dp[0], is[i], dp[1], sumw); dp[0].resize(0); lower = (std::upper_bound(dp[1].cbegin(), dp[1].cend(), w, [](int w, const state &x) { return x.aw > w; }) - 1) ->av; shrink(dp[1], is[i - 1].d, is[j].d, dp[0]); dp[1].resize(0); --i; } if (j <= n) { add(dp[0], is[j], dp[1], sumw); dp[0].resize(0); lower = (std::upper_bound(dp[1].cbegin(), dp[1].cend(), w, [](int w, const state &x) { return x.aw > w; }) - 1) ->av; shrink(dp[1], is[i].d, is[j + 1].d, dp[0]); dp[1].resize(0); ++j; } if (lower == upper) break; } lower = (std::upper_bound(dp[0].cbegin(), dp[0].cend(), w, [](int w, const state &x) { return x.aw > w; }) - 1) ->av; printf("%lld\n", lower); return 0; }
#include <algorithm> #include <cstdio> #include <vector> typedef long long int ll; struct state { ll aw; ll av; state(ll aw = 0, ll av = 0) : aw(aw), av(av) {} }; struct item { int w; int v; double d; item(int w, int v) : w(w), v(v), d((double)v / w) {} }; int n, w; ll lower; std::vector<item> is; std::vector<state> dp[2]; void add(const std::vector<state> &s, const item &k, std::vector<state> &u, ll uw) { auto i = s.cbegin(); auto j = s.cbegin(); while (i != s.cend() && j != s.cend()) { if (i->aw > uw) { i = s.cend(); break; } ll jav = j->av + k.v; ll jaw = j->aw + k.w; if (jaw > uw) { j = s.cend(); break; } if (i->aw <= jaw && i->av >= jav) { ++j; } else if (i->aw >= jaw && i->av <= jav) { ++i; } else if (i->aw < jaw) { u.push_back(*i++); } else { u.emplace_back(state(jaw, jav)); ++j; } } while (i != s.cend()) { if (i->aw > uw) return; u.push_back(*i++); } while (j != s.cend()) { ll jav = j->av + k.v; ll jaw = j->aw + k.w; if (jaw > uw) return; u.emplace_back(state(jaw, jav)); ++j; } } void remove(const std::vector<state> &s, const item &k, std::vector<state> &u, ll uw) { auto i = s.cbegin(); auto j = s.cbegin(); while (i != s.cend() && j != s.cend()) { if (i->aw > uw) { i = s.cend(); break; } ll jav = j->av - k.v; ll jaw = j->aw - k.w; if (jaw > uw) { j = s.cend(); break; } if (i->aw <= jaw && i->av >= jav) { ++j; } else if (i->aw >= jaw && i->av <= jav) { ++i; } else if (i->aw < jaw) { u.push_back(*i++); } else { u.emplace_back(state(jaw, jav)); ++j; } } while (i != s.cend()) { if (i->aw > uw) return; u.push_back(*i++); } while (j != s.cend()) { ll jav = j->av - k.v; ll jaw = j->aw - k.w; if (jaw > uw) return; u.emplace_back(state(jaw, jav)); ++j; } } ll upper; inline void shrink(const std::vector<state> &s, double d0, double d1, std::vector<state> &u) { for (auto x : s) { ll t = (x.aw > w) ? x.av - (x.aw - w) * d0 : x.av + (w - x.aw) * d1; if (t >= lower) u.push_back(x); if (t > upper) upper = t; } } int main() { scanf("%d%d", &n, &w); is.reserve(200); dp[0].reserve(300); dp[1].reserve(300); is.emplace_back(item(1, 0)); for (int i = 0; i < n; i++) { int ww, vv; scanf("%d%d", &ww, &vv); if (ww <= w) is.emplace_back(item(ww, vv)); } n = is.size() - 1; std::sort(is.begin() + 1, is.end(), [](const item &x, const item &y) { return x.d > y.d; }); is.emplace_back(item(1, 0)); ll aw = 0; ll av = 0; int ii; for (ii = 1; ii <= n; ii++) { const item &x = is[ii]; if (aw + x.w > w) break; aw += x.w; av += x.v; } dp[0].emplace_back(state(aw, av)); lower = av; ll sumw = w + aw; for (int i = ii - 1, j = ii; i > 0 || j <= n;) { if (i > 0) { sumw -= is[i].w; remove(dp[0], is[i], dp[1], sumw); dp[0].resize(0); lower = (std::upper_bound(dp[1].cbegin(), dp[1].cend(), w, [](int w, const state &x) { return x.aw > w; }) - 1) ->av; shrink(dp[1], is[i - 1].d, is[j].d, dp[0]); dp[1].resize(0); --i; } if (j <= n) { add(dp[0], is[j], dp[1], sumw); dp[0].resize(0); lower = (std::upper_bound(dp[1].cbegin(), dp[1].cend(), w, [](int w, const state &x) { return x.aw > w; }) - 1) ->av; shrink(dp[1], is[i].d, is[j + 1].d, dp[0]); dp[1].resize(0); ++j; } if (lower == upper) break; } lower = (std::upper_bound(dp[0].cbegin(), dp[0].cend(), w, [](int w, const state &x) { return x.aw > w; }) - 1) ->av; printf("%lld\n", lower); return 0; }
[ "identifier.change", "call.arguments.change" ]
968,191
968,192
u858107870
cpp
p03163
// https://atcoder.jp/contests/dp/tasks/dp_e #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <tuple> #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 FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() // int gcd(long a, long b) { return b ? gcd(b, a % b) : a; } // int lcm(long a, long b) { return a * b / gcd(a, b); } // dp[i] : 重さi以下の価値を最大化する int dp[100001]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, w, i1, i2; cin >> n >> w; REP(i, n) { cin >> i1 >> i2; for (ll k = w; k >= i1; k--) { dp[k] = max(dp[k], dp[k - i1] + i2); } } cout << dp[w] << endl; return 0; }
// https://atcoder.jp/contests/dp/tasks/dp_e #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <tuple> #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 FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() // int gcd(long a, long b) { return b ? gcd(b, a % b) : a; } // int lcm(long a, long b) { return a * b / gcd(a, b); } // dp[i] : 重さi以下の価値を最大化する ll dp[100001]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, w, i1, i2; cin >> n >> w; REP(i, n) { cin >> i1 >> i2; for (ll k = w; k >= i1; k--) { dp[k] = max(dp[k], dp[k - i1] + i2); } } cout << dp[w] << endl; return 0; }
[ "variable_declaration.type.change" ]
968,193
968,194
u858107870
cpp
p03163
#include <iostream> using namespace std; int N, W; long long int w[100001], v[100001]; long long int dp[10001][10001]; int main() { cin >> N >> W; long long int ans; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; for (int i = 0; i <= N; i++) dp[i][0] = 0; for (int j = 0; j <= W; j++) dp[0][j] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j - w[i] < 0) dp[i + 1][j] = dp[i][j]; else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); } } for (int j = 0; j <= W; j++) { if (j == 0) ans = dp[N][j]; if (dp[N][j] > ans) ans = dp[N][j]; } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int N, W; long long int w[100001], v[100001]; long long int dp[101][100001]; int main() { cin >> N >> W; long long int ans; for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; for (int i = 0; i <= N; i++) dp[i][0] = 0; for (int j = 0; j <= W; j++) dp[0][j] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= W; j++) { if (j - w[i] < 0) dp[i + 1][j] = dp[i][j]; else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]); } } for (int j = 0; j <= W; j++) { if (j == 0) ans = dp[N][j]; if (dp[N][j] > ans) ans = dp[N][j]; } cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.array_dimensions.change" ]
968,200
968,201
u570124150
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; int weight[N]; int value[N]; for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } int dp[N + 1][W + 1]; for (int i = 0; i <= N; i++) { for (int j = 0; j <= W; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= weight[i - 1]) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; }
#include <bits/stdc++.h> using namespace std; int main() { int N, W; cin >> N >> W; long long weight[N]; long long value[N]; for (int i = 0; i < N; i++) { cin >> weight[i] >> value[i]; } long long dp[N + 1][W + 1]; for (int i = 0; i <= N; i++) { for (int j = 0; j <= W; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= weight[i - 1]) { dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + value[i - 1]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[N][W]; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,202
968,203
u991501953
cpp
p03163
#include <bits/stdc++.h> using namespace std; // typedef long long ll; long long n, w, a[105], b[105], d[105][100005]; int main(void) { cin >> n >> w; for (int i = 1; i < n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j >= a[i]) d[i][j] = max(d[i - 1][j - a[i]] + b[i], d[i - 1][j]); else d[i][j] = d[i - 1][j]; } } cout << d[n][w] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; // typedef long long ll; long long n, w, a[105], b[105], d[105][100005]; int main(void) { cin >> n >> w; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j >= a[i]) d[i][j] = max(d[i - 1][j - a[i]] + b[i], d[i - 1][j]); else d[i][j] = d[i - 1][j]; } } cout << d[n][w] << '\n'; return 0; }
[ "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change" ]
968,204
968,205
u540547607
cpp
p03163
#include <bits/stdc++.h> using namespace std; // typedef long long ll; long long n, w, a[105], v[105], d[105][100005]; int main(void) { cin >> n >> w; for (int i = 1; i < n; i++) cin >> a[i] >> v[i]; for (int i = 1; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j >= a[i]) d[i][j] = max(d[i - 1][j - a[i]] + v[i], d[i - 1][j]); else d[i][j] = d[i - 1][j]; } } cout << d[n][w] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; // typedef long long ll; long long n, w, a[105], b[105], d[105][100005]; int main(void) { cin >> n >> w; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) { for (int j = 0; j <= w; j++) { if (j >= a[i]) d[i][j] = max(d[i - 1][j - a[i]] + b[i], d[i - 1][j]); else d[i][j] = d[i - 1][j]; } } cout << d[n][w] << '\n'; return 0; }
[ "identifier.change", "variable_declaration.array_dimensions.change", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.off_by_one", "expression.operation.binary.change", "assignment.value.change", "call.arguments.change" ]
968,206
968,205
u540547607
cpp
p03163
#include <bits/stdc++.h> using namespace std; int n, m, a[102], b[102], d[102][100005]; int main(void) { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++) if (j >= a[i]) d[i][j] = max(d[i - 1][j], d[i - 1][j - a[i]] + b[i]); else d[i][j] = d[i - 1][j]; cout << d[n][m] << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m, a[102], b[102], d[102][100005]; int main(void) { cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) for (int j = 0; j <= m; j++) if (j >= a[i]) d[i][j] = max(d[i - 1][j], d[i - 1][j - a[i]] + b[i]); else d[i][j] = d[i - 1][j]; cout << d[n][m] << '\n'; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
968,207
968,208
u540547607
cpp
p03163
#include <bits/stdc++.h> using namespace std; int dp[100005]; int main() { int v, c, n, i, maxim = 0, w; cin >> n >> w; for (int t = 1; t <= n; t++) { cin >> c >> v; for (i = w; i >= c; i--) { dp[i] = max(dp[i], dp[i - c] + v); maxim = max(maxim, dp[i]); } } cout << maxim; return 0; }
#include <bits/stdc++.h> using namespace std; long long dp[100005]; int main() { long long v, c, n, i, maxim = 0, w; cin >> n >> w; for (long long t = 1; t <= n; t++) { cin >> c >> v; for (i = w; i >= c; i--) { dp[i] = max(dp[i], dp[i - c] + v); maxim = max(maxim, dp[i]); } } cout << maxim; return 0; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change", "control_flow.loop.for.initializer.change" ]
968,209
968,210
u966446815
cpp
p03163
#include <iostream> using namespace std; int main() { int n, W; cin >> n >> W; int v[n], w[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; int dp[n + 1][W + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= W; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= w[i - 1]) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][W]; return 0; }
#include <iostream> using namespace std; int main() { int n, W; cin >> n >> W; long v[n], w[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; long dp[n + 1][W + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= W; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (j >= w[i - 1]) dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i - 1]] + v[i - 1]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][W]; return 0; }
[ "variable_declaration.type.primitive.change" ]
968,211
968,212
u474674098
cpp
p03163
#include <iostream> #include <vector> using namespace std; signed main() { int n, w; cin >> n >> w; vector<int> x(n, 0), v(n, 0); for (int i = 1; i <= n; i++) cin >> x[i] >> v[i]; vector<vector<long long>> f(n + 1, vector<long long>(w * 2 + 5, 0)); for (int i = 1; i <= n; i++) { for (int j = 0; j < x[i]; j++) f[i][j] = f[i - 1][j]; for (int j = x[i]; j <= w; j++) { f[i][j] = max(f[i - 1][j], f[i - 1][j - x[i]] + v[i]); } } cout << f[n][w]; return 0; }
#include <iostream> #include <vector> using namespace std; signed main() { int n, w; cin >> n >> w; vector<int> x(n + 1, 0), v(n + 1, 0); for (int i = 1; i <= n; i++) cin >> x[i] >> v[i]; vector<vector<long long>> f(n + 1, vector<long long>(w * 2 + 5, 0)); for (int i = 1; i <= n; i++) { for (int j = 0; j < x[i]; j++) f[i][j] = f[i - 1][j]; for (int j = x[i]; j <= w; j++) { f[i][j] = max(f[i - 1][j], f[i - 1][j - x[i]] + v[i]); } } cout << f[n][w]; return 0; }
[ "assignment.change" ]
968,213
968,214
u803450165
cpp
p03163
#include <bits/stdc++.h> using namespace std; using ll = int64_t; main() { ll n, w; cin >> n >> w; vector<ll> weight(n), value(n); for (ll i = 0; i < n; ++i) cin >> weight[i] >> value[i]; vector<vector<ll>> dp(n + 1, vector<ll>(w)); for (ll i = 0; i < n; ++i) { for (ll j = 0; j <= w; ++j) { if (j - weight[i] >= 0) dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]); if (i > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j]); if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1]); } } cout << dp[n][w] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; main() { ll n, w; cin >> n >> w; vector<ll> weight(n), value(n); for (ll i = 0; i < n; ++i) cin >> weight[i] >> value[i]; vector<vector<ll>> dp(200, vector<ll>(200000)); for (ll i = 0; i < n; ++i) { for (ll j = 0; j <= w; ++j) { if (j - weight[i] >= 0) dp[i + 1][j] = max(dp[i][j], dp[i][j - weight[i]] + value[i]); if (i > 0) dp[i][j] = max(dp[i][j], dp[i - 1][j]); if (j > 0) dp[i][j] = max(dp[i][j], dp[i][j - 1]); } } cout << dp[n][w] << endl; }
[ "identifier.replace.remove", "literal.replace.add", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
968,215
968,216
u423624748
cpp
p03163
#include <bits/stdc++.h> #define m ((long long)1e9 + 7) typedef long long ll; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, w; cin >> n >> w; ll dp[n + 1][w + 1], a[n][2]; for (ll i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } for (ll i = 0; i < n + 1; i++) { for (ll j = 0; j < w + 1; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (a[i][0] <= j) dp[i][j] = max(a[i][1] + dp[i - 1][j - a[i][0]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << endl; return 0; }
#include <bits/stdc++.h> #define m ((long long)1e9 + 7) typedef long long ll; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, w; cin >> n >> w; ll dp[n + 1][w + 1], a[n][2]; for (ll i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } for (ll i = 0; i < n + 1; i++) { for (ll j = 0; j < w + 1; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (a[i - 1][0] <= j) dp[i][j] = max(a[i - 1][1] + dp[i - 1][j - a[i - 1][0]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][w] << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "misc.off_by_one", "assignment.change" ]
968,226
968,227
u997340502
cpp
p03163
#include <bits/stdc++.h> using namespace std; int main() { int n, w, i, j; cin >> n >> w; long long dp[n + 1][w + 1]; long long wt[n]; long long v[n]; for (i = 0; i < n; i++) { int w1, v1; cin >> w1 >> v1; wt[i] = w1; v[i] = v1; } for (i = 0; i <= n; i++) { for (j = 0; j <= w; j++) { if (i == 0) dp[i][j] = 0; else if (j == 0) dp[i][j] = 0; else if (j < wt[i - 1]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = min(dp[i - 1][j], v[i - 1] + dp[i - 1][j - wt[i - 1]]); } } cout << dp[n][w] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, w, i, j; cin >> n >> w; long long dp[n + 1][w + 1]; long long wt[n]; long long v[n]; for (i = 0; i < n; i++) { int w1, v1; cin >> w1 >> v1; wt[i] = w1; v[i] = v1; } for (i = 0; i <= n; i++) { for (j = 0; j <= w; j++) { if (i == 0) dp[i][j] = 0; else if (j == 0) dp[i][j] = 0; else if (j < wt[i - 1]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - wt[i - 1]]); } } cout << dp[n][w] << endl; return 0; }
[ "misc.opposites", "assignment.value.change", "identifier.change", "call.function.change" ]
968,236
968,237
u953182071
cpp
p03163
// In the Name of ̲A̲l̲l̲a̲h̲ #define pb push_back #define F first #define S second #define sz size() #define ll long long #include <bits/stdc++.h> using namespace std; int n, w[101], v[101], mx, dp[100001][101]; int main() { ios_base::sync_with_stdio(0); cin >> n >> mx; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } for (int i = w[0]; i <= mx; i++) dp[i][0] = v[0]; for (int i = 1; i < n; i++) { for (int j = 1; j <= mx; j++) { dp[j][i] = dp[j][i - 1]; if (j >= w[i]) dp[j][i] = max(dp[j][i], dp[j - w[i]][i - 1] + v[i]); } } cout << dp[mx][n - 1]; } /*𝐻𝒶𝒹𝒾*/
// In the Name of ̲A̲l̲l̲a̲h̲ #define pb push_back #define F first #define S second #define sz size() #define ll long long #include <bits/stdc++.h> using namespace std; ll n, w[101], v[101], mx, dp[100001][101]; int main() { ios_base::sync_with_stdio(0); cin >> n >> mx; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } for (ll i = w[0]; i <= mx; i++) dp[i][0] = v[0]; for (ll i = 0; i < n; i++) { for (ll j = 1; j <= mx; j++) { dp[j][i] = dp[j][i - 1]; if (j >= w[i]) dp[j][i] = max(dp[j][i], dp[j - w[i]][i - 1] + v[i]); } } cout << dp[mx][n - 1]; } /*𝐻𝒶𝒹𝒾*/
[ "variable_declaration.type.change", "control_flow.loop.for.initializer.change", "literal.number.change", "variable_declaration.value.change", "expression.off_by_one" ]
968,241
968,242
u947459087
cpp
p03163
#include <bits/stdc++.h> using namespace std; void solve(int w[], int v[], int W, int n) { int dp[n + 1][W + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= W; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (w[i - 1] <= j) dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - w[i - 1]]); else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][W]; } int main() { int n, W; cin >> n >> W; int v[n], w[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; solve(w, v, W, n); }
#include <bits/stdc++.h> using namespace std; void solve(int w[], int v[], int W, int n) { long dp[n + 1][W + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= W; j++) { if (i == 0 || j == 0) dp[i][j] = 0; else if (w[i - 1] <= j) dp[i][j] = max(dp[i - 1][j], v[i - 1] + dp[i - 1][j - w[i - 1]]); else dp[i][j] = dp[i - 1][j]; } } // for(int i=0; i<=n; i++) cout << dp[n][W]; } int main() { int n, W; cin >> n >> W; int v[n], w[n]; for (int i = 0; i < n; i++) cin >> w[i] >> v[i]; solve(w, v, W, n); }
[ "variable_declaration.type.primitive.change" ]
968,243
968,244
u589502773
cpp
p03163
#include <bits/stdc++.h> #define ll long long #define tezina first #define vrednost second using namespace std; int n, w; pair<int, ll> predmeti[110]; ll dp[100010][110]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> w; int t, v; for (int i = 1; i <= n; i++) { cin >> t >> v; predmeti[i] = make_pair(t, v); } sort(predmeti, predmeti + n); for (int j = 1; j <= n; j++) for (int i = 1; i <= w; i++) if (predmeti[j].tezina <= i) dp[i][j] = max(dp[i][j], dp[i - predmeti[j].tezina][j - 1] + predmeti[j].vrednost); else dp[i][j] = dp[i][j - 1]; cout << dp[w][n]; return 0; }
#include <bits/stdc++.h> #define ll long long #define tezina first #define vrednost second using namespace std; int n, w; pair<int, ll> predmeti[110]; ll dp[100010][110]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> w; int t, v; for (int i = 1; i <= n; i++) { cin >> t >> v; predmeti[i] = make_pair(t, v); } sort(predmeti, predmeti + n); for (int j = 1; j <= n; j++) for (int i = 1; i <= w; i++) if (predmeti[j].tezina <= i) dp[i][j] = max(dp[i][j - 1], dp[i - predmeti[j].tezina][j - 1] + predmeti[j].vrednost); else dp[i][j] = dp[i][j - 1]; cout << dp[w][n]; return 0; }
[ "assignment.change" ]
968,248
968,249
u433582964
cpp
p03163
#include <bits/stdc++.h> #define ll long long int using namespace std; signed main() { int n, x; cin >> n >> x; int w[n]; int v[n]; for (int i = 0; i < n; ++i) { cin >> w[i]; cin >> v[i]; } int dp[n + 1][x + 1]; for (int i = 0; i < n + 1; ++i) { dp[i][0] = 0; } for (int i = 0; i < x + 1; ++i) { dp[0][i] = 0; } for (int i = 1; i < n + 1; ++i) { for (int j = 1; j < x + 1; j++) { if (w[i - 1] <= j) { dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][x]; }
#include <bits/stdc++.h> #define int long long int using namespace std; signed main() { int n, x; cin >> n >> x; int w[n]; int v[n]; for (int i = 0; i < n; ++i) { cin >> w[i]; cin >> v[i]; } int dp[n + 1][x + 1]; for (int i = 0; i < n + 1; ++i) { dp[i][0] = 0; } for (int i = 0; i < x + 1; ++i) { dp[0][i] = 0; } for (int i = 1; i < n + 1; ++i) { for (int j = 1; j < x + 1; j++) { if (w[i - 1] <= j) { dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][x]; }
[ "identifier.change" ]
968,252
968,253
u072555549
cpp
p03163
#include <bits/stdc++.h> #define ll long long int using namespace std; signed main() { int n, x; cin >> n >> x; int w[n]; int v[n]; for (int i = 0; i < n; ++i) { cin >> w[i]; cin >> v[i]; } int dp[n + 1][x + 1]; for (int i = 0; i < n + 1; ++i) { dp[i][0] = 0; } for (int i = 0; i < x + 1; ++i) { dp[0][i] = 0; } for (int i = 1; i < n + 1; ++i) { for (int j = 1; j < x + 1; j++) { if (w[i - 1] <= j) { dp[i][j] = max(v[i - 1] + dp[i][j - w[i - 1]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][x]; }
#include <bits/stdc++.h> #define int long long int using namespace std; signed main() { int n, x; cin >> n >> x; int w[n]; int v[n]; for (int i = 0; i < n; ++i) { cin >> w[i]; cin >> v[i]; } int dp[n + 1][x + 1]; for (int i = 0; i < n + 1; ++i) { dp[i][0] = 0; } for (int i = 0; i < x + 1; ++i) { dp[0][i] = 0; } for (int i = 1; i < n + 1; ++i) { for (int j = 1; j < x + 1; j++) { if (w[i - 1] <= j) { dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } cout << dp[n][x]; }
[ "identifier.change" ]
968,254
968,253
u072555549
cpp