problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k โ | fixed_code stringlengths 12 526k โ | labels listlengths 0 15 โ | buggy_submission_id int64 1 1.54M โ | fixed_submission_id int64 2 1.54M โ | user_id stringlengths 10 10 โ | language stringclasses 9
values |
|---|---|---|---|---|---|---|---|
p03163 | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define input_from_file freopen("input.txt", "r", stdin);
int main() {
input_from_file;
// int t; cin>>t;
// while(t--){
ll n, sum;
cin >> n >> sum;
vector<vector<ll>> vec(n, vector<ll>(2, 0));
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < 2; j++)
cin >> vec[i][j];
}
vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, 0));
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= sum; j++) {
if (j < vec[i - 1][0])
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - vec[i - 1][0]] + vec[i - 1][1]);
}
}
}
// for(ll i=0;i<=n;i++){
// for(ll j=0;j<=sum;j++) cout<<dp[i][j]<<" ";cout<<endl;}
cout << dp[n][sum];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod = 1e9 + 7;
#define input_from_file freopen("input.txt", "r", stdin);
int main() {
// input_from_file;
// int t; cin>>t;
// while(t--){
ll n, sum;
cin >> n >> sum;
vector<vector<ll>> vec(n, vector<ll>(2, 0));
for (ll i = 0; i < n; i++) {
for (ll j = 0; j < 2; j++)
cin >> vec[i][j];
}
vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, 0));
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= sum; j++) {
if (j < vec[i - 1][0])
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - vec[i - 1][0]] + vec[i - 1][1]);
}
}
}
// for(ll i=0;i<=n;i++){
// for(ll j=0;j<=sum;j++) cout<<dp[i][j]<<" ";cout<<endl;}
cout << dp[n][sum];
return 0;
} | [] | 965,119 | 965,120 | u066630187 | cpp |
p03163 | #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//~ using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//~ int v[100100];
vector<vector<int>> dp(110, vector<int>(100100, 0));
//~ vector<int> dp(100100, 0));
int w[110], v[110];
int rec(int N, int W) {
if (dp[N][W] > 0)
return dp[N][W];
if (N == 0)
return 0;
int r = 0;
chmax(r, rec(N - 1, W));
if (W - w[N - 1] >= 0)
chmax(r, rec(N - 1, W - w[N - 1]) + v[N - 1]);
return dp[N][W] = r;
}
int main() {
int N, W;
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
cout << rec(N, W) << endl;
return 0;
}
| #define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//~ using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//~ int v[100100];
vector<vector<ll>> dp(110, vector<ll>(100100, 0));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));
ll w[110], v[110];
ll rec(int N, int W) {
if (dp[N][W] > 0)
return dp[N][W];
if (N == 0)
return 0;
ll r = 0;
chmax(r, rec(N - 1, W));
if (W - w[N - 1] >= 0)
chmax(r, rec(N - 1, W - w[N - 1]) + v[N - 1]);
return dp[N][W] = r;
}
int main() {
int N, W;
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
cout << rec(N, W) << endl;
return 0;
}
| [
"call.arguments.change",
"variable_declaration.type.change"
] | 965,122 | 965,123 | u986555878 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pi;
typedef long long ll;
const int MAX_INT = 2000000000;
int maxVal[100001];
int main() {
int N, W;
cin >> N >> W;
FOR(i, 1, W) { maxVal[i] = -1; }
int w, val;
FOR(j, 1, N) {
cin >> w >> val;
for (int i = W; i >= 0; i--) {
if (maxVal[i] != -1 && i + w <= W && maxVal[i] + val > maxVal[i + w])
maxVal[i + w] = maxVal[i] + val;
}
}
int ans = -1;
FOR(i, 0, W) { ans = max(ans, maxVal[i]); }
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pi;
typedef long long ll;
const int MAX_INT = 2000000000;
ll maxVal[100001];
int main() {
int N, W;
cin >> N >> W;
FOR(i, 1, W) { maxVal[i] = -1; }
int w, val;
FOR(j, 1, N) {
cin >> w >> val;
for (int i = W; i >= 0; i--) {
if (maxVal[i] != -1 && i + w <= W && maxVal[i] + val > maxVal[i + w])
maxVal[i + w] = maxVal[i] + val;
}
}
ll ans = -1;
FOR(i, 0, W) { ans = max(ans, maxVal[i]); }
cout << ans;
return 0;
}
| [
"variable_declaration.type.change"
] | 965,124 | 965,125 | u117022482 | cpp |
p03163 | #include <bits/stdc++.h>
typedef long long ll;
#define pb push_back;
using namespace std;
int main() {
ll n, w, a, b;
cin >> n >> w;
pair<ll, ll> l[n];
for (ll i = 0; i < n; i++) {
cin >> a >> b;
l[i] = {a, b};
}
ll m[n][w];
for (int x = 1; x <= w; x++) {
for (int i = 0; i < n; i++) {
if (l[i].first <= x) {
if (i - 1 < 0)
m[i][x] = l[i].second;
else {
m[i][x] =
max((m[i - 1][x]), (l[i].second + m[i - 1][x - (l[i].first)]));
}
} else {
if (i - 1 < 0)
m[i][x] = 0;
else {
m[i][x] = m[i - 1][x];
}
}
}
}
cout << m[n - 1][w] << endl;
}
| #include <bits/stdc++.h>
typedef long long ll;
#define pb push_back;
using namespace std;
int main() {
ll n, w, a, b;
cin >> n >> w;
pair<ll, ll> l[n];
for (ll i = 0; i < n; i++) {
cin >> a >> b;
l[i] = {a, b};
}
ll m[n][w];
for (int x = 0; x <= w; x++) {
for (int i = 0; i < n; i++) {
if (l[i].first <= x) {
if (i - 1 < 0)
m[i][x] = l[i].second;
else {
m[i][x] =
max((m[i - 1][x]), (l[i].second + m[i - 1][x - (l[i].first)]));
}
} else {
if (i - 1 < 0)
m[i][x] = 0;
else {
m[i][x] = m[i - 1][x];
}
}
}
}
cout << m[n - 1][w] << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 965,126 | 965,127 | u834471595 | cpp |
p03163 | #include <bits/stdc++.h>
typedef long long ll;
#define pb push_back;
using namespace std;
int main() {
ll n, w, a, b;
cin >> n >> w;
pair<ll, ll> l[n];
for (ll i = 0; i < n; i++) {
cin >> a >> b;
l[i] = {a, b};
}
ll m[n][w];
for (int x = 1; x <= w; x++) {
for (int i = 0; i < n; i++) {
if (l[i].first <= x) {
if (i - 1 < 0)
m[i][x] = l[i].second;
else {
m[i][x] =
max((m[i - 1][x]), (l[i].second + m[i - 1][x - l[i].first]));
}
} else {
if (i - 1 < 0)
m[i][x] = 0;
else {
m[i][x] = m[i - 1][x];
}
}
}
}
cout << m[n - 1][w] << endl;
}
| #include <bits/stdc++.h>
typedef long long ll;
#define pb push_back;
using namespace std;
int main() {
ll n, w, a, b;
cin >> n >> w;
pair<ll, ll> l[n];
for (ll i = 0; i < n; i++) {
cin >> a >> b;
l[i] = {a, b};
}
ll m[n][w];
for (int x = 0; x <= w; x++) {
for (int i = 0; i < n; i++) {
if (l[i].first <= x) {
if (i - 1 < 0)
m[i][x] = l[i].second;
else {
m[i][x] =
max((m[i - 1][x]), (l[i].second + m[i - 1][x - (l[i].first)]));
}
} else {
if (i - 1 < 0)
m[i][x] = 0;
else {
m[i][x] = m[i - 1][x];
}
}
}
}
cout << m[n - 1][w] << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"call.arguments.change"
] | 965,128 | 965,127 | u834471595 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (wt[i - 1] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
}
}
cout << dp[n][w] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= w; j++) {
if (wt[i - 1] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][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"
] | 965,135 | 965,136 | u167869723 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
int n,
w;
cin >> n >> w;
int v[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
int dp[n + 1][w + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
}
}
cout << dp[n][w] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
}
}
cout << dp[n][w] << endl;
return 0;
} | [
"identifier.change",
"variable_declaration.type.change",
"control_flow.loop.for.initializer.change"
] | 965,137 | 965,138 | u167869723 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long
// nt a[100000];
int dp[100][100001];
int solve(vector<pair<int, int>> &ar, int n, int w) {
dp[0][ar[0].first] = ar[0].second;
for (int i = 1; i < n; ++i) {
for (int weight = 0; weight <= w; ++weight) {
dp[i][weight] = dp[i - 1][weight];
if (ar[i].first > weight) {
continue;
}
dp[i][weight] =
max(dp[i - 1][weight], ar[i].second + dp[i - 1][w - ar[i].first]);
}
}
int mx = -1;
for (int i = 0; i <= w; ++i) {
mx = max(mx, dp[n - 1][i]);
}
return mx;
}
int32_t main() {
memset(dp, 0, sizeof dp);
vector<pair<int, int>> ar;
int n, w;
cin >> n >> w;
for (int i = 0; i < n; ++i) {
int wt, val;
cin >> wt >> val;
ar.push_back(make_pair(wt, val));
}
cout << solve(ar, n, w);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
// nt a[100000];
int dp[100][100001];
int solve(vector<pair<int, int>> &ar, int n, int w) {
dp[0][ar[0].first] = ar[0].second;
for (int i = 1; i < n; ++i) {
for (int weight = 0; weight <= w; ++weight) {
dp[i][weight] = dp[i - 1][weight];
if (ar[i].first > weight) {
continue;
}
dp[i][weight] = max(dp[i - 1][weight],
ar[i].second + dp[i - 1][weight - ar[i].first]);
}
}
int mx = -1;
for (int i = 0; i <= w; ++i) {
mx = max(mx, dp[n - 1][i]);
}
return mx;
}
int32_t main() {
memset(dp, 0, sizeof dp);
vector<pair<int, int>> ar;
int n, w;
cin >> n >> w;
for (int i = 0; i < n; ++i) {
int wt, val;
cin >> wt >> val;
ar.push_back(make_pair(wt, val));
}
cout << solve(ar, n, w);
return 0;
} | [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,141 | 965,142 | u103697897 | cpp |
p03163 | // Author - Saikat_7
#include <bits/stdc++.h>
using namespace std;
#define fl(i, a, b) for (int i = a; i < b; i++)
#define trav(i, cont) for (const auto &i : cont)
#define cs(x) cout << x << " "
#define cn(x) cout << x << " " << endl
#define ll long long int
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007 // 998244353
#define inf 1e17
const int mx = 2000005; // 2* (10 to power 5);
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int tc = 1;
// cin>>tc;
while (tc-- > 0) {
int n, w;
cin >> n >> w;
int wi[n + 1], vi[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wi[i] >> vi[i];
}
int dp[n + 1][w + 1] = {0};
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 < wi[i])
dp[i][j] = dp[i - 1][j];
// cout<<dp[i][j]<<" ";}
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wi[i]] + vi[i]);
// cout<<dp[i-1][j]<<i-1<<" " <<j<<" "<<endl;
// cout<<dp[i-1][j-wi[i]]+vi[i]<<endl;
}
}
cout << dp[n][w];
}
return 0;
} | // Author - Saikat_7
#include <bits/stdc++.h>
using namespace std;
#define fl(i, a, b) for (int i = a; i < b; i++)
#define trav(i, cont) for (const auto &i : cont)
#define cs(x) cout << x << " "
#define cn(x) cout << x << " " << endl
#define ll long long int
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007 // 998244353
#define inf 1e17
const int mx = 2000005; // 2* (10 to power 5);
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int tc = 1;
// cin>>tc;
while (tc-- > 0) {
ll n, w;
cin >> n >> w;
ll wi[n + 1], vi[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wi[i] >> vi[i];
}
ll dp[n + 1][w + 1] = {0};
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 < wi[i])
dp[i][j] = dp[i - 1][j];
// cout<<dp[i][j]<<" ";}
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wi[i]] + vi[i]);
// cout<<dp[i-1][j]<<i-1<<" " <<j<<" "<<endl;
// cout<<dp[i-1][j-wi[i]]+vi[i]<<endl;
}
}
cout << dp[n][w];
}
return 0;
} | [
"variable_declaration.type.change"
] | 965,143 | 965,144 | u426260736 | cpp |
p03163 | /*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
// sometimes it's the people who no one imagines anything of
// who do the things that no one can imagine.
// code author: iamxlr8
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define off \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
int main() {
off;
ll N, W;
cin >> N >> W;
ll w[N + 1], v[N + 1];
for (ll i = 1; i <= N; i++)
cin >> w[i] >> v[i];
vector<ll> dp(W + 1, INT_MIN);
dp[0] = 0;
for (ll i = 1; i <= N; i++) {
for (ll j = W; j >= w[i]; j--) {
dp[j] = max(dp[j], v[i] + dp[j - w[i]]);
}
}
cout << dp[W];
return 0;
} | /*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
// sometimes it's the people who no one imagines anything of
// who do the things that no one can imagine.
// code author: iamxlr8
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define off \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
int main() {
off;
ll N, W;
cin >> N >> W;
ll w[N + 1], v[N + 1];
for (ll i = 1; i <= N; i++)
cin >> w[i] >> v[i];
vector<ll> dp(W + 1, 0);
dp[0] = 0;
for (ll i = 1; i <= N; i++) {
for (ll j = W; j >= w[i]; j--) {
dp[j] = max(dp[j], v[i] + dp[j - w[i]]);
}
}
cout << dp[W];
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 965,145 | 965,146 | u788930704 | cpp |
p03163 | #include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[155][100055];
signed main() {
int n, w;
cin >> n >> w;
vector<int> inn(n), inw(n);
for (int i = 1; i <= n; i++)
cin >> inw[i] >> inn[i];
for (int k = 1; k <= n; k++)
for (int i = 0; i <= w; i++) {
dp[k][i] =
max(dp[k - 1][i], (i >= inw[k] ? dp[k - 1][i - inw[k]] + inn[k] : 0));
// cout<<dp[k][i]<<endl;
}
cout << dp[n][w] << endl;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[105][100005];
signed main() {
int n, w;
cin >> n >> w;
vector<int> inn(n + 1), inw(n + 1);
for (int i = 1; i <= n; i++)
cin >> inw[i] >> inn[i];
for (int k = 1; k <= n; k++)
for (int i = 0; i <= w; i++) {
dp[k][i] =
max(dp[k - 1][i], (i >= inw[k] ? dp[k - 1][i - inw[k]] + inn[k] : 0));
// cout<<dp[k][i]<<endl;
}
cout << dp[n][w] << endl;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 965,151 | 965,152 | u578026104 | cpp |
p03163 | #include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[102][100005];
signed main() {
int n, w;
cin >> n >> w;
vector<int> inn(n), inw(n);
for (int i = 1; i <= n; i++)
cin >> inw[i] >> inn[i];
for (int k = 1; k <= n; k++)
for (int i = 1; i <= w; i++) {
dp[k][i] =
max(dp[k - 1][i], (i >= inw[k] ? dp[k - 1][i - inw[k]] + inn[k] : 0));
// cout<<dp[k][i]<<endl;
}
cout << dp[n][w] << endl;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[105][100005];
signed main() {
int n, w;
cin >> n >> w;
vector<int> inn(n + 1), inw(n + 1);
for (int i = 1; i <= n; i++)
cin >> inw[i] >> inn[i];
for (int k = 1; k <= n; k++)
for (int i = 0; i <= w; i++) {
dp[k][i] =
max(dp[k - 1][i], (i >= inw[k] ? dp[k - 1][i - inw[k]] + inn[k] : 0));
// cout<<dp[k][i]<<endl;
}
cout << dp[n][w] << endl;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 965,153 | 965,152 | u578026104 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int n, W, v[107], w[107];
long long dp[107][107];
int main() {
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int wt = 1; wt <= W; wt++) {
if (w[i] <= wt) {
dp[i][wt] = max(v[i] + dp[i - 1][wt - w[i]], dp[i - 1][wt]);
} else
dp[i][wt] = dp[i - 1][wt];
}
}
cout << dp[n - 1][W];
}
| #include <bits/stdc++.h>
using namespace std;
int n, W, v[107], w[107];
long long dp[107][100007];
int main() {
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int wt = 1; wt <= W; wt++) {
if (w[i] <= wt) {
dp[i][wt] = max(v[i] + dp[i - 1][wt - w[i]], dp[i - 1][wt]);
} else
dp[i][wt] = dp[i - 1][wt];
}
}
cout << dp[n][W];
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"expression.operation.binary.remove"
] | 965,165 | 965,164 | u005436314 | cpp |
p03163 | //
// Created by Harshit on 20-08-2020.
//
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> weight(n);
vector<int> value(n);
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));
/*for(int i=1;i<n+1;i++){
for(int j=0;j<=W;j++){
if(j>=weight[i-1])
dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i-1]]+value[i-1]);
else
dp[i][j]=dp[i-1][j];
}
}*/
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
if (j + weight[i] <= W) {
dp[i + 1][j + weight[i]] =
max(dp[i + 1][j + weight[i]], dp[i][j] + value[i]);
}
}
}
cout << dp[n][W] << endl;
} | //
// Created by Harshit on 20-08-2020.
//
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> weight(n);
vector<int> value(n);
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
vector<vector<long long>> dp(n + 1, vector<long long>(W + 1, 0));
/* for(int i=1;i<n+1;i++){
for(int j=0;j<=W;j++){
if(j>=weight[i-1])
dp[i][j]=max(dp[i-1][j],dp[i-1][j-weight[i-1]]+value[i-1]);
else
dp[i][j]=dp[i-1][j];
}
}*/
for (int i = 0; i < n; i++) {
for (int j = 0; j <= W; j++) {
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
if (j + weight[i] <= W)
dp[i + 1][j + weight[i]] =
max(dp[i + 1][j + weight[i]], dp[i][j] + value[i]);
}
}
cout << dp[n][W] << endl;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 964,890 | 964,891 | u241916882 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
struct item {
int wt;
int val;
};
ll solve(vector<item> arr, int n, int W) {
int dp[n + 1][W + 1];
for (int w = 0; w <= W; w++) {
dp[1][w] = 0;
}
dp[1][arr[1].wt] = arr[1].val;
for (int i = 2; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (arr[i].wt > w)
continue;
dp[i][w] = max(dp[i][w], arr[i].val + dp[i - 1][w - arr[i].wt]);
}
}
return *max_element(dp[n], dp[n] + W + 1);
}
int main() {
int n, w;
cin >> n >> w;
vector<item> arr(n + 1);
for (int i = 1; i <= n; i++) {
cin >> arr[i].wt >> arr[i].val;
}
cout << solve(arr, n, w);
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
struct item {
int wt;
int val;
};
ll solve(vector<item> arr, int n, int W) {
ll dp[n + 1][W + 1];
for (int w = 0; w <= W; w++) {
dp[1][w] = 0;
}
dp[1][arr[1].wt] = arr[1].val;
for (int i = 2; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (arr[i].wt > w)
continue;
dp[i][w] = max(dp[i][w], arr[i].val + dp[i - 1][w - arr[i].wt]);
}
}
return *max_element(dp[n], dp[n] + W + 1);
}
int main() {
int n, w;
cin >> n >> w;
vector<item> arr(n + 1);
for (int i = 1; i <= n; i++) {
cin >> arr[i].wt >> arr[i].val;
}
cout << solve(arr, n, w);
return 0;
} | [
"variable_declaration.type.change"
] | 964,904 | 964,905 | u186820109 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N, W;
cin >> N >> W;
ll v[N], w[N];
for (ll i = 0; i < N; i++)
cin >> v[i] >> w[i];
ll dp[N + 1][W + 1];
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= W; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
dp[i][j] = dp[i - 1][j];
if (w[i - 1] <= j)
dp[i][j] = max(dp[i][j], v[i - 1] + dp[i - 1][j - w[i - 1]]);
}
}
}
ll ans = dp[N][W];
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N, W;
cin >> N >> W;
ll v[N], w[N];
for (ll i = 0; i < N; i++)
cin >> w[i] >> v[i];
ll dp[N + 1][W + 1];
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= W; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else {
dp[i][j] = dp[i - 1][j];
if (w[i - 1] <= j)
dp[i][j] = max(dp[i][j], v[i - 1] + dp[i - 1][j - w[i - 1]]);
}
}
}
ll ans = dp[N][W];
cout << ans;
return 0;
}
| [
"expression.operation.binary.remove"
] | 964,906 | 964,907 | u590450959 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using vll = vector<ll>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int n, W;
int w[110], v[110];
int dp[110][110000];
int main() {
cin >> n >> W;
rep(i, n) { cin >> w[i + 1] >> v[i + 1]; }
// dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
chmax(dp[i][j], dp[i - 1][j]);
if (j - w[i] >= 0)
chmax(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
}
}
cout << dp[n][W] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mp(x, y) make_pair(x, y)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using vll = vector<ll>;
using P = pair<int, int>;
const int inf = 1e9 + 7;
const ll INF = 1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
ll n, W;
ll w[110], v[110];
ll dp[110][110000];
int main() {
cin >> n >> W;
rep(i, n) { cin >> w[i + 1] >> v[i + 1]; }
// dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
chmax(dp[i][j], dp[i - 1][j]);
if (j - w[i] >= 0)
chmax(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
}
}
cout << dp[n][W] << endl;
} | [
"variable_declaration.type.change"
] | 964,910 | 964,911 | u531461815 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REV(i, a, n) for (int i = a; i >= n; i--)
#define all(a) a.begin(), a.end()
#define UB upper_bound
#define LB lower_bound
const int NUM = 2e5 + 5;
int w[100], v[100], dp[100][100001];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int num_tests = 1;
// cin >> num_tests;
while (num_tests-- > 0) {
int n, W;
cin >> n >> W;
FOR(i, 0, n) { cin >> w[i] >> v[i]; }
dp[0][0] = 0;
dp[0][w[0]] = v[0];
FOR(i, 1, n) {
dp[i][0] = 0;
FOR(j, 1, W + 1) {
dp[i][j] = dp[i - 1][j];
if (j >= W - w[i])
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
}
}
int ans = -1e18;
FOR(i, 0, W + 1)
ans = max(ans, dp[n - 1][i]);
cout << ans;
}
} | #include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REV(i, a, n) for (int i = a; i >= n; i--)
#define all(a) a.begin(), a.end()
#define UB upper_bound
#define LB lower_bound
const int NUM = 2e5 + 5;
int w[100], v[100], dp[100][100001];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int num_tests = 1;
// cin >> num_tests;
while (num_tests-- > 0) {
int n, W;
cin >> n >> W;
FOR(i, 0, n) { cin >> w[i] >> v[i]; }
dp[0][0] = 0;
dp[0][w[0]] = v[0];
FOR(i, 1, n) {
dp[i][0] = 0;
FOR(j, 1, W + 1) {
dp[i][j] = dp[i - 1][j];
if (j >= w[i])
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
}
}
int ans = -1e18;
FOR(i, 0, W + 1)
ans = max(ans, dp[n - 1][i]);
cout << ans;
}
} | [
"expression.operation.binary.remove"
] | 964,912 | 964,913 | u041777697 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
int main() {
ll n, w;
cin >> n >> w;
ll value[n];
ll weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i];
cin >> value[i];
}
ll dp[n][w + 1] = {0};
for (ll i = 0; i < n; i++) {
dp[i][0] = 0;
}
for (ll i = 0; i < n; i++) {
for (ll j = 1; j <= w; j++) {
if (i == 0) {
if (weight[i] < j) {
dp[i][j] = 0;
} else {
dp[i][j] = value[i];
}
continue;
}
if (j - weight[i] >= 0) {
dp[i][j] = max(dp[i - 1][j], value[i] + dp[i - 1][j - weight[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n - 1][w] << endl;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
int main() {
ll n, w;
cin >> n >> w;
ll value[n];
ll weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i];
cin >> value[i];
}
ll dp[n][w + 1] = {0};
for (ll i = 0; i < n; i++) {
dp[i][0] = 0;
}
for (ll i = 0; i < n; i++) {
for (ll j = 1; j <= w; j++) {
if (i == 0) {
if (weight[i] > j) {
dp[i][j] = 0;
} else {
dp[i][j] = value[i];
}
continue;
}
if (j - weight[i] >= 0) {
dp[i][j] = max(dp[i - 1][j], value[i] + dp[i - 1][j - weight[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n - 1][w] << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 964,916 | 964,917 | u844027714 | cpp |
p03163 | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
long int n;
long int a[100005][3];
long int dp[100005][5];
long int Func(int i, int wt_left) {
if (i >= n)
return 0;
if (dp[i][wt_left] != -1)
return dp[i][wt_left];
if (wt_left == 0)
return 0;
dp[i][wt_left] = Func(i + 1, wt_left);
if (-a[i][0] + wt_left >= 0) {
dp[i][wt_left] =
max(dp[i][wt_left], a[i][1] + Func(i + 1, wt_left - a[i][0]));
}
return dp[i][wt_left];
}
int main() {
cin >> n;
long int sum_left;
cin >> sum_left;
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
memset(dp, -1, sizeof(dp));
cout << Func(0, sum_left) << endl;
// for(int i=0;i<n;i++){
// for(int j=0;j<sum_left;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
} | #include <algorithm>
#include <bits/stdc++.h>
using namespace std;
long int n;
long int a[100005][3];
long int dp[102][100005];
long int Func(int i, int wt_left) {
if (i >= n)
return 0;
if (dp[i][wt_left] != -1)
return dp[i][wt_left];
if (wt_left == 0)
return 0;
dp[i][wt_left] = Func(i + 1, wt_left);
if (-a[i][0] + wt_left >= 0) {
dp[i][wt_left] =
max(dp[i][wt_left], a[i][1] + Func(i + 1, wt_left - a[i][0]));
}
return dp[i][wt_left];
}
int main() {
cin >> n;
long int sum_left;
cin >> sum_left;
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
}
memset(dp, -1, sizeof(dp));
cout << Func(0, sum_left) << endl;
// for(int i=0;i<n;i++){
// for(int j=0;j<sum_left;j++){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 964,920 | 964,921 | u395649803 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
struct item {
int wt;
int val;
};
ll solve(vector<item> ar, int n, int W) {
int dp[n + 1][W + 1];
// for first item other than weight of item is zero
for (int w = 0; w <= W; w++)
dp[1][w] = 0;
dp[1][ar[1].wt] = ar[1].val;
// bottom up approach now
for (int i = 2; i <= n; i++) {
// calculating best possible answer for given weight
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w]; // not taking the item
if (ar[i].wt > w)
continue;
dp[i][w] =
max(dp[i][w], ar[i].val + dp[i - 1][w - ar[i].wt]); // taking the item
}
}
return *max_element(dp[n], dp[n] + W + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<item> ar(n + 1);
for (int i = 1; i <= n; i++)
cin >> ar[i].wt >> ar[i].val;
cout << solve(ar, n, w);
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
struct item {
int wt;
int val;
};
ll solve(vector<item> ar, int n, int W) {
ll dp[n + 1][W + 1];
// for first item other than weight of item is zero
for (int w = 0; w <= W; w++)
dp[1][w] = 0;
dp[1][ar[1].wt] = ar[1].val;
// bottom up approach now
for (int i = 2; i <= n; i++) {
// calculating best possible answer for given weight
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w]; // not taking the item
if (ar[i].wt > w)
continue;
dp[i][w] =
max(dp[i][w], ar[i].val + dp[i - 1][w - ar[i].wt]); // taking the item
}
}
return *max_element(dp[n], dp[n] + W + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<item> ar(n + 1);
for (int i = 1; i <= n; i++)
cin >> ar[i].wt >> ar[i].val;
cout << solve(ar, n, w);
} | [
"variable_declaration.type.change"
] | 964,922 | 964,923 | u658097643 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int solve() {
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[w + 1][n + 1];
for (int i = 0; i <= n; ++i) {
dp[0][i] = 0;
}
for (int i = 0; i <= w; ++i) {
dp[i][0] = 0;
}
for (int i = 1; i <= w; ++i) {
for (int j = 1; j <= n; ++j) {
dp[i][j] = i - wt[j - 1] >= 0
? max(val[j - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1])
: dp[i][j - 1];
}
}
// for(int i = 0; i<=w; ++i) {
// for(int j = 0; j<=n; ++j)
// cout<<dp[i][j]<<" ";
// cout<<endl;
// }
return dp[w][n];
}
int main() {
cout << solve() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long solve() {
int n, w;
cin >> n >> w;
long long wt[n], val[n];
for (int i = 0; i < n; ++i) {
cin >> wt[i] >> val[i];
// cout<<wt[i]<<" "<<val[i]<<endl;
}
long long dp[w + 1][n + 1];
for (int i = 0; i <= n; ++i) {
dp[0][i] = 0;
}
for (int i = 0; i <= w; ++i) {
dp[i][0] = 0;
}
for (int i = 1; i <= w; ++i) {
for (int j = 1; j <= n; ++j) {
dp[i][j] = i - wt[j - 1] >= 0
? max(val[j - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1])
: dp[i][j - 1];
}
}
return dp[w][n];
}
int main() {
cout << solve() << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 964,924 | 964,925 | u697483609 | cpp |
p03163 | #include <bits/stdc++.h>
#define line cout << endl;
#define space cout << " ";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;
using namespace std;
const int N = 1e9 + 7;
vector<ll> wt(100005);
vector<ll> val(100005);
ll dp[10005][10005];
ll knapsackone(ll n, ll w) {
if (n == 0 || w == 0)
return 0;
if (dp[n][w] != -1)
return dp[n][w];
if (wt[n - 1] <= w) {
return dp[n][w] = max(val[n - 1] + knapsackone(n - 1, w - wt[n - 1]),
knapsackone(n - 1, w));
} else
return dp[n][w] = knapsackone(n - 1, w);
}
void solve() {
memset(dp, -1, sizeof(dp));
ll n, w;
cin >> n;
cin >> w;
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
}
ll ans = knapsackone(n, w);
cout << ans;
}
int main() {
ll t;
t = 1;
// cin>>t;
while (t--) {
solve();
cout << endl;
}
}
| #include <bits/stdc++.h>
#define line cout << endl;
#define space cout << " ";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;
using namespace std;
const int N = 1e9 + 7;
vector<ll> wt(100005);
vector<ll> val(100005);
ll dp[105][100005];
ll knapsackone(ll n, ll w) {
if (n == 0 || w == 0)
return 0;
if (dp[n][w] != -1)
return dp[n][w];
if (wt[n - 1] <= w) {
return dp[n][w] = max(val[n - 1] + knapsackone(n - 1, w - wt[n - 1]),
knapsackone(n - 1, w));
} else
return dp[n][w] = knapsackone(n - 1, w);
}
void solve() {
memset(dp, -1, sizeof(dp));
ll n, w;
cin >> n;
cin >> w;
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
}
ll ans = knapsackone(n, w);
cout << ans;
}
int main() {
ll t;
t = 1;
// cin>>t;
while (t--) {
solve();
cout << endl;
}
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 964,926 | 964,927 | u478482513 | cpp |
p03163 | #include <bits/stdc++.h>
#define line cout << endl;
#define space cout << " ";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;
using namespace std;
const int N = 1e9 + 7;
vector<ll> wt(100005);
vector<ll> val(100005);
ll dp[10005][10005];
ll knapsackone(ll n, ll w) {
if (n == 0 || w == 0)
return 0;
if (dp[n][w] != -1)
return dp[n][w];
if (wt[n] <= w) {
return dp[n][w] = max(val[n] + knapsackone(n - 1, w - wt[n]),
knapsackone(n - 1, w));
} else
return dp[n][w] = knapsackone(n - 1, w);
}
void solve() {
memset(dp, -1, sizeof(dp));
ll n, w;
cin >> n;
cin >> w;
for (int i = 1; i <= n; i++) {
cin >> wt[i];
cin >> val[i];
}
ll ans = knapsackone(n, w);
cout << dp[n][w];
}
int main() {
ll t;
t = 1;
// cin>>t;
while (t--) {
solve();
cout << endl;
}
}
| #include <bits/stdc++.h>
#define line cout << endl;
#define space cout << " ";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.141592653589793238
typedef long long int ll;
using namespace std;
const int N = 1e9 + 7;
vector<ll> wt(100005);
vector<ll> val(100005);
ll dp[105][100005];
ll knapsackone(ll n, ll w) {
if (n == 0 || w == 0)
return 0;
if (dp[n][w] != -1)
return dp[n][w];
if (wt[n] <= w) {
return dp[n][w] = max(val[n] + knapsackone(n - 1, w - wt[n]),
knapsackone(n - 1, w));
} else
return dp[n][w] = knapsackone(n - 1, w);
}
void solve() {
memset(dp, -1, sizeof(dp));
ll n, w;
cin >> n;
cin >> w;
for (int i = 1; i <= n; i++) {
cin >> wt[i];
cin >> val[i];
}
ll ans = knapsackone(n, w);
cout << dp[n][w];
}
int main() {
ll t;
t = 1;
// cin>>t;
while (t--) {
solve();
cout << endl;
}
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 964,928 | 964,929 | u943964167 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
int n, w;
void solve() {
cin >> n >> w;
int weight[n], value[n], dp[n + 1][w + 1];
for (int i = 0; i < n; ++i) {
cin >> weight[i];
cin >> value[i];
}
for (int i = 0; i < n + 1; i++)
dp[i][0] = 0;
for (int i = 0; i <= w; i++)
dp[0][i] = 0;
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j <= w; j++) {
if (j - weight[i - 1] < 0)
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] =
max(value[i - 1] + dp[i - 1][j - weight[i - 1]], dp[i - 1][j]);
}
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
// cout<<endl;
cout << dp[n][w];
}
int main() {
io;
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
int n, w;
void solve() {
cin >> n >> w;
int weight[n], value[n];
ll dp[n + 1][w + 1];
for (int i = 0; i < n; ++i) {
cin >> weight[i];
cin >> value[i];
}
for (int i = 0; i < n + 1; i++)
dp[i][0] = 0;
for (int i = 0; i <= w; i++)
dp[0][i] = 0;
for (int i = 1; i < n + 1; i++) {
for (int j = 1; j <= w; j++) {
if (j - weight[i - 1] < 0)
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] =
(ll)max(value[i - 1] + dp[i - 1][j - weight[i - 1]], dp[i - 1][j]);
}
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
// cout<<endl;
cout << dp[n][w];
}
int main() {
io;
solve();
return 0;
}
| [
"type_conversion.add"
] | 964,930 | 964,931 | u372058452 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
int n, w;
cin >> n >> w;
int weight[n];
int prices[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> prices[i];
}
int dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (j - weight[i - 1] >= 0)
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + prices[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
/*
for(int i=0;i<=n;i++){
for(int j=0;j<=w;j++){
cout<<dp[i][j]<<" " ;
}
cout<<"\n" ;
}
*/
cout << dp[n][w];
}
int main() {
int y;
y = 1;
// cin>>y ;
while (y--) {
solve();
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
int n, w;
cin >> n >> w;
ll weight[n];
ll prices[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> prices[i];
}
ll dp[n + 1][w + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (j - weight[i - 1] >= 0)
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + prices[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
/*
for(int i=0;i<=n;i++){
for(int j=0;j<=w;j++){
cout<<dp[i][j]<<" " ;
}
cout<<"\n" ;
}
*/
cout << dp[n][w];
}
int main() {
int y;
y = 1;
// cin>>y ;
while (y--) {
solve();
}
}
| [
"variable_declaration.type.change"
] | 964,934 | 964,935 | u806692883 | cpp |
p03163 |
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int dp[n + 1][w + 1];
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 (i == 0 || j == 0) {
dp[i][j] = 0;
} else 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][w];
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
long dp[n + 1][w + 1];
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 (i == 0 || j == 0) {
dp[i][j] = 0;
} else 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][w];
}
| [
"variable_declaration.type.primitive.change"
] | 964,944 | 964,945 | u794552329 | cpp |
p03163 | #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n, W;
scanf("%d %d", &n, &W);
vector<ll> dp(n + 1, 0);
for (int k = 0; k < n; k++) {
int w, val;
scanf("%d%d", &w, &val);
for (auto x = W - w; x >= 0; --x) {
dp[x + w] = max(dp[x + w], dp[x] + val);
}
}
ll res = 0;
for (int i = 0; i <= W; i++) {
res = max(res, dp[i]);
}
printf("%lld\n", res);
}
| #include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n, W;
scanf("%d %d", &n, &W);
vector<ll> dp(W + 1, 0);
for (int k = 0; k < n; k++) {
int w, val;
scanf("%d%d", &w, &val);
for (int x = W - w; x >= 0; x--) {
dp[x + w] = max(dp[x + w], dp[x] + val);
}
}
ll res = 0;
for (int i = 0; i <= W; i++) {
res = max(res, dp[i]);
}
printf("%lld\n", res);
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.for.initializer.change"
] | 964,946 | 964,947 | u371777495 | cpp |
p03163 | #include <bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn = 1e5 + 10;
int n, w;
int dp[105][maxn];
int val[105];
int wet[105];
int32_t main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> wet[i] >> val[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (wet[i] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wet[i]] + val[i]);
}
}
}
cout << dp[n][w] << endl;
}
| #include <bits/stdc++.h>
typedef long long LL;
using namespace std;
const LL maxn = 1e5 + 10;
LL n, w;
LL dp[105][maxn];
int val[105];
int wet[105];
int32_t main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> wet[i] >> val[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (wet[i] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wet[i]] + val[i]);
}
}
}
cout << dp[n][w] << endl;
}
| [
"variable_declaration.type.change"
] | 964,952 | 964,953 | u283484070 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define dlog(x) cerr << #x << '=' << x << endl
#define f first
#define s second
#define endl '\n'
#define sq(x) (x) * (x)*1ll
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int weight[100], value[100], dp[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("test_input.txt", "r", stdin);
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
for (int i = 0; i < n; i++) {
for (int j = w; j >= weight[i]; j--) {
dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
}
}
cout << dp[w];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define dlog(x) cerr << #x << '=' << x << endl
#define f first
#define s second
#define endl '\n'
#define sq(x) (x) * (x)*1ll
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll weight[100], value[100], dp[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// freopen("test_input.txt", "r", stdin);
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
for (int i = 0; i < n; i++) {
for (int j = w; j >= weight[i]; j--) {
dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);
}
}
cout << dp[w];
return 0;
} | [
"variable_declaration.type.change"
] | 965,171 | 965,172 | u093681822 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define WEIGHTSUM weight + i
#define VALUESUM maxValue[i] + value
using namespace std;
ll maxValue[100005];
int main() {
ll n, w, weight, value;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> weight >> value;
for (int i = w; i >= 0; i--)
if (maxValue[i] && WEIGHTSUM <= w) {
maxValue[WEIGHTSUM] = max(maxValue[WEIGHTSUM], VALUESUM);
maxValue[w] = max(maxValue[w], VALUESUM);
}
}
cout << maxValue[w];
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define WEIGHTSUM weight + i
#define VALUESUM maxValue[i] + value
using namespace std;
ll maxValue[100005];
int main() {
ll n, w, weight, value;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> weight >> value;
for (int i = w; i >= 0; i--)
if (WEIGHTSUM <= w) {
maxValue[WEIGHTSUM] = max(maxValue[WEIGHTSUM], VALUESUM);
maxValue[w] = max(maxValue[w], VALUESUM);
}
}
cout << maxValue[w];
return 0;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 965,173 | 965,174 | u684798281 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> dp(W + 1, 0);
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
for (int wa = W - w; wa >= 0; wa--) {
dp[wa + w] = max(dp[wa + w], dp[wa] + v);
}
}
int maxi = 0;
for (int i = 0; i <= W; i++)
maxi = max(dp[i], maxi);
cout << maxi;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<long long> dp(W + 1, 0);
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
for (int wa = W - w; wa >= 0; wa--) {
dp[wa + w] = max(dp[wa + w], dp[wa] + v);
}
}
long long maxi = 0;
for (int i = 0; i <= W; i++)
maxi = max(dp[i], maxi);
cout << maxi;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,180 | 965,181 | u001462978 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, w;
cin >> n >> w;
ll W[n + 1];
ll V[n + 1];
for (ll i = 1; i <= n; i++)
cin >> W[i] >> V[i];
ll M[n + 1][w + 1];
memset(M, 0, sizeof M);
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= w; j++) {
if (j - W[i] >= 0)
M[i][j] = max(M[i][j], M[i - 1][j - W[i]] + V[i]);
else
M[i][j] = M[i - 1][j];
}
}
cout << M[n][w];
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll, ll>
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, w;
cin >> n >> w;
ll W[n + 1];
ll V[n + 1];
for (ll i = 1; i <= n; i++)
cin >> W[i] >> V[i];
ll M[n + 1][w + 1];
memset(M, 0, sizeof M);
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= w; j++) {
if (j - W[i] >= 0)
M[i][j] = max(M[i - 1][j], M[i - 1][j - W[i]] + V[i]);
else
M[i][j] = M[i - 1][j];
}
}
cout << M[n][w];
}
| [
"assignment.change"
] | 965,184 | 965,185 | u241586777 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int v[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> v[i];
}
vector<long long> dp(w + 1, 0);
for (int i = 0; i < n; i++) {
for (int j = w - i; j >= 0; j--) {
dp[j + wt[i]] = max(dp[j + wt[i]], v[i] + dp[j]);
}
// for (int i = 0; i < w + 1; i++)
// {
// cout << dp[i] << " ";
// }
// cout << endl;
}
long long ans = 0;
for (int i = 0; i < w + 1; i++) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int v[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> v[i];
}
vector<long long> dp(w + 1, 0);
for (int i = 0; i < n; i++) {
for (long long j = w - wt[i]; j >= 0; j--) {
dp[j + wt[i]] = max(dp[j + wt[i]], v[i] + dp[j]);
}
// for (int i = 0; i < w + 1; i++)
// {
// cout << dp[i] << " ";
// }
// cout << endl;
}
long long ans = 0;
for (int i = 0; i < w + 1; i++) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
} | [
"control_flow.loop.for.initializer.change",
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,190 | 965,191 | u335562906 | cpp |
p03163 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n, we;
cin >> n >> we;
vector<int> dp(we + 1, 0), w(n), v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int j = 0; j < n; j++) {
for (int i = we; i > 0; i--) {
if (i >= w[j]) {
dp[i] = max(dp[i], v[j] + dp[i - w[j]]);
}
}
}
// for(auto i:dp)cout<<i<<" ";
cout << dp[we] << endl;
return 0;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
int main() {
int n, we;
cin >> n >> we;
vector<ll int> dp(we + 1, 0), w(n), v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int j = 0; j < n; j++) {
for (int i = we; i > 0; i--) {
if (i >= w[j]) {
dp[i] = max(dp[i], v[j] + dp[i - w[j]]);
}
}
}
// for(auto i:dp)cout<<i<<" ";
cout << dp[we] << endl;
return 0;
} | [] | 965,192 | 965,193 | u275249182 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
long long int dp[w + 1][n + 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++) {
int w1;
long long int c;
cin >> w1 >> c;
for (int j = 1; j <= w; j++) {
if (w1 <= j) {
dp[i][j] = max(c + dp[i - 1][j - w1], 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;
long long 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++) {
int w1;
long long int c;
cin >> w1 >> c;
for (int j = 1; j <= w; j++) {
if (w1 <= j) {
dp[i][j] = max(c + dp[i - 1][j - w1], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
return 0;
} | [
"identifier.change",
"expression.operation.binary.change"
] | 965,194 | 965,195 | u427759487 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
long long int dp[w + 1][n + 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++) {
int w1;
long long int c;
cin >> w1 >> c;
for (int j = 1; j <= w; j++) {
if (w1 <= j) {
dp[i][j] = max(c + dp[i][j - w1], 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;
long long 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++) {
int w1;
long long int c;
cin >> w1 >> c;
for (int j = 1; j <= w; j++) {
if (w1 <= j) {
dp[i][j] = max(c + dp[i - 1][j - w1], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
return 0;
} | [
"identifier.change",
"expression.operation.binary.change"
] | 965,197 | 965,195 | u427759487 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
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++) {
int w1, c;
cin >> w1 >> c;
for (int j = 1; j <= w; j++) {
if (w1 <= j) {
dp[i][j] = max(c + dp[i - 1][j - w1], 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;
long long 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++) {
int w1;
long long int c;
cin >> w1 >> c;
for (int j = 1; j <= w; j++) {
if (w1 <= j) {
dp[i][j] = max(c + dp[i - 1][j - w1], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
return 0;
} | [
"variable_declaration.type.widen.change"
] | 965,199 | 965,195 | u427759487 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n), value(n);
for (ll i = 1; i <= n; ++i) {
cin >> weight[i] >> value[i];
}
ll arr[n + 1][w + 1];
for (ll i = 0; i < n + 1; ++i) {
for (ll j = 0; j < w + 1; ++j)
arr[i][j] = 0;
}
for (ll i = 1; i <= n; ++i) {
for (ll j = 1; j <= w; ++j) {
if (j < weight[i]) {
arr[i][j] = arr[i - 1][j];
} else
arr[i][j] = max(value[i] + arr[i - 1][j - weight[i]], arr[i - 1][j]);
}
}
cout << *max_element(arr[n], arr[n] + w + 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(101), value(101);
for (ll i = 1; i <= n; ++i) {
cin >> weight[i] >> value[i];
}
ll arr[n + 1][w + 1];
for (ll i = 0; i < n + 1; ++i) {
for (ll j = 0; j < w + 1; ++j)
arr[i][j] = 0;
}
for (ll i = 1; i <= n; ++i) {
for (ll j = 1; j <= w; ++j) {
if (j < weight[i]) {
arr[i][j] = arr[i - 1][j];
} else
arr[i][j] = max(value[i] + arr[i - 1][j - weight[i]], arr[i - 1][j]);
}
}
cout << *max_element(arr[n], arr[n] + w + 1);
return 0;
}
| [] | 965,203 | 965,204 | u027630431 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n), value(n);
for (ll i = 1; i <= n; ++i) {
cin >> weight[i] >> value[i];
}
ll arr[n + 24][w + 51];
for (ll i = 0; i < n + 24; ++i) {
for (ll j = 0; j < w + 51; ++j)
arr[i][j] = 0;
}
for (ll i = 1; i <= n; ++i) {
for (ll j = 1; j <= w; ++j) {
if (j < weight[i]) {
arr[i][j] = arr[i - 1][j];
} else
arr[i][j] = max(value[i] + arr[i - 1][j - weight[i]], arr[i - 1][j]);
}
}
cout << *max_element(arr[n], arr[n] + w + 1);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(101), value(101);
for (ll i = 1; i <= n; ++i) {
cin >> weight[i] >> value[i];
}
ll arr[n + 1][w + 1];
for (ll i = 0; i < n + 1; ++i) {
for (ll j = 0; j < w + 1; ++j)
arr[i][j] = 0;
}
for (ll i = 1; i <= n; ++i) {
for (ll j = 1; j <= w; ++j) {
if (j < weight[i]) {
arr[i][j] = arr[i - 1][j];
} else
arr[i][j] = max(value[i] + arr[i - 1][j - weight[i]], arr[i - 1][j]);
}
}
cout << *max_element(arr[n], arr[n] + w + 1);
return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change",
"control_flow.loop.for.condition.change"
] | 965,205 | 965,204 | u027630431 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return (a > b ? a : b); }
int main() {
// code
int t;
t = 1;
while (t--) {
int n;
cin >> n;
int W;
cin >> 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 w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (w < wt[i - 1])
dp[i][w] = dp[i - 1][w];
else
dp[i][w] = max(val[i - 1] + dp[i - 1][w - wt[i - 1]], dp[i - 1][w]);
}
cout << dp[n][W] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int max(int a, int b) { return (a > b ? a : b); }
int main() {
// code
int t;
t = 1;
while (t--) {
int n;
cin >> n;
int W;
cin >> W;
int wt[n], val[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
long dp[n + 1][W + 1];
for (int i = 0; i <= n; i++)
for (int w = 0; w <= W; w++) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else if (w < wt[i - 1])
dp[i][w] = dp[i - 1][w];
else
dp[i][w] = max(val[i - 1] + dp[i - 1][w - wt[i - 1]], dp[i - 1][w]);
}
cout << dp[n][W] << endl;
}
return 0;
} | [
"variable_declaration.type.primitive.change"
] | 965,208 | 965,209 | u205212925 | cpp |
p03163 | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<int> wt(N), score(N);
for (int i = 0; i < N; ++i) {
cin >> wt[i] >> score[i];
}
long long dp[N + 1][W + 1];
for (int i = 0; i <= N; ++i) {
for (int w = 0; w <= W; ++w) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else {
int inc = 0, exc = 0;
if (wt[i - 1] <= w)
inc = score[i - 1] + dp[i - 1][w - wt[i - 1]];
exc = dp[i - 1][w];
dp[i][w] = max(inc, exc);
}
}
}
cout << dp[N][W];
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<int> wt(N), score(N);
for (int i = 0; i < N; ++i) {
cin >> wt[i] >> score[i];
}
long long dp[N + 1][W + 1];
for (int i = 0; i <= N; ++i) {
for (int w = 0; w <= W; ++w) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else {
long long inc = 0, exc = 0;
if (wt[i - 1] <= w)
inc = score[i - 1] + dp[i - 1][w - wt[i - 1]];
exc = dp[i - 1][w];
dp[i][w] = max(inc, exc);
}
}
}
cout << dp[N][W];
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,216 | 965,217 | u767425163 | cpp |
p03163 | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<int> wt(N), score(N);
for (int i = 0; i < N; ++i) {
cin >> wt[i] >> score[i];
}
int dp[N + 1][W + 1];
for (int i = 0; i <= N; ++i) {
for (int w = 0; w <= W; ++w) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else {
int inc = 0, exc = 0;
if (wt[i - 1] <= w)
inc = score[i - 1] + dp[i - 1][w - wt[i - 1]];
exc = dp[i - 1][w];
dp[i][w] = max(inc, exc);
}
}
}
cout << dp[N][W];
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<int> wt(N), score(N);
for (int i = 0; i < N; ++i) {
cin >> wt[i] >> score[i];
}
long long dp[N + 1][W + 1];
for (int i = 0; i <= N; ++i) {
for (int w = 0; w <= W; ++w) {
if (i == 0 || w == 0)
dp[i][w] = 0;
else {
long long inc = 0, exc = 0;
if (wt[i - 1] <= w)
inc = score[i - 1] + dp[i - 1][w - wt[i - 1]];
exc = dp[i - 1][w];
dp[i][w] = max(inc, exc);
}
}
}
cout << dp[N][W];
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,218 | 965,217 | u767425163 | cpp |
p03163 | #include <iostream>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int *wt = new int[n];
int *val = new int[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
int dp[n + 1][w + 1];
for (int item = 0; item <= n; item++) {
for (int weight = 0; weight <= w; weight++) {
if (weight == 0 || item == 0) {
dp[item][weight] = 0;
} else if (wt[item - 1] <= weight) {
dp[item][weight] =
std::max(dp[item - 1][weight],
val[item - 1] + dp[item - 1][weight - wt[item - 1]]);
} else {
dp[item][weight] = dp[item - 1][weight];
}
}
}
cout << dp[n][w];
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
int *wt = new int[n];
int *val = new int[n];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
long long dp[n + 1][w + 1];
for (int item = 0; item <= n; item++) {
for (int weight = 0; weight <= w; weight++) {
if (weight == 0 || item == 0) {
dp[item][weight] = 0;
} else if (wt[item - 1] <= weight) {
dp[item][weight] =
std::max(dp[item - 1][weight],
val[item - 1] + dp[item - 1][weight - wt[item - 1]]);
} else {
dp[item][weight] = dp[item - 1][weight];
}
}
}
cout << dp[n][w] << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"io.output.newline.add"
] | 965,225 | 965,226 | u186994371 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define all(c) c.begin(), c.end()
#define pb push_back
#define F first
#define S second
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
int k, w;
cin >> n >> w;
vector<pair<int, int>> arr(n);
int dp[n + 1][w + 1];
for (int i = 0; i < n; ++i) {
cin >> arr[i].F >> arr[i].S;
}
sort(all(arr));
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 (arr[i - 1].F <= j) {
dp[i][j] =
max(arr[i - 1].S + dp[i - 1][j - arr[i - 1].F], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
}
cout << dp[n][w] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define all(c) c.begin(), c.end()
#define pb push_back
#define F first
#define S second
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
int k, w;
cin >> n >> w;
vector<pair<int, ll>> arr(n);
ll dp[n + 1][w + 1];
for (int i = 0; i < n; ++i) {
cin >> arr[i].F >> arr[i].S;
}
sort(all(arr));
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 (arr[i - 1].F <= j) {
dp[i][j] =
max(arr[i - 1].S + dp[i - 1][j - arr[i - 1].F], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
}
cout << dp[n][w] << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 965,237 | 965,238 | u287226050 | cpp |
p03163 | #include <bits/stdc++.h>
#define rep(i, n) \
; \
for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> state;
long double pi = acos(-1);
const int INF = 1001001001;
const int N_MAX = 1000;
// ๆๅฐๅ
ฌๅๆฐใๆฑใใ
int euqlid(int a, int b) {
int temp;
temp = a % b;
if (temp == 0)
return b;
return euqlid(b, temp);
}
ll conbination(ll a, ll b) {
ll u = 1;
ll d = 1;
while (b != 0) {
u *= a;
d *= b;
a--;
b--;
}
return u / d;
}
int strtoint(char s) { return (int(s - '0')); }
char changeS(char alpha) {
if (0x41 <= alpha and alpha <= 0x5A)
return (alpha + 0x20);
else if (0x61 <= alpha and alpha <= 0x7A)
return (alpha - 0x20);
return alpha;
}
int fact(int n) {
if (n == 1)
return 1;
return n * fact(n - 1);
}
int ceil(int a, int b) {
// a/bใฎๅใไธใใ่ใใ
return (a + b - 1) / b;
}
int n, wlim;
int w[N_MAX], v[N_MAX];
int dp[101][100001];
ll dfs(int i, int noww) {
if (dp[i][noww] > 0) {
return dp[i][noww];
}
ll ret;
if (i == n) {
// ๅ
จใฆ่ฆใใฎใงๆข็ดขใ็ตใใ
ret = 0;
} else if (noww + w[i] > wlim) {
// ไปๅใฎ่ฆ็ด ใฏๅซใพใใซๆฌกใธ้ฒใ
ret = dfs(i + 1, noww);
} else {
ret = max(dfs(i + 1, noww), dfs(i + 1, noww + w[i]) + v[i]);
}
return dp[i][noww] = ret;
}
int main() {
cin >> n >> wlim;
rep(i, n) cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << dfs(0, 0) << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) \
; \
for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> state;
long double pi = acos(-1);
const int INF = 1001001001;
const int N_MAX = 1000;
// ๆๅฐๅ
ฌๅๆฐใๆฑใใ
int euqlid(int a, int b) {
int temp;
temp = a % b;
if (temp == 0)
return b;
return euqlid(b, temp);
}
ll conbination(ll a, ll b) {
ll u = 1;
ll d = 1;
while (b != 0) {
u *= a;
d *= b;
a--;
b--;
}
return u / d;
}
int strtoint(char s) { return (int(s - '0')); }
char changeS(char alpha) {
if (0x41 <= alpha and alpha <= 0x5A)
return (alpha + 0x20);
else if (0x61 <= alpha and alpha <= 0x7A)
return (alpha - 0x20);
return alpha;
}
int fact(int n) {
if (n == 1)
return 1;
return n * fact(n - 1);
}
int ceil(int a, int b) {
// a/bใฎๅใไธใใ่ใใ
return (a + b - 1) / b;
}
int n, wlim;
int w[N_MAX], v[N_MAX];
ll dp[101][100001];
ll dfs(int i, int noww) {
if (dp[i][noww] > 0) {
return dp[i][noww];
}
ll ret;
if (i == n) {
// ๅ
จใฆ่ฆใใฎใงๆข็ดขใ็ตใใ
ret = 0;
} else if (noww + w[i] > wlim) {
// ไปๅใฎ่ฆ็ด ใฏๅซใพใใซๆฌกใธ้ฒใ
ret = dfs(i + 1, noww);
} else {
ret = max(dfs(i + 1, noww), dfs(i + 1, noww + w[i]) + v[i]);
}
return dp[i][noww] = ret;
}
int main() {
cin >> n >> wlim;
rep(i, n) cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
cout << dfs(0, 0) << endl;
}
| [
"variable_declaration.type.change"
] | 965,243 | 965,244 | u239316561 | cpp |
p03162 | /*author : Yashvardhan
Saturday, January 12, 2019
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define pb push_back
#define make_pair mp
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pi>
#define ff first
#define ss second
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size(); ++i)
os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto it : v)
os << it << " ";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << v.ff << " " << v.ss;
return os;
}
const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;
int pow(int a, int b, int m) {
int ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
time_t t1, t2;
t1 = clock();
int n;
cin >> n;
int dp[100005][3];
int vals[n + 1][3];
for (int i = 1; i <= n; i++) {
int a, b, c;
cin >> a >> b >> c;
vals[i][0] = a;
vals[i][1] = b;
vals[i][2] = c;
}
dp[1][0] = vals[1][0];
dp[1][1] = vals[1][1];
dp[1][2] = vals[1][2];
for (int i = 2; i <= n; i++) {
for (int j = 0; j < 3; j++) {
if (j == 0) {
dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]);
} else if (j == 1) {
dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]);
} else {
dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]);
}
dp[i][j] += vals[i][j];
}
}
int maxi = max(dp[n][0], dp[n][1]);
maxi = max(maxi, dp[n][2]);
cout << maxi << endl;
t2 = clock();
cerr << endl << t2 - t1 << endl;
return 0;
}
| /*author : Yashvardhan
Saturday, January 12, 2019
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define pb push_back
#define make_pair mp
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pi>
#define ff first
#define ss second
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size(); ++i)
os << v[i] << " ";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
for (auto it : v)
os << it << " ";
return os;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, const pair<T, S> &v) {
os << v.ff << " " << v.ss;
return os;
}
const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;
int pow(int a, int b, int m) {
int ans = 1;
while (b) {
if (b & 1)
ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
time_t t1, t2;
t1 = clock();
int n;
cin >> n;
int dp[100005][3];
int vals[n + 1][3];
for (int i = 1; i <= n; i++) {
int a, b, c;
cin >> a >> b >> c;
vals[i][0] = a;
vals[i][1] = b;
vals[i][2] = c;
}
dp[1][0] = vals[1][0];
dp[1][1] = vals[1][1];
dp[1][2] = vals[1][2];
for (int i = 2; i <= n; i++) {
for (int j = 0; j < 3; j++) {
if (j == 0) {
dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]);
} else if (j == 1) {
dp[i][j] = max(dp[i - 1][0], dp[i - 1][2]);
} else {
dp[i][j] = max(dp[i - 1][0], dp[i - 1][1]);
}
dp[i][j] += vals[i][j];
}
}
int maxi = max(dp[n][0], dp[n][1]);
maxi = max(maxi, dp[n][2]);
cout << maxi << endl;
t2 = clock();
cerr << endl << t2 - t1 << endl;
return 0;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change"
] | 965,245 | 965,246 | u368039995 | cpp |
p03162 | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const long long INF = 1LL << 60;
//ๅ
ฅๅ
int N;
long long a[100010][3];
// dpใใผใใซ
long long dp[100010][3];
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (j == k) {
continue;
}
chmax(dp[i + 1][j], dp[i][j] + a[i][k]);
}
}
}
long long res = 0;
for (int i = 0; i < 3; i++) {
chmax(res, dp[N][i]);
}
cout << res << endl;
}
| #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const long long INF = 1LL << 60;
//ๅ
ฅๅ
int N;
long long a[100010][3];
// dpใใผใใซ
long long dp[100010][3];
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
cin >> a[i][j];
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (j == k) {
continue;
}
chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
}
}
}
long long res = 0;
for (int i = 0; i < 3; i++) {
chmax(res, dp[N][i]);
}
cout << res << endl;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"call.arguments.change"
] | 965,247 | 965,248 | u334656323 | cpp |
p03162 | #include <bits/stdc++.h>
using namespace std;
int dt[100001][3], n;
int main() {
scanf("%d", &n);
scanf("%d %d %d", &dt[1][0], &dt[1][1], &dt[1][2]);
for (int i = 2; i <= n; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
dt[i][0] = max(dt[i - 1][1], dt[i - 1][2]) + a;
dt[i][1] = max(dt[i - 1][0], dt[i - 1][2]) + b;
dt[i][2] = max(dt[i - 1][0], dt[i - 1][1]) + c;
}
printf("%d", max(max(dt[n][0], dt[n][0]), dt[n][0]));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int dt[100001][3], n;
int main() {
scanf("%d", &n);
scanf("%d %d %d", &dt[1][0], &dt[1][1], &dt[1][2]);
for (int i = 2; i <= n; i++) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
dt[i][0] = max(dt[i - 1][1], dt[i - 1][2]) + a;
dt[i][1] = max(dt[i - 1][0], dt[i - 1][2]) + b;
dt[i][2] = max(dt[i - 1][0], dt[i - 1][1]) + c;
}
printf("%d", max(max(dt[n][0], dt[n][1]), dt[n][2]));
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"io.output.change"
] | 965,249 | 965,250 | u426432817 | cpp |
p03162 | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); (b) <= i; i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1) * (a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1 << 29)
using namespace std;
#define ld long double
#define ll long long
map<int, int> mpa, mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
int a[100100][5] = {0};
for (int i = 1; i <= N; i++) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
ll dp[100100][5] = {0};
for (int i = 1; i <= 3; i++) {
dp[1][i] = a[1][i];
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= 2; j++) {
dp[i + 1][j] = max(dp[i][(j + 1) % 3] + a[i + 1][j],
dp[i][(j + 2) % 3] + a[i + 1][j]);
}
// cout << max({dp[i][0],dp[i][1],dp[i][2]}) << endl;
}
ll ans = max({dp[N][0], dp[N][1], dp[N][2]});
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); (b) <= i; i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1) * (a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1 << 29)
using namespace std;
#define ld long double
#define ll long long
map<int, int> mpa, mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
int a[100100][5] = {0};
for (int i = 1; i <= N; i++) {
cin >> a[i][0] >> a[i][1] >> a[i][2];
}
ll dp[100100][5] = {0};
for (int i = 0; i <= 2; i++) {
dp[1][i] = a[1][i];
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= 2; j++) {
dp[i + 1][j] = max(dp[i][(j + 1) % 3] + a[i + 1][j],
dp[i][(j + 2) % 3] + a[i + 1][j]);
}
// cout << max({dp[i][0],dp[i][1],dp[i][2]}) << endl;
}
ll ans = max({dp[N][0], dp[N][1], dp[N][2]});
cout << ans << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 965,253 | 965,254 | u789417951 | cpp |
p03162 | #include <algorithm>
#include <cmath>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld, ld>
#define ii pair<int, int>
#define si set<int>
#define vii vector<pair<int, int>>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vs vector<string>
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x, y) ((ll)(x) * (y)) % mod
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF = 9223372036854775807;
const ll mod = 998244353;
ll MOD(ll a, ll b) {
if (a > b)
return a - b;
else
return b - a;
}
ll max3(ll a, ll b, ll c) { return max(c, max(a, b)); }
ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = (res * x); //%mod;
y = y >> 1;
x = (x * x); //%mod;
}
return res; //%mod;
}
ll power1(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
ll logg(ll a) {
ll x = 0;
while (a > 1) {
x++;
a /= 2;
}
return x;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll abso(ll x) {
if (x < 0) {
return -x;
}
return x;
}
ll ceiling(ll a, ll b) {
if (a % b == 0) {
return a / b;
} else {
return a / b + 1;
}
}
ll modinv(ll x) { return power1(x, mod - 2); }
int main() {
int n;
cin >> n;
vector<vector<ll>> v(n);
for (int i = 0; i < n; i++) {
v[i].resize(3);
for (int j = 0; j < 3; j++) {
cin >> v[i][j];
}
}
vector<vector<ll>> dp(n);
for (int i = 0; i < n; i++) {
dp[i].resize(3, INF);
}
dp[0][0] = v[0][0];
dp[0][1] = v[0][1];
dp[0][2] = v[0][2];
for (int i = 1; i < n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (j != k) {
dp[i][j] = max(dp[i - 1][k] + v[i][j], dp[i][j]);
}
}
}
}
cout << max3(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]);
}
| #include <algorithm>
#include <cmath>
#include <complex>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld, ld>
#define ii pair<int, int>
#define si set<int>
#define vii vector<pair<int, int>>
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vs vector<string>
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x, y) ((ll)(x) * (y)) % mod
#define tr(c, i) for (auto i = (c).begin(); i != (c).end(); i++)
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF = 9223372036854775807;
const ll mod = 998244353;
ll MOD(ll a, ll b) {
if (a > b)
return a - b;
else
return b - a;
}
ll max3(ll a, ll b, ll c) { return max(c, max(a, b)); }
ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); }
ll power(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = (res * x); //%mod;
y = y >> 1;
x = (x * x); //%mod;
}
return res; //%mod;
}
ll power1(ll x, ll y) {
ll res = 1;
while (y > 0) {
if (y & 1)
res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res % mod;
}
ll logg(ll a) {
ll x = 0;
while (a > 1) {
x++;
a /= 2;
}
return x;
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
ll abso(ll x) {
if (x < 0) {
return -x;
}
return x;
}
ll ceiling(ll a, ll b) {
if (a % b == 0) {
return a / b;
} else {
return a / b + 1;
}
}
ll modinv(ll x) { return power1(x, mod - 2); }
int main() {
int n;
cin >> n;
vector<vector<ll>> v(n);
for (int i = 0; i < n; i++) {
v[i].resize(3);
for (int j = 0; j < 3; j++) {
cin >> v[i][j];
}
}
vector<vector<ll>> dp(n);
for (int i = 0; i < n; i++) {
dp[i].resize(3, 0);
}
dp[0][0] = v[0][0];
dp[0][1] = v[0][1];
dp[0][2] = v[0][2];
for (int i = 1; i < n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (j != k) {
dp[i][j] = max(dp[i - 1][k] + v[i][j], dp[i][j]);
}
}
}
}
cout << max3(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]);
}
| [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 965,260 | 965,261 | u920844524 | cpp |
p03162 | #include <iostream>
#include <limits>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a, b, c;
for (int i = 0; i < n; ++i) {
int aa, bb, cc;
cin >> aa >> bb >> cc;
a.emplace_back(aa);
b.emplace_back(bb);
c.emplace_back(cc);
}
vector<vector<int>> dp(3, vector<int>(n, numeric_limits<int>::max()));
dp[0].back() = a.back();
dp[1].back() = b.back();
dp[2].back() = c.back();
vector<int> *abc[3] = {&a, &b, &c};
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
if (k == j)
continue;
dp[j][i] = max(dp[j][i], (*abc[j])[i] + dp[k][i + 1]);
}
}
}
cout << max(dp[0][0], max(dp[1][0], dp[2][0])) << '\n';
}
| #include <iostream>
#include <limits>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a, b, c;
for (int i = 0; i < n; ++i) {
int aa, bb, cc;
cin >> aa >> bb >> cc;
a.emplace_back(aa);
b.emplace_back(bb);
c.emplace_back(cc);
}
vector<vector<int>> dp(3, vector<int>(n, numeric_limits<int>::min()));
dp[0].back() = a.back();
dp[1].back() = b.back();
dp[2].back() = c.back();
vector<int> *abc[3] = {&a, &b, &c};
for (int i = n - 1; i >= 0; --i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
if (k == j)
continue;
dp[j][i] = max(dp[j][i], (*abc[j])[i] + dp[k][i + 1]);
}
}
}
cout << max(dp[0][0], max(dp[1][0], dp[2][0])) << '\n';
}
| [
"misc.opposites",
"identifier.change",
"call.arguments.change"
] | 965,262 | 965,263 | u403618885 | cpp |
p03162 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int dp[N][4];
int arr[N][3];
int n;
int solve(int idx, int prev) {
if (idx == n)
return 0;
int &ans = dp[idx][prev];
if (ans != -1)
return ans;
ans = 0;
for (int i = 0; i < 3; i++) {
if (i + 1 != prev)
ans = max(ans, solve(idx + 1, i + 1) + arr[idx][i]);
}
return ans;
}
int main() {
cin >> n;
for (int i = 0; i < 3; i++)
for (int j = 0; j < n; j++)
cin >> arr[j][i];
memset(dp, -1, sizeof(dp));
cout << solve(0, 0);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
int dp[N][4];
int arr[N][3];
int n;
int solve(int idx, int prev) {
if (idx == n)
return 0;
int &ans = dp[idx][prev];
if (ans != -1)
return ans;
ans = 0;
for (int i = 0; i < 3; i++) {
if (i + 1 != prev)
ans = max(ans, solve(idx + 1, i + 1) + arr[idx][i]);
}
return ans;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < 3; j++)
cin >> arr[i][j];
memset(dp, -1, sizeof(dp));
cout << solve(0, 0);
return 0;
} | [
"identifier.replace.add",
"literal.replace.remove",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change",
"identifier.replace.remove",
"literal.replace.add",
"identifier.change",
"variable_access.subscript.index.change"
] | 965,264 | 965,265 | u173976156 | cpp |
p03162 | #include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define __ \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pi acos(-1)
#define ll long long int
#define f0(n) for (int i = 0; i < n; i++)
#define mem(a) memset(a, 0, sizeof(a))
#define mems(a) memset(a, -1, sizeof(a))
ll dp[5][111111], a, b, c;
int main() {
/* #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
__
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
dp[0][i + 1] = max(dp[1][i], dp[2][i]) + a;
dp[1][i + 1] = max(dp[0][i], dp[2][i]) + b;
dp[2][i + 1] = max(dp[1][i], dp[2][i]) + c;
}
cout << max(dp[0][n], max(dp[1][n], dp[2][n]));
return 0;
}
| #include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define __ \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define pi acos(-1)
#define ll long long int
#define f0(n) for (int i = 0; i < n; i++)
#define mem(a) memset(a, 0, sizeof(a))
#define mems(a) memset(a, -1, sizeof(a))
ll dp[5][111111], a, b, c;
int main() {
/* #ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
__
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b >> c;
dp[0][i + 1] = max(dp[1][i], dp[2][i]) + a;
dp[1][i + 1] = max(dp[0][i], dp[2][i]) + b;
dp[2][i + 1] = max(dp[1][i], dp[0][i]) + c;
}
cout << max(dp[0][n], max(dp[1][n], dp[2][n]));
return 0;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,270 | 965,271 | u404706753 | cpp |
p03162 | #include <bits/stdc++.h>
using namespace std;
#define MX_N 100000
#define MX 1000000000
int n, k;
int tab[MX_N + 5][5];
long long dp[MX_N + 5][3];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> tab[i][0] >> tab[i][1] >> tab[i][2];
dp[0][0] = tab[0][0];
dp[0][1] = tab[0][2];
dp[0][2] = tab[0][2];
for (int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + tab[i][0];
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + tab[i][1];
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + tab[i][2];
}
cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#define MX_N 100000
#define MX 1000000000
int n;
int tab[MX_N + 5][5];
long long dp[MX_N + 5][3];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> tab[i][0] >> tab[i][1] >> tab[i][2];
dp[0][0] = tab[0][0];
dp[0][1] = tab[0][1];
dp[0][2] = tab[0][2];
for (int i = 1; i < n; i++) {
dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + tab[i][0];
dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + tab[i][1];
dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + tab[i][2];
}
cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << "\n";
}
| [
"variable_declaration.remove",
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change"
] | 965,275 | 965,276 | u718303016 | cpp |
p03162 | /*author:anshumanc007
created on:05/01/2019
*/
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
#define first fi
#define second se
typedef pair<long long int, long long int> pa;
#define MAX 100005
long long int MOD = 1e9 + 7;
long long int INF = 1e18;
long long int dp[MAX][3];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int i, j, k, l, m, n, o, p, q, r, x, y, a, b, mini = INF, maxi = 0,
cnt = 0;
cin >> n >> k;
long long int A[n + 1][3];
for (i = 0; i < n; i++) {
cin >> A[i][0];
cin >> A[i][1];
cin >> A[i][2];
}
for (i = 0; i <= n; i++) {
dp[i][0] = 0;
dp[i][1] = 0;
dp[i][2] = 0;
}
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = 0;
for (i = 1; i <= n; i++) {
dp[i][0] = max(dp[i - 1][1] + A[i - 1][0], dp[i - 1][2] + A[i - 1][0]);
dp[i][1] = max(dp[i - 1][2] + A[i - 1][1], dp[i - 1][0] + A[i - 1][1]);
dp[i][2] = max(dp[i - 1][0] + A[i - 1][2], dp[i - 1][1] + A[i - 1][2]);
}
cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
} | /*author:anshumanc007
created on:05/01/2019
*/
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;
#define first fi
#define second se
typedef pair<long long int, long long int> pa;
#define MAX 100005
long long int MOD = 1e9 + 7;
long long int INF = 1e18;
long long int dp[MAX][3];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int i, j, k, l, m, n, o, p, q, r, x, y, a, b, mini = INF, maxi = 0,
cnt = 0;
cin >> n;
long long int A[n + 1][3];
for (i = 0; i < n; i++) {
cin >> A[i][0];
cin >> A[i][1];
cin >> A[i][2];
}
for (i = 0; i <= n; i++) {
dp[i][0] = 0;
dp[i][1] = 0;
dp[i][2] = 0;
}
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = 0;
for (i = 1; i <= n; i++) {
dp[i][0] = max(dp[i - 1][1] + A[i - 1][0], dp[i - 1][2] + A[i - 1][0]);
dp[i][1] = max(dp[i - 1][2] + A[i - 1][1], dp[i - 1][0] + A[i - 1][1]);
dp[i][2] = max(dp[i - 1][0] + A[i - 1][2], dp[i - 1][1] + A[i - 1][2]);
}
cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
} | [
"expression.operation.binary.remove"
] | 965,281 | 965,282 | u422347032 | cpp |
p03162 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
int N;
cin >> N;
V<ll> a(N), b(N), c(N);
REP(i, N) cin >> a[i] >> b[i] >> c[i];
V<V<ll>> dp(N, V<ll>(3, 0));
dp[0][0] = a[0];
dp[0][0] = b[0];
dp[0][0] = c[0];
FOR(i, 1, N) {
dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + b[i]);
dp[i][1] = max(dp[i - 1][2] + b[i], dp[i - 1][0] + c[i]);
dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + a[i]);
}
cout << *max_element(ALL(dp[N - 1])) << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
int N;
cin >> N;
V<ll> a(N), b(N), c(N);
REP(i, N) cin >> a[i] >> b[i] >> c[i];
V<V<ll>> dp(N, V<ll>(3, 0));
dp[0][0] = a[0];
dp[0][1] = b[0];
dp[0][2] = c[0];
FOR(i, 1, N) {
dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
dp[i][1] = max(dp[i - 1][2] + b[i], dp[i - 1][0] + b[i]);
dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
}
cout << *max_element(ALL(dp[N - 1])) << endl;
return 0;
}
| [
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,283 | 965,284 | u898651494 | cpp |
p03162 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
int N;
cin >> N;
V<ll> a(N), b(N), c(N);
REP(i, N) cin >> a[i] >> b[i] >> c[i];
V<V<ll>> dp(N, V<ll>(3, 0));
dp[0][0] = a[0];
dp[0][0] = b[0];
dp[0][0] = c[0];
FOR(i, 1, N) {
dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + b[i]);
dp[i][1] = max(dp[i - 1][2] + b[i], dp[i - 1][0] + c[i]);
dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + a[i]);
}
cout << *max_element(ALL(dp[N - 1])) << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
int N;
cin >> N;
V<ll> a(N), b(N), c(N);
REP(i, N) cin >> a[i] >> b[i] >> c[i];
V<V<ll>> dp(N, V<ll>(3, 0));
dp[0][0] = a[0];
dp[0][1] = b[0];
dp[0][2] = c[0];
FOR(i, 1, N) {
dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
dp[i][1] = max(dp[i - 1][2] + b[i], dp[i - 1][0] + b[i]);
dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
}
cout << *max_element(ALL(dp[N - 1])) << endl;
return 0;
} | [
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,283 | 965,285 | u898651494 | cpp |
p03162 | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 1000000000;
int main() {
int N;
cin >> N;
vector<int> a(N), b(N), c(N);
for (int i = 0; i < N; i++) {
cin >> a[i] >> b[i] >> c[i];
}
vector<vector<int>> dp(N, vector<int>(3, 0));
for (int i = 0; i < N; i++) {
dp[i + 1][0] = a[i] + max(dp[i][1], dp[i][2]);
dp[i + 1][1] = b[i] + max(dp[i][0], dp[i][2]);
dp[i + 1][2] = c[i] + max(dp[i][0], dp[i][1]);
}
cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long LL;
typedef pair<LL, LL> P;
const LL mod = 1e9 + 7;
const LL LINF = 1LL << 62;
const int INF = 1000000000;
int main() {
int N;
cin >> N;
vector<int> a(N), b(N), c(N);
for (int i = 0; i < N; i++) {
cin >> a[i] >> b[i] >> c[i];
}
vector<vector<int>> dp(N + 1, vector<int>(3, 0));
for (int i = 0; i < N; i++) {
dp[i + 1][0] = a[i] + max(dp[i][1], dp[i][2]);
dp[i + 1][1] = b[i] + max(dp[i][0], dp[i][2]);
dp[i + 1][2] = c[i] + max(dp[i][0], dp[i][1]);
}
cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
return 0;
}
| [
"assignment.change"
] | 965,286 | 965,287 | u640323045 | cpp |
p03162 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const mod = 1000000007;
ll const md = 998244353;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ifstream in("txt.in");
ofstream out("txt.out");
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int f[100005][5];
int dp[100005][5];
int main() {
cout << fixed << setprecision(12);
cin.tie(0);
ios_base::sync_with_stdio(0);
cout.tie(0);
ll n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
cin >> f[i][j];
}
}
dp[1][1] = f[1][1];
dp[2][1] = f[1][2];
dp[3][1] = f[1][3];
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
if (j == 1)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][3]) + f[i][j];
if (j == 2)
dp[i][j] = max(dp[i - 1][1], dp[i - 1][3]) + f[i][j];
if (j == 3)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][1]) + f[i][j];
}
}
cout << max({dp[n][1], dp[n][2], dp[n][3]});
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const mod = 1000000007;
ll const md = 998244353;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ifstream in("txt.in");
ofstream out("txt.out");
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int f[100005][5];
int dp[100005][5];
int main() {
cout << fixed << setprecision(12);
cin.tie(0);
ios_base::sync_with_stdio(0);
cout.tie(0);
ll n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
cin >> f[i][j];
}
}
dp[1][1] = f[1][1];
dp[1][2] = f[1][2];
dp[1][3] = f[1][3];
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
if (j == 1)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][3]) + f[i][j];
if (j == 2)
dp[i][j] = max(dp[i - 1][1], dp[i - 1][3]) + f[i][j];
if (j == 3)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][1]) + f[i][j];
}
}
cout << max({dp[n][1], dp[n][2], dp[n][3]});
return 0;
}
| [
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change"
] | 965,290 | 965,291 | u635511681 | cpp |
p03162 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const mod = 1000000007;
ll const md = 998244353;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ifstream in("txt.in");
ofstream out("txt.out");
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int f[100005][5];
int dp[5][100005];
int main() {
cout << fixed << setprecision(12);
cin.tie(0);
ios_base::sync_with_stdio(0);
cout.tie(0);
ll n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
cin >> f[i][j];
}
}
dp[1][1] = f[1][1];
dp[1][2] = f[1][2];
dp[1][3] = f[1][3];
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
if (j == 1)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][3]) + f[i][j];
if (j == 2)
dp[i][j] = max(dp[i - 1][1], dp[i - 1][3]) + f[i][j];
if (j == 3)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][1]) + f[i][j];
}
}
cout << max({dp[n][1], dp[n][2], dp[n][3]});
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll const mod = 1000000007;
ll const md = 998244353;
ll powmod(ll a, ll b) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
ifstream in("txt.in");
ofstream out("txt.out");
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int f[100005][5];
int dp[100005][5];
int main() {
cout << fixed << setprecision(12);
cin.tie(0);
ios_base::sync_with_stdio(0);
cout.tie(0);
ll n;
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
cin >> f[i][j];
}
}
dp[1][1] = f[1][1];
dp[1][2] = f[1][2];
dp[1][3] = f[1][3];
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= 3; ++j) {
if (j == 1)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][3]) + f[i][j];
if (j == 2)
dp[i][j] = max(dp[i - 1][1], dp[i - 1][3]) + f[i][j];
if (j == 3)
dp[i][j] = max(dp[i - 1][2], dp[i - 1][1]) + f[i][j];
}
}
cout << max({dp[n][1], dp[n][2], dp[n][3]});
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 965,292 | 965,291 | u635511681 | cpp |
p03162 | #include <iostream>
using namespace std;
int A[100009] = {};
int B[100009] = {};
int C[100009] = {};
int main() {
int N;
cin >> N;
for (int in = 1; in <= N; in++) {
cin >> A[in] >> B[in] >> C[in];
}
int dp[100009][3];
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = 0;
for (int day = 1; day <= N; day++) {
dp[day][0] = max(dp[day - 1][0], dp[day - 1][1]) + A[day];
dp[day][1] = max(dp[day - 1][0], dp[day - 1][2]) + B[day];
dp[day][2] = max(dp[day - 1][1], dp[day - 1][0]) + C[day];
}
int ans = max(dp[N][0], dp[N][1]);
ans = max(ans, dp[N][2]);
cout << ans << endl;
return 0;
}
| #include <iostream>
using namespace std;
int A[100009] = {};
int B[100009] = {};
int C[100009] = {};
int main() {
int N;
cin >> N;
for (int in = 1; in <= N; in++) {
cin >> A[in] >> B[in] >> C[in];
}
int dp[100009][3];
dp[0][0] = 0;
dp[0][1] = 0;
dp[0][2] = 0;
for (int day = 1; day <= N; day++) {
dp[day][0] = max(dp[day - 1][2], dp[day - 1][1]) + A[day];
dp[day][1] = max(dp[day - 1][0], dp[day - 1][2]) + B[day];
dp[day][2] = max(dp[day - 1][1], dp[day - 1][0]) + C[day];
}
int ans = max(dp[N][0], dp[N][1]);
ans = max(ans, dp[N][2]);
cout << ans << endl;
return 0;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 965,296 | 965,297 | u617525345 | cpp |
p03163 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl "\n"
#define ll long long
#define pb emplace_back
#define fi first
#define se second
#define pll pair<ll, ll>
#define ull unsigned long long
#define ld long double
#define debug(x) cout << #x << " :: " << x << endl;
#define debug2(x, y) \
cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define debug3(x, y, z) \
cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z \
<< " :: " << z << endl;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repa(i, a, b) for (ll i = (a); i <= (b); i++)
#define all(x) (x).begin(), (x).end()
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
/*
Ordered set docs:
order_of_key (k) : Number of items strictly smaller than k .
find_by_order(k) : K-th element in a set (counting from zero).
*/
#define blc boost::lexical_cast<long long>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
ll add(ll x, ll y) {
ll res = x + y;
return (res >= MOD ? res - MOD : res);
}
ll sub(ll x, ll y) {
ll res = x - y;
return (res < 0 ? res + MOD : res);
}
ll lcm(ll x, ll y) {
ll res = (x * y) / __gcd(x, y);
return res;
}
ll powerLL(ll x, ll n, ll mod) {
ll result = 1;
while (n) {
if (n & 1)
result = (result % mod * x % mod) % mod;
n = n / 2;
x = (x % mod * x % mod) % mod;
}
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int fun(vector<int> &A, vector<int> &B, int C) {
int n = A.size();
int w = C;
int dp[n + 1][w + 1];
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 (B[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], A[i - 1] + dp[i - 1][j - B[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][w];
}
void solve() {
int n, w;
cin >> n >> w;
vector<int> wei(n);
vector<int> val(n);
rep(i, n) cin >> wei[i] >> val[i];
// s+=val[i];
cout << fun(val, wei, w) << endl;
}
int32_t main() {
fast;
int t;
t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl "\n"
#define int ll
#define ll long long
#define pb emplace_back
#define fi first
#define se second
#define pll pair<ll, ll>
#define ull unsigned long long
#define ld long double
#define debug(x) cout << #x << " :: " << x << endl;
#define debug2(x, y) \
cout << #x << " :: " << x << "\t" << #y << " :: " << y << endl;
#define debug3(x, y, z) \
cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z \
<< " :: " << z << endl;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define repa(i, a, b) for (ll i = (a); i <= (b); i++)
#define all(x) (x).begin(), (x).end()
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
/*
Ordered set docs:
order_of_key (k) : Number of items strictly smaller than k .
find_by_order(k) : K-th element in a set (counting from zero).
*/
#define blc boost::lexical_cast<long long>
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
const int MOD = 1e9 + 7;
ll add(ll x, ll y) {
ll res = x + y;
return (res >= MOD ? res - MOD : res);
}
ll sub(ll x, ll y) {
ll res = x - y;
return (res < 0 ? res + MOD : res);
}
ll lcm(ll x, ll y) {
ll res = (x * y) / __gcd(x, y);
return res;
}
ll powerLL(ll x, ll n, ll mod) {
ll result = 1;
while (n) {
if (n & 1)
result = (result % mod * x % mod) % mod;
n = n / 2;
x = (x % mod * x % mod) % mod;
}
return result;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int fun(vector<int> &A, vector<int> &B, int C) {
int n = A.size();
int w = C;
int dp[n + 1][w + 1];
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 (B[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], A[i - 1] + dp[i - 1][j - B[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
return dp[n][w];
}
void solve() {
int n, w;
cin >> n >> w;
vector<int> wei(n);
vector<int> val(n);
rep(i, n) cin >> wei[i] >> val[i];
// s+=val[i];
cout << fun(val, wei, w) << endl;
}
int32_t main() {
fast;
int t;
t = 1;
// cin>>t;
while (t--)
solve();
return 0;
} | [] | 965,302 | 965,303 | u298511956 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, w, sol = 0;
int weight[101];
int value[101];
int dp[101][100005];
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> weight[i];
cin >> value[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= weight[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]);
}
}
}
cout << dp[n][w] << endl;
}
| #include <bits/stdc++.h>
#define ll long long
using namespace std;
int n, w, sol = 0;
int weight[101];
int value[101];
ll dp[101][100005];
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> weight[i];
cin >> value[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= weight[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - weight[i]] + value[i]);
}
}
}
cout << dp[n][w] << endl;
}
| [
"variable_declaration.type.change"
] | 965,306 | 965,307 | u787597250 | cpp |
p03163 | //
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>
//
using ll = long long;
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template <typename Type> inline void chmin(Type &a, Type b) {
if (a > b)
a = b;
}
template <typename Type> inline void chmax(Type &a, Type b) {
if (a < b)
a = b;
}
template <typename Type> inline void sort(Type &arr) {
std::sort(arr.begin(), arr.end());
}
template <typename Type> inline Type nth(vector<Type> &arr, size_t pos) {
std::nth_element(arr.begin(), arr.begin() + pos, arr.end());
return arr[pos];
}
#define BIGP 1000000007
#define INF_I std::numeric_limits<ll>::max()
#define INF_F std::numeric_limits<float>::infinity()
//
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
//
ll N, W;
cin >> N >> W;
vector<pair<ll, ll>> ps;
rep(i, N) {
ll w, v;
cin >> w >> v;
ps.push_back({w, v});
}
vector<vector<ll>> dp;
dp.resize(N + 1);
rep(i, N + 1) { dp[i].resize(10001000, 0); }
for (ll item = 0; item < N; ++item) {
auto p = ps[item];
ll w = std::get<0>(p);
ll v = std::get<1>(p);
for (ll wi = 0; wi <= W; ++wi) {
chmax(dp[item + 1][wi], dp[item][wi]);
if (wi + w <= W) {
chmax(dp[item + 1][wi + w], dp[item][wi] + v);
}
}
}
ll h = dp[N][W];
cout << h;
//
return 0;
} | //
#include <algorithm>
#include <array>
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <set>
#include <vector>
//
using ll = long long;
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template <typename Type> inline void chmin(Type &a, Type b) {
if (a > b)
a = b;
}
template <typename Type> inline void chmax(Type &a, Type b) {
if (a < b)
a = b;
}
template <typename Type> inline void sort(Type &arr) {
std::sort(arr.begin(), arr.end());
}
template <typename Type> inline Type nth(vector<Type> &arr, size_t pos) {
std::nth_element(arr.begin(), arr.begin() + pos, arr.end());
return arr[pos];
}
#define BIGP 1000000007
#define INF_I std::numeric_limits<ll>::max()
#define INF_F std::numeric_limits<float>::infinity()
//
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
//
ll N, W;
cin >> N >> W;
vector<pair<ll, ll>> ps;
rep(i, N) {
ll w, v;
cin >> w >> v;
ps.push_back({w, v});
}
vector<vector<ll>> dp;
dp.resize(N + 1);
rep(i, N + 1) { dp[i].resize(100100, 0); }
for (ll item = 0; item < N; ++item) {
auto p = ps[item];
ll w = std::get<0>(p);
ll v = std::get<1>(p);
for (ll wi = 0; wi <= W; ++wi) {
chmax(dp[item + 1][wi], dp[item][wi]);
if (wi + w <= W) {
chmax(dp[item + 1][wi + w], dp[item][wi] + v);
}
}
}
ll h = dp[N][W];
cout << h;
//
return 0;
} | [
"literal.number.change",
"call.arguments.change"
] | 965,308 | 965,309 | u337949146 | cpp |
p03163 | #include <bits/stdc++.h>
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 (w[i - 1] <= j) {
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] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, W;
cin >> n >> W;
long long int v[n], w[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
long long 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], dp[i - 1][j - w[i - 1]] + v[i - 1]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][W] << endl;
} | [
"variable_declaration.type.widen.change"
] | 965,313 | 965,314 | u466076667 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
int i, j;
cin >> N >> W;
vector<int> w(N);
vector<int> v(N);
vector<vector<int>> dp(N + 1, vector<int>(W + 1, 0));
for (i = 0; i < N; i++)
cin >> w[i] >> v[i];
for (i = 0; i < N; i++)
for (j = 0; j <= W; j++) {
if (j >= w[i])
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 <bits/stdc++.h>
using namespace std;
int main() {
int N, W;
int i, j;
cin >> N >> W;
vector<long> w(N);
vector<long> v(N);
vector<vector<long>> dp(N + 1, vector<long>(W + 1, 0));
for (i = 0; i < N; i++)
cin >> w[i] >> v[i];
for (i = 0; i < N; i++)
for (j = 0; j <= W; j++) {
if (j >= w[i])
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;
}
| [
"variable_declaration.type.primitive.change"
] | 965,318 | 965,319 | u900753971 | cpp |
p03163 | /*
Educational DP Contest - D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST_INP \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
typedef long long ll;
int main() {
FAST_INP;
ll n, W, w, v;
cin >> n >> W;
ll dp[W];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> w >> v;
for (int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << dp[W] << endl;
return 0;
}
| /*
Educational DP Contest - D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST_INP \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
typedef long long ll;
int main() {
FAST_INP;
ll n, W, w, v;
cin >> n >> W;
ll dp[W + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> w >> v;
for (int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << dp[W] << endl;
return 0;
}
| [
"variable_declaration.array_dimensions.change",
"expression.operation.binary.add"
] | 965,322 | 965,323 | u040094338 | cpp |
p03163 | /*
Educational DP Contest - D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST_INP \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
typedef long long ll;
int main() {
FAST_INP;
ll n, W, w, v;
cin >> n >> W;
ll dp[W];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> w >> v;
for (int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << dp[W] << endl;
return 0;
}
| /*
Educational DP Contest - D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d
*/
#include <bits/stdc++.h>
using namespace std;
#define FAST_INP \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
typedef long long ll;
int main() {
FAST_INP;
ll n, W, w, v;
cin >> n >> W;
ll dp[100005];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> w >> v;
for (int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << dp[W] << endl;
return 0;
}
| [
"identifier.replace.remove",
"literal.replace.add",
"variable_declaration.array_dimensions.change"
] | 965,322 | 965,324 | u040094338 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forr(i, n) for (ll i = 0; i < n; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout << ele << ' '
#define cs(ele) cout << ele << '\n'
#define CASE(t) \
ll t; \
cin >> t; \
while (t--)
#define sor(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
ll power(ll a, ll b) {
ll r = 1;
while (b--)
r *= a;
return r;
}
int solve(vector<vector<int>> v, int n, vector<vector<int>> dp) {
for (int i = 1; i <= n; i++) {
dp[i][0] = max(dp[i - 1][1] + v[i - 1][0], dp[i - 1][2] + v[i - 1][0]);
dp[i][1] = max(dp[i - 1][0] + v[i - 1][1], dp[i - 1][2] + v[i - 1][1]);
dp[i][2] = max(dp[i - 1][1] + v[i - 1][2], dp[i - 1][0] + v[i - 1][2]);
}
return max(dp[n][0], max(dp[n][1], dp[n][2]));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
vector<vector<int>> dp(n + 1, vector<int>(W + 1, 0));
f(i, 0, n) cin >> w[i] >> v[i];
f(i, 1, n + 1) {
f(j, 1, W + 1) {
if (w[i - 1] <= j) {
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];
}
}
int mx = 0;
for (int i = 1; i <= n; i++)
mx = max(mx, dp[i][W]);
cs(mx);
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forr(i, n) for (ll i = 0; i < n; i++)
#define f(i, a, b) for (ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define endl '\n'
#define ce(ele) cout << ele << ' '
#define cs(ele) cout << ele << '\n'
#define CASE(t) \
ll t; \
cin >> t; \
while (t--)
#define sor(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
ll power(ll a, ll b) {
ll r = 1;
while (b--)
r *= a;
return r;
}
int solve(vector<vector<int>> v, int n, vector<vector<int>> dp) {
for (int i = 1; i <= n; i++) {
dp[i][0] = max(dp[i - 1][1] + v[i - 1][0], dp[i - 1][2] + v[i - 1][0]);
dp[i][1] = max(dp[i - 1][0] + v[i - 1][1], dp[i - 1][2] + v[i - 1][1]);
dp[i][2] = max(dp[i - 1][1] + v[i - 1][2], dp[i - 1][0] + v[i - 1][2]);
}
return max(dp[n][0], max(dp[n][1], dp[n][2]));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, W;
cin >> n >> W;
vector<ll> w(n), v(n);
vector<vector<ll>> dp(n + 1, vector<ll>(W + 1, 0));
f(i, 0, n) cin >> w[i] >> v[i];
f(i, 1, n + 1) {
f(j, 1, W + 1) {
if (w[i - 1] <= j) {
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 mx = 0;
for (ll i = 1; i <= n; i++)
mx = max(mx, dp[i][W]);
cs(mx);
}
| [
"variable_declaration.type.change",
"call.arguments.change",
"control_flow.loop.for.initializer.change"
] | 965,330 | 965,331 | u987274574 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
vector<int> w(n), v(n), t(wt + 1, 0);
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
vector<vector<int>> val(n + 1, t);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= wt; j++) {
val[i][j] = val[i - 1][j];
if (w[i - 1] <= j) {
val[i][j] = max(val[i][j], val[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
}
cout << val[n][wt] << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
ll n, wt;
cin >> n >> wt;
vector<ll> w(n), v(n), t(wt + 1, 0);
for (ll i = 0; i < n; i++)
cin >> w[i] >> v[i];
vector<vector<ll>> val(n + 1, t);
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= wt; j++) {
val[i][j] = val[i - 1][j];
if (w[i - 1] <= j) {
val[i][j] = max(val[i][j], val[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
}
cout << val[n][wt] << "\n";
return 0;
}
| [
"variable_declaration.type.change",
"control_flow.loop.for.initializer.change"
] | 965,332 | 965,333 | u987274574 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<int> dp(w + 1, 0);
for (int i = 0; i < n; i++) {
int weight, value;
cin >> weight >> value;
for (int j = w - weight; j >= 0; j--) {
dp[j + weight] = max(dp[j + weight], dp[j] + value);
}
}
int mx = 0;
for (int i = 0; i <= w; i++)
mx = max(mx, dp[i]);
cout << mx << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<ll> dp(w + 1, 0);
for (int i = 0; i < n; i++) {
int weight, value;
cin >> weight >> value;
for (int j = w - weight; j >= 0; j--) {
dp[j + weight] = max(dp[j + weight], dp[j] + value);
}
}
ll mx = 0;
for (int i = 0; i <= w; i++)
mx = max(mx, dp[i]);
cout << mx << "\n";
return 0;
}
| [
"variable_declaration.type.change"
] | 965,334 | 965,335 | u987274574 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <vector>
#define INF 1e9
using namespace std;
struct item {
int wt;
int val;
};
// Bottom Up Approach
long long int knapsackBottomUp(vector<item> arr, int n, int W) {
int dp[n + 1][W + 1]; // Memory
// Base Case
for (int w = 0; w <= W; w++)
dp[1][w] = 0;
dp[1][arr[1].wt] = arr[1].val;
// Iteratively Calculating Other Cases In Bottom Up Fashion
for (int i = 2; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (arr[i].wt > w)
continue;
dp[i][w] = max(dp[i][w], (arr[i].val + dp[i - 1][w - arr[i].wt]));
}
}
return *max_element(dp[n], (dp[n] + W + 1));
}
int main() {
int n, w;
cin >> n >> w;
vector<item> arr(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i].wt >> arr[i].val;
cout << knapsackBottomUp(arr, n, w) << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
#define INF 1e9
using namespace std;
struct item {
int wt;
int val;
};
// Bottom Up Approach
long long int knapsackBottomUp(vector<item> arr, int n, int W) {
long long int dp[n + 1][W + 1]; // Memory
// Base Case
for (int w = 0; w <= W; w++)
dp[1][w] = 0;
dp[1][arr[1].wt] = arr[1].val;
// Iteratively Calculating Other Cases In Bottom Up Fashion
for (int i = 2; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (arr[i].wt > w)
continue;
dp[i][w] = max(dp[i][w], (arr[i].val + dp[i - 1][w - arr[i].wt]));
}
}
return *max_element(dp[n], (dp[n] + W + 1));
}
int main() {
int n, w;
cin >> n >> w;
vector<item> arr(n + 1);
for (int i = 1; i <= n; i++)
cin >> arr[i].wt >> arr[i].val;
cout << knapsackBottomUp(arr, n, w) << endl;
return 0;
} | [
"variable_declaration.type.widen.change"
] | 965,346 | 965,347 | u148301183 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n;
int w;
cin >> n >> w;
int arr[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> arr[i][j];
}
}
long long int dp[n + 1][w + 1];
// dp1[0]=max(dp[0][0],max(dp[0][1],dp[0][2]));
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 (arr[i][0] <= j) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - arr[i - 1][0]] + arr[i - 1][1]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
// cout<<dp[j]<<" ";
}
cout << dp[n][w];
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n;
int w;
cin >> n >> w;
int arr[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
cin >> arr[i][j];
}
}
long long int dp[n + 1][w + 1];
// dp1[0]=max(dp[0][0],max(dp[0][1],dp[0][2]));
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 (arr[i - 1][0] <= j) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - arr[i - 1][0]] + arr[i - 1][1]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
// cout<<dp[j]<<" ";
}
cout << dp[n][w];
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 965,348 | 965,349 | u859645287 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <queue>
#include <stack>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(x, y) for (ll i = x; i <= y; i++)
#define repi(x, y) for (ll i = x; i >= y; i--)
priority_queue<ll> cancel;
ll weight[200005];
ll value[200005];
int main() {
ll test = 1;
// cin>>test;
for (ll z = 0; z < test; z++) {
ll n, W;
cin >> n >> W;
ll dp[n][W];
for (ll i = 1; i <= n; i++) {
cin >> weight[i];
cin >> value[i];
}
for (ll i = 0; i <= n; i++) {
dp[0][i] = 0;
}
for (ll i = 1; i <= W; i++) {
dp[i][0] = 0;
}
for (ll i = 0; i <= W; i++) {
for (ll j = 1; j <= n; j++) {
if (weight[j] > i) {
dp[i][j] = dp[i][j - 1];
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - weight[j]][j - 1] + value[j]);
}
}
}
cout << dp[W][n] << endl;
}
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <queue>
#include <stack>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(x, y) for (ll i = x; i <= y; i++)
#define repi(x, y) for (ll i = x; i >= y; i--)
priority_queue<ll> cancel;
ll weight[200005];
ll value[200005];
int main() {
ll test = 1;
// cin>>test;
for (ll z = 0; z < test; z++) {
ll n, W;
cin >> n >> W;
ll dp[W + 5][n + 5];
for (ll i = 1; i <= n; i++) {
cin >> weight[i];
cin >> value[i];
}
for (ll i = 0; i <= n; i++) {
dp[0][i] = 0;
}
for (ll i = 1; i <= W; i++) {
dp[i][0] = 0;
}
for (ll i = 0; i <= W; i++) {
for (ll j = 1; j <= n; j++) {
if (weight[j] > i) {
dp[i][j] = dp[i][j - 1];
} else {
dp[i][j] = max(dp[i][j - 1], dp[i - weight[j]][j - 1] + value[j]);
}
}
}
cout << dp[W][n] << endl;
}
} | [
"variable_declaration.array_dimensions.change",
"expression.operation.binary.add"
] | 965,350 | 965,351 | u320525899 | cpp |
p03163 | // Knapsack
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define req(i, a, b) for (int i = (int)b - 1; i >= a; i--)
#define all(a) (a).begin(), (a).end()
#define ret(x) \
{ \
cout << x << endl; \
return; \
}
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
#ifdef LOCAL
#define wa(x) cerr << (#x) << " --- " << (x) << endl
#define pvi(v) \
{ \
for (auto it : v) \
cerr << it << "\t"; \
cerr << endl; \
}
#define line1 cerr << "---------------------------" << endl;
#else
#define wa //
#define line1 //
#define pvi //
#define printf //
#endif
void solve();
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--) {
solve();
line1;
}
printf("Time : %fms\n", (1000 * (double)clock()) / CLOCKS_PER_SEC);
return 0;
}
//___________________________________________________________________________________________________
void solve() {
int n, wt;
cin >> n >> wt;
vi v(n);
vi w(n);
rep(i, 0, n) cin >> w[i] >> v[i];
// dp[i][j] :
// Max value that can be obtained after considering
// the first i points with combined weight at max j.
vector<vi> dp(n + 1, vi(wt + 1, 0));
// pvi(w);
// pvi(v);
rep(i, 0, n + 1) {
req(j, 0, wt + 1) {
// Ignore the current element.
if (i > 0)
dp[i][j] = max(dp[i - 1][j], dp[i][j]);
// Consider the current element.
if (i > 0 && j >= w[i - 1])
dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i][j]);
}
}
// for(auto v:dp) pvi(v);
ret(dp[n][wt]);
}
| // Knapsack
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define req(i, a, b) for (int i = (int)b - 1; i >= a; i--)
#define all(a) (a).begin(), (a).end()
#define ret(x) \
{ \
cout << x << endl; \
return; \
}
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
#ifdef LOCAL
#define wa(x) cerr << (#x) << " --- " << (x) << endl
#define pvi(v) \
{ \
for (auto it : v) \
cerr << it << "\t"; \
cerr << endl; \
}
#define line1 cerr << "---------------------------" << endl;
#else
#define wa //
#define line1 //
#define pvi //
#define printf //
#endif
void solve();
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--) {
solve();
line1;
}
printf("Time : %fms\n", (1000 * (double)clock()) / CLOCKS_PER_SEC);
return 0;
}
//___________________________________________________________________________________________________
void solve() {
int n, wt;
cin >> n >> wt;
vi v(n);
vi w(n);
rep(i, 0, n) cin >> w[i] >> v[i];
// dp[i][j] :
// Max value that can be obtained after considering
// the first i points with combined weight at max j.
vector<vi> dp(n + 1, vi(wt + 1, 0));
// pvi(w);
// pvi(v);
rep(i, 0, n + 1) {
req(j, 0, wt + 1) {
// Ignore the current element.
if (i > 0)
dp[i][j] = max(dp[i - 1][j], dp[i][j]);
// Consider the current element.
if (i > 0 && j >= w[i - 1])
dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i][j]);
}
}
// for(auto v:dp) pvi(v);
ret(dp[n][wt]);
}
| [] | 965,352 | 965,353 | u765321936 | cpp |
p03163 | /* _________________________________________________________________________________________________
| | | Author : Aditya Ahuja | | Date :
Sun, 4th Aug 2019 |
|_________________________________________________________________________________________________|
*/
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define req(i, a, b) for (int i = (int)b - 1; i >= a; i--)
#define all(a) (a).begin(), (a).end()
#define ret(x) \
{ \
cout << x << endl; \
return; \
}
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
#ifdef LOCAL
#define wa(x) cerr << (#x) << " --- " << (x) << endl
#define pvi(v) \
{ \
for (auto it : v) \
cerr << it << " "; \
cerr << endl; \
}
#define line1 cerr << "---------------------------" << endl;
#else
#define wa //
#define line1 //
#define pvi //
#define printf //
#endif
void solve();
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
//___________________________________________________________________________________________________
void maxi(int &a, int b) { a = max(a, b); }
void solve() {
int n, w;
cin >> n >> w;
vi wt(n + 1, 0);
vi val(n + 1, 0);
rep(i, 0, n) cin >> wt[i + 1] >> val[i + 1];
// dp[i][j] - max value reachable using first i items
// and maximum weight j
vector<vi> dp(n + 1, vi(w + 1, 0));
rep(i, 0, n + 1) {
// wa(wt[i]);
// wa(val[i]);
rep(j, 0, w + 1) {
if (i == 0)
continue;
maxi(dp[i][j], dp[i - 1][j]);
if (j - wt[i] >= 0) {
maxi(dp[i][j], dp[i - 1][j - wt[i]] + val[i]);
}
}
// for(auto r:dp) pvi(r);
// line1;
}
cout << *max_element(all(dp[n])) << endl;
}
| /* _________________________________________________________________________________________________
| | | Author : Aditya Ahuja | | Date :
Sun, 4th Aug 2019 |
|_________________________________________________________________________________________________|
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define req(i, a, b) for (int i = (int)b - 1; i >= a; i--)
#define all(a) (a).begin(), (a).end()
#define ret(x) \
{ \
cout << x << endl; \
return; \
}
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
#ifdef LOCAL
#define wa(x) cerr << (#x) << " --- " << (x) << endl
#define pvi(v) \
{ \
for (auto it : v) \
cerr << it << " "; \
cerr << endl; \
}
#define line1 cerr << "---------------------------" << endl;
#else
#define wa //
#define line1 //
#define pvi //
#define printf //
#endif
void solve();
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
//___________________________________________________________________________________________________
void maxi(int &a, int b) { a = max(a, b); }
void solve() {
int n, w;
cin >> n >> w;
vi wt(n + 1, 0);
vi val(n + 1, 0);
rep(i, 0, n) cin >> wt[i + 1] >> val[i + 1];
// dp[i][j] - max value reachable using first i items
// and maximum weight j
vector<vi> dp(n + 1, vi(w + 1, 0));
rep(i, 0, n + 1) {
// wa(wt[i]);
// wa(val[i]);
rep(j, 0, w + 1) {
if (i == 0)
continue;
maxi(dp[i][j], dp[i - 1][j]);
if (j - wt[i] >= 0) {
maxi(dp[i][j], dp[i - 1][j - wt[i]] + val[i]);
}
}
// for(auto r:dp) pvi(r);
// line1;
}
cout << *max_element(all(dp[n])) << endl;
}
| [] | 965,354 | 965,355 | u765321936 | cpp |
p03163 | /* _________________________________________________________________________________________________
| | | Author : Aditya Ahuja | | Date :
Thu, 20th Jun 2019 |
|_________________________________________________________________________________________________|
*/
#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define pb push_back
#define F first
#define S second
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(a) (a).begin(), (a).end()
#define ret(x) \
{ \
cout << (x) << endl; \
return; \
}
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
#define wa(x) cout << (#x) << " -------- " << (x) << endl
#define pvi(v) \
{ \
for (auto it : v) \
cout << it << " "; \
cout << endl; \
}
#define line1 printf("---------------------------\n")
// #define wa //
// #define line1 //
// #define pvi //
// #define printf //
void solve();
signed main() {
// ios_base::sync_with_stdio(false); cin.tie(NULL);
////cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
//___________________________________________________________________________________________________
void solve() {
int n, w;
cin >> n >> w;
vi dp(w + 1, 0);
rep(i, 0, n) {
int wi, vi;
cin >> wi >> vi;
for (int wa = w; wa >= wi; wa--) {
dp[wa] = max(dp[wa], dp[wa - wi] + vi);
}
// pvi(dp);
// line1;
}
ret(*max_element(all(dp)));
}
| /* _________________________________________________________________________________________________
| | | Author : Aditya Ahuja | | Date :
Thu, 20th Jun 2019 |
|_________________________________________________________________________________________________|
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(a) (a).begin(), (a).end()
#define ret(x) \
{ \
cout << (x) << endl; \
return; \
}
#define sz(x) (int)x.size()
#define type(x) typeid(x).name()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vector<int>> vii;
#define wa(x) cout << (#x) << " -------- " << (x) << endl
#define pvi(v) \
{ \
for (auto it : v) \
cout << it << " "; \
cout << endl; \
}
#define line1 printf("---------------------------\n")
// #define wa //
// #define line1 //
// #define pvi //
// #define printf //
void solve();
signed main() {
// ios_base::sync_with_stdio(false); cin.tie(NULL);
////cout << fixed << setprecision(10);
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
//___________________________________________________________________________________________________
//
void solve() {
int n, w;
cin >> n >> w;
vi dp(w + 1, 0);
rep(i, 0, n) {
int wi, vi;
cin >> wi >> vi;
for (int wa = w; wa >= wi; wa--) {
dp[wa] = max(dp[wa], dp[wa - wi] + vi);
}
// pvi(dp);
// line1;
}
ret(*max_element(all(dp)));
}
| [] | 965,356 | 965,357 | u765321936 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n, capacity;
cin >> n >> capacity;
int wt[n], val[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
int dp[n + 1][capacity + 1] = {};
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= capacity; j++) {
int a = 0, b = 0;
if (wt[i - 1] <= j)
a = dp[i - 1][j - wt[i - 1]] + val[i - 1];
b = dp[i - 1][j];
dp[i][j] = max(a, b);
}
}
cout << dp[n][capacity];
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
int n, capacity;
cin >> n >> capacity;
ll wt[n], val[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
ll dp[n + 1][capacity + 1] = {};
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= capacity; j++) {
ll a = 0, b = 0;
if (wt[i - 1] <= j)
a = dp[i - 1][j - wt[i - 1]] + val[i - 1];
b = dp[i - 1][j];
dp[i][j] = max(a, b);
}
}
cout << dp[n][capacity];
} | [
"variable_declaration.type.change"
] | 965,358 | 965,359 | u659210268 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n, w;
cin >> n >> w;
ll arr[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> arr[i] >> wt[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 {
int inc = 0, exc = 0;
exc = dp[i - 1][j];
if (arr[i - 1] <= j) {
inc = dp[i - 1][j - arr[i - 1]] + wt[i - 1];
}
dp[i][j] = max(inc, exc);
}
}
}
cout << dp[n][w];
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n, w;
cin >> n >> w;
ll arr[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> arr[i] >> wt[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 {
ll inc = 0, exc = 0;
exc = dp[i - 1][j];
if (arr[i - 1] <= j) {
inc = dp[i - 1][j - arr[i - 1]] + wt[i - 1];
}
dp[i][j] = max(inc, exc);
}
}
}
cout << dp[n][w];
} | [
"variable_declaration.type.change"
] | 965,360 | 965,361 | u659210268 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
int n, w;
cin >> n >> w;
int arr[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> arr[i] >> wt[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 {
int inc = 0, exc = 0;
exc = dp[i - 1][j];
if (arr[i - 1] <= j) {
inc = dp[i - 1][j - arr[i - 1]] + wt[i - 1];
}
dp[i][j] = max(inc, exc);
}
}
}
cout << dp[n][w];
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ll n, w;
cin >> n >> w;
ll arr[n], wt[n];
for (int i = 0; i < n; i++) {
cin >> arr[i] >> wt[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 {
ll inc = 0, exc = 0;
exc = dp[i - 1][j];
if (arr[i - 1] <= j) {
inc = dp[i - 1][j - arr[i - 1]] + wt[i - 1];
}
dp[i][j] = max(inc, exc);
}
}
}
cout << dp[n][w];
} | [
"variable_declaration.type.change"
] | 965,362 | 965,361 | u659210268 | cpp |
p03163 | #include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define pb push_back
#define f first
#define se second
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
ll n, W, ans = 0;
cin >> n >> W;
ll dp[n + 1][W + 1];
mem(dp, 0);
ll v[n + 1], w[n + 1];
mem(v, 0);
mem(w, 0);
for (ll i = 1; i < n + 1; ++i) {
cin >> w[i] >> v[i];
}
dp[1][0] = 0;
dp[1][w[0]] = v[0];
for (ll i = 2; i < n + 1; ++i) {
dp[i][0] = 0;
for (ll j = 1; j < W + 1; ++j) {
dp[i][j] = dp[i - 1][j];
if (j - w[i] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
for (ll i = 0; i < W + 1; ++i) {
ans = max(ans, dp[n][i]);
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define pb push_back
#define f first
#define se second
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
ll n, W, ans = 0;
cin >> n >> W;
ll dp[n + 1][W + 1];
mem(dp, 0);
ll v[n + 1], w[n + 1];
mem(v, 0);
mem(w, 0);
for (ll i = 1; i < n + 1; ++i) {
cin >> w[i] >> v[i];
}
dp[1][0] = 0;
dp[1][w[1]] = v[1];
for (ll i = 2; i < n + 1; ++i) {
dp[i][0] = 0;
for (ll j = 1; j < W + 1; ++j) {
dp[i][j] = dp[i - 1][j];
if (j - w[i] >= 1)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
for (ll i = 1; i < W + 1; ++i) {
ans = max(ans, dp[n][i]);
}
cout << ans;
return 0;
} | [
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"assignment.value.change",
"control_flow.branch.if.condition.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 965,369 | 965,370 | u344194703 | cpp |
p03163 | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
using namespace std;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
int n;
const int N = 103, nax = 1e5 + 3;
ll W, w[N], v[N];
ll dp[N][nax];
ll rec(int ind, ll s) {
if (ind == n && s >= 0)
return 0;
else if (ind == n || s < 0)
return -1e12;
ll &cur = dp[ind][s];
if (cur != -1)
return cur;
return cur = max(v[ind] + rec(ind + 1, s - w[ind]), rec(ind + 1, s));
}
void solve() {
cin >> n >> W;
for (int i = 0; i < n; ++i)
for (int j = 0; j < W; ++j)
dp[i][j] = -1;
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
cout << rec(0, W) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
using namespace std;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
int n;
const int N = 103, nax = 1e5 + 3;
ll W, w[N], v[N];
ll dp[N][nax];
ll rec(int ind, ll s) {
if (ind == n && s >= 0)
return 0;
else if (ind == n || s < 0)
return -1e12;
ll &cur = dp[ind][s];
if (cur != -1)
return cur;
return cur = max(v[ind] + rec(ind + 1, s - w[ind]), rec(ind + 1, s));
}
void solve() {
cin >> n >> W;
for (int i = 0; i < n; ++i)
for (int j = 0; j <= W; ++j)
dp[i][j] = -1;
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
}
cout << rec(0, W) << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 965,371 | 965,372 | u215674898 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
int value[n], weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
int dp[n + 1][wt + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int w = 0; w <= wt; w++) {
if (w == 0 || i == 0) {
dp[i][w] = 0;
} else if (weight[i - 1] <= w) {
dp[i][w] =
max(value[i - 1] + dp[i - 1][w - weight[i - 1]], dp[i - 1][w]);
} else {
dp[i][w] = dp[i - 1][w];
}
}
}
cout << dp[n][wt] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
long long int value[n], weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
long long int dp[n + 1][wt + 1];
memset(dp, 0, sizeof(dp));
for (int i = 0; i <= n; i++) {
for (int w = 0; w <= wt; w++) {
if (w == 0 || i == 0) {
dp[i][w] = 0;
} else if (weight[i - 1] <= w) {
dp[i][w] =
max(value[i - 1] + dp[i - 1][w - weight[i - 1]], dp[i - 1][w]);
} else {
dp[i][w] = dp[i - 1][w];
}
}
}
cout << dp[n][wt] << endl;
} | [
"variable_declaration.type.widen.change"
] | 965,373 | 965,374 | u364129544 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
// map<int,int> m;
int w[n], v[n];
for (int i{}; i < n; i++) {
cin >> w[i] >> v[i];
}
int dp[W + 1]{};
// for(int i{};i<=W;i++){
// cout<<i<<"\t";
// }
//
for (int i = 0; i < n; i++) {
for (int j = W; w[i] <= j; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
// cout<<endl;
// for(auto x:dp){
// cout<<x<<"\t";
// }
}
cout << dp[W];
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, W;
cin >> n >> W;
// map<int,int> m;
long long w[n], v[n];
for (int i{}; i < n; i++) {
cin >> w[i] >> v[i];
}
long long dp[W + 1]{};
// for(int i{};i<=W;i++){
// cout<<i<<"\t";
// }
//
for (int i = 0; i < n; i++) {
for (int j = W; w[i] <= j; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
// cout<<endl;
// for(auto x:dp){
// cout<<x<<"\t";
// }
}
cout << dp[W];
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,375 | 965,376 | u752124256 | cpp |
p03163 | #include <bits/stdc++.h>
#include <string.h>
#define ll long long
#include <vector>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;
int main() {
IOS;
int n, W;
cin >> n >> W;
vector<int> dp(W + 1, 0);
// dp[i] max vlaue of items with total weight exacty i
int weight, value;
for (int i = 0; i < n; i++) {
cin >> weight >> value;
for (ll weight_already = W - weight; weight_already >= 0;
weight_already--) {
dp[weight_already + weight] =
max(dp[weight_already + weight], dp[weight_already] + value);
}
}
int ans = 0;
for (int i = 0; i <= W; i++)
ans = max(ans, dp[i]);
cout << ans;
} | #include <bits/stdc++.h>
#include <string.h>
#define ll long long
#include <vector>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;
int main() {
IOS;
int n, W;
cin >> n >> W;
vector<ll> dp(W + 1, 0);
// dp[i] max vlaue of items with total weight exacty i
int weight, value;
for (int i = 0; i < n; i++) {
cin >> weight >> value;
for (ll weight_already = W - weight; weight_already >= 0;
weight_already--) {
dp[weight_already + weight] =
max(dp[weight_already + weight], dp[weight_already] + value);
}
}
ll ans = 0;
for (int i = 0; i <= W; i++)
ans = max(ans, dp[i]);
cout << ans;
} | [
"variable_declaration.type.change"
] | 965,378 | 965,379 | u375055372 | cpp |
p03163 | #include <bits/stdc++.h>
#include <string.h>
#define ll long long
#include <vector>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;
int main() {
IOS;
int n, W;
cin >> n >> W;
vector<int> dp(W + 1);
// dp[i] max vlaue of items with total weight exacty i
int weight, value;
for (int i = 0; i < n; i++) {
cin >> weight >> value;
for (int weight_already = W - weight; weight_already >= 0;
weight_already--) {
dp[weight_already + weight] =
max(dp[weight_already + weight], dp[weight_already] + value);
}
}
int ans = 0;
for (int i = 0; i <= W; i++)
ans = max(ans, dp[i]);
cout << ans;
} | #include <bits/stdc++.h>
#include <string.h>
#define ll long long
#include <vector>
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;
int main() {
IOS;
int n, W;
cin >> n >> W;
vector<ll> dp(W + 1, 0);
// dp[i] max vlaue of items with total weight exacty i
int weight, value;
for (int i = 0; i < n; i++) {
cin >> weight >> value;
for (ll weight_already = W - weight; weight_already >= 0;
weight_already--) {
dp[weight_already + weight] =
max(dp[weight_already + weight], dp[weight_already] + value);
}
}
ll ans = 0;
for (int i = 0; i <= W; i++)
ans = max(ans, dp[i]);
cout << ans;
} | [
"call.arguments.add",
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change"
] | 965,380 | 965,379 | u375055372 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <vector>
#define lli long long int
#define INF 1e9 + 5
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> dp(W + 1, 0);
// dp[i] max value so that total weight is i
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
// weight_already can go from 0 to W-w as the item may be the first item we
// are iterating over or the last
for (int weight_already = W - w; weight_already >= 0; weight_already--)
dp[weight_already + w] =
max(dp[weight_already + w], dp[weight_already] + v);
}
int answer = 0;
for (int i = 0; i <= W; i++)
answer = max(answer, dp[i]);
cout << answer << endl;
} | #include <algorithm>
#include <iostream>
#include <vector>
#define lli long long int
#define INF 1e9 + 5
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<lli> dp(W + 1, 0);
// dp[i] max value so that total weight is i
for (int i = 0; i < n; i++) {
lli w, v;
cin >> w >> v;
// weight_already can go from 0 to W-w as the item may be the first item we
// are iterating over or the last
for (lli weight_already = W - w; weight_already >= 0; weight_already--)
dp[weight_already + w] =
max(dp[weight_already + w], dp[weight_already] + v);
}
lli answer = 0;
for (lli i = 0; i <= W; i++)
answer = max(answer, dp[i]);
cout << answer << endl;
} | [
"variable_declaration.type.change",
"control_flow.loop.for.initializer.change"
] | 965,381 | 965,382 | u375055372 | cpp |
p03163 | #include <bits/stdc++.h>
#define ll long long
#define vi vector<ll>
#define vii vector<vector<int>>
#define mii map<int, int>
#define pb push_back
#define mod 1e9 + 7;
const int INF = 1e9 + 5;
#define PQ priority_queue<int>
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
int knap(ll n, vi wt, vi val, ll W) {
ll **dp = new ll *[n + 1];
for (int i = 0; i <= n; i++) {
dp[i] = new ll[W + 1];
}
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 = 1; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (wt[i - 1] <= w) {
dp[i][w] = max(dp[i][w], val[i - 1] + dp[i - 1][w - wt[i - 1]]);
}
}
}
ll ans = dp[n][W];
return ans;
}
int main() {
ll n, W;
cin >> n >> W;
vi w(n), v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knap(n, w, v, W);
return 0;
} | #include <bits/stdc++.h>
#define ll long long int
#define vi vector<ll>
#define vii vector<vector<int>>
#define mii map<int, int>
#define pb push_back
#define mod 1e9 + 7;
const int INF = 1e9 + 5;
#define PQ priority_queue<int>
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
ll knap(ll n, vi wt, vi val, ll W) {
ll **dp = new ll *[n + 1];
for (int i = 0; i <= n; i++) {
dp[i] = new ll[W + 1];
}
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 = 1; i <= n; i++) {
for (int w = 0; w <= W; w++) {
dp[i][w] = dp[i - 1][w];
if (wt[i - 1] <= w) {
dp[i][w] = max(dp[i][w], val[i - 1] + dp[i - 1][w - wt[i - 1]]);
}
}
}
ll ans = dp[n][W];
return ans;
}
int main() {
ll n, W;
cin >> n >> W;
vi w(n), v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knap(n, w, v, W);
return 0;
} | [] | 965,386 | 965,387 | u402611027 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, w;
cin >> n >> w;
vector<vector<int>> dp(n + 1, vector<int>(w + 1));
vector<pair<int, int>> data(n + 1);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
data[i + 1] = {a, b};
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (data[i].first <= j) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - data[i].first] + data[i].second);
}
}
}
cout << dp[n][w] << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, w;
cin >> n >> w;
vector<vector<long long>> dp(n + 1, vector<long long>(w + 1));
vector<pair<int, int>> data(n + 1);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
data[i + 1] = {a, b};
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (data[i].first <= j) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - data[i].first] + data[i].second);
}
}
}
cout << dp[n][w] << '\n';
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change"
] | 965,388 | 965,389 | u897417872 | cpp |
p03163 | #include <bits/stdc++.h>
// DEEP
using namespace std;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define fwd(i, a, n) for (int i = a; i <= n; i++)
#define bak(i, a, n) for (int i = a; i >= n; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef set<int> si;
const ll mod = 1e9 + 7;
ull power(ull x, ull y) {
if (y == 0)
return 1;
else {
if (y % 2 == 0)
return power(x * x, y / 2);
else
return x * power(x * x, (y - 1) / 2);
}
}
ull gcd(ull x, ull y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int main() {
int n, w;
cin >> n >> w;
vi wei(n + 1);
vi val(n + 1);
for (int i = 1; i <= n; i++)
cin >> wei[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 {
dp[i][j] = dp[i - 1][j];
if (j >= wei[i])
dp[i][j] = max(dp[i - 1][j - wei[i]] + val[i], dp[i][j]);
}
}
}
cout << dp[n][w] << endl;
}
| #include <bits/stdc++.h>
// DEEP
using namespace std;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define fwd(i, a, n) for (int i = a; i <= n; i++)
#define bak(i, a, n) for (int i = a; i >= n; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef set<int> si;
const ll mod = 1e9 + 7;
ull power(ull x, ull y) {
if (y == 0)
return 1;
else {
if (y % 2 == 0)
return power(x * x, y / 2);
else
return x * power(x * x, (y - 1) / 2);
}
}
ull gcd(ull x, ull y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int main() {
ll n, w;
cin >> n >> w;
vll wei(n + 1);
vll val(n + 1);
for (int i = 1; i <= n; i++)
cin >> wei[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 {
dp[i][j] = dp[i - 1][j];
if (j >= wei[i])
dp[i][j] = max(dp[i - 1][j - wei[i]] + val[i], dp[i][j]);
}
}
}
cout << dp[n][w] << endl;
}
| [
"variable_declaration.type.change"
] | 965,390 | 965,391 | u915716225 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
int w[n + 1], v[n + 1], dp[wt + 1];
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= wt; i++)
dp[i] = 0;
for (int j = 1; j <= n; j++)
for (int i = wt; i >= 1; i--)
if (w[j] <= i)
dp[i] = max(dp[i], dp[i - w[j]] + v[j]);
cout << dp[wt];
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
int w[n + 1], v[n + 1];
long long int dp[wt + 1];
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= wt; i++)
dp[i] = 0;
for (int j = 1; j <= n; j++)
for (int i = wt; i >= 0; i--)
if (w[j] <= i)
dp[i] = max(dp[i], dp[i - w[j]] + v[j]);
cout << dp[wt];
} | [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 965,393 | 965,394 | u659211619 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
int w[n + 1], v[n + 1], dp[wt + 1];
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= wt; i++)
dp[i] = 0;
for (int j = 1; j <= n; j++)
for (int i = wt; i >= 1; i--)
if (w[j] <= i)
dp[i] = max(dp[i], dp[i - w[j]] + v[j]);
cout << dp[wt];
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, wt;
cin >> n >> wt;
long long int w[n + 1], v[n + 1], dp[wt + 1];
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= wt; i++)
dp[i] = 0;
for (int j = 1; j <= n; j++)
for (int i = wt; i >= 0; i--)
if (w[j] <= i)
dp[i] = max(dp[i], dp[i - w[j]] + v[j]);
cout << dp[wt];
} | [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 965,393 | 965,395 | u659211619 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, wt;
cin >> n >> wt;
int w[n + 1], v[n + 1], dp[wt + 1];
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= wt; i++)
dp[i] = 0;
for (int j = 1; j <= n; j++)
for (int i = wt; i >= 1; i--)
if (w[j] <= i)
dp[i] = max(dp[i], dp[i - w[j]] + v[j]);
cout << dp[wt];
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, wt;
cin >> n >> wt;
long long int w[n + 1], v[n + 1], dp[wt + 1];
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= wt; i++)
dp[i] = 0;
for (int j = 1; j <= n; j++)
for (int i = wt; i >= 1; i--)
if (w[j] <= i)
dp[i] = max(dp[i], dp[i - w[j]] + v[j]);
cout << dp[wt];
} | [
"variable_declaration.type.widen.change"
] | 965,393 | 965,396 | u659211619 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
vector<vector<int>> NW(N + 1, vector<int>(W + 1));
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int j = 0; j <= W; j++) {
NW[0][j] = 0;
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (w[i - 1] > j) {
NW[i][j] = NW[i - 1][j];
} else {
NW[i][j] = max(NW[i - 1][j], v[i - 1] + NW[i - 1][j - w[i - 1]]);
}
}
}
cout << NW[N][W];
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main() {
long N, W;
cin >> N >> W;
vector<long> w(N), v(N);
vector<vector<long>> NW(N + 1, vector<long>(W + 1));
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int j = 0; j <= W; j++) {
NW[0][j] = 0;
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (w[i - 1] > j) {
NW[i][j] = NW[i - 1][j];
} else {
NW[i][j] = max(NW[i - 1][j], v[i - 1] + NW[i - 1][j - w[i - 1]]);
}
}
}
cout << NW[N][W];
}
| [
"variable_declaration.type.primitive.change"
] | 965,397 | 965,398 | u659211619 | cpp |
p03163 | #include <bits/stdc++.h>
using namespace std;
void print_err() { cerr << "\n"; }
template <class T, class... Arg> void print_err(T x, Arg &&...args) {
cerr << x << " ";
print_err(args...);
}
#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define ll int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define vpll vector<pair<ll, ll>>
#define mll map<ll, ll>
#define mllrev map<ll, ll, greater<int>>
#define ps(x, y) fixed << setprecision(y) << x
#define w(t) \
ll t; \
cin >> t; \
while (t--)
#define fo(i, n) for (ll i = 0; i < n; ++i)
#define foab(i, a, b) for (ll i = a; i < b; ++i)
#define inp cin >>
#define pr cout <<
#define fastio \
ios_base::sync_with_stdio(NULL); \
cin.tie(NULL); \
cout.tie(NULL);
class Graph {
public:
list<ll> *adj_list;
ll v;
Graph(ll v) {
this->v = v;
adj_list = new list<ll>[v];
}
void add_edge(ll u, ll v, bool bidirectional = true) {
adj_list[u].push_back(v);
if (bidirectional) {
adj_list[v].push_back(u);
}
}
void print();
void connected_compo();
void dfs(ll v, bool visited[]);
void bfs(ll v, bool visited[]);
};
ll dp[101][100001];
ll recurese(ll n, ll w, ll *val, ll *wt) {
if (n == 0 or w == 0) {
return 0;
}
if (dp[n][w] != -1) {
return dp[n][w];
}
if (wt[n - 1] <= w) {
return dp[n][w] = max(val[n - 1] + recurese(n - 1, w - wt[n - 1], val, wt),
recurese(n - 1, w, val, wt));
} else if (wt[n - 1] > w) {
return dp[n][w] = recurese(n - 1, w, val, wt);
}
return dp[n][w];
}
void solve() {
// // http://codeforces.com/problemset/problem/445/A
// inp n >> m;
// fo(i, n) {
// fo(j, m) {
// inp ch[i][j];
// }
// }
ll n, w;
inp n >> w;
ll val[n], wt[n];
fo(i, n) {
inp wt[i];
inp val[i];
}
memset(dp, -1, sizeof(dp));
cout << recurese(n, w, val, wt) << endl;
return;
}
int main() {
fastio
#ifdef local
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
solve();
return 0;
}
// ll n, m;
// char ch[100][100];
// bool istrue = false;
// ll dx[] = { -1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
// void dfs(ll row, ll col, char ch) {
// if (ch[row][col] == 'B' or ch[row][col] == 'W' or ch[row][col] == '-' or
// istrue) { return;
// }
// fo(i, 4) {
// if (isvalid(ch, row + dx[i], col + dy[i])) {
// if (ch == 'B') {
// dfs(row + dx[i], col + dy[i], 'W');
// } else if (ch == 'W') {
// dfs(row + dx[i], col + dy[i], 'B');
// }
// }
// }
// } | #include <bits/stdc++.h>
using namespace std;
void print_err() { cerr << "\n"; }
template <class T, class... Arg> void print_err(T x, Arg &&...args) {
cerr << x << " ";
print_err(args...);
}
#ifdef local
#define debug(...) print_err(__VA_ARGS__)
#else
#define debug(...)
#endif
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define vpll vector<pair<ll, ll>>
#define mll map<ll, ll>
#define mllrev map<ll, ll, greater<int>>
#define ps(x, y) fixed << setprecision(y) << x
#define w(t) \
ll t; \
cin >> t; \
while (t--)
#define fo(i, n) for (ll i = 0; i < n; ++i)
#define foab(i, a, b) for (ll i = a; i < b; ++i)
#define inp cin >>
#define pr cout <<
#define fastio \
ios_base::sync_with_stdio(NULL); \
cin.tie(NULL); \
cout.tie(NULL);
class Graph {
public:
list<ll> *adj_list;
ll v;
Graph(ll v) {
this->v = v;
adj_list = new list<ll>[v];
}
void add_edge(ll u, ll v, bool bidirectional = true) {
adj_list[u].push_back(v);
if (bidirectional) {
adj_list[v].push_back(u);
}
}
void print();
void connected_compo();
void dfs(ll v, bool visited[]);
void bfs(ll v, bool visited[]);
};
ll dp[101][100001];
ll recurese(ll n, ll w, ll *val, ll *wt) {
if (n == 0 or w == 0) {
return 0;
}
if (dp[n][w] != -1) {
return dp[n][w];
}
if (wt[n - 1] <= w) {
return dp[n][w] = max(val[n - 1] + recurese(n - 1, w - wt[n - 1], val, wt),
recurese(n - 1, w, val, wt));
} else if (wt[n - 1] > w) {
return dp[n][w] = recurese(n - 1, w, val, wt);
}
return dp[n][w];
}
void solve() {
// // http://codeforces.com/problemset/problem/445/A
// inp n >> m;
// fo(i, n) {
// fo(j, m) {
// inp ch[i][j];
// }
// }
ll n, w;
inp n >> w;
ll val[n], wt[n];
fo(i, n) {
inp wt[i];
inp val[i];
}
memset(dp, -1, sizeof(dp));
// ll ans=
cout << recurese(n, w, val, wt) << endl;
return;
}
int main() {
fastio
#ifdef local
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
solve();
return 0;
}
// ll n, m;
// char ch[100][100];
// bool istrue = false;
// ll dx[] = { -1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
// void dfs(ll row, ll col, char ch) {
// if (ch[row][col] == 'B' or ch[row][col] == 'W' or ch[row][col] == '-' or
// istrue) { return;
// }
// fo(i, 4) {
// if (isvalid(ch, row + dx[i], col + dy[i])) {
// if (ch == 'B') {
// dfs(row + dx[i], col + dy[i], 'W');
// } else if (ch == 'W') {
// dfs(row + dx[i], col + dy[i], 'B');
// }
// }
// }
// } | [] | 965,402 | 965,403 | u950979790 | cpp |
p03163 | // author:satwik_bhv1
#include <bits/stdc++.h>
// datatypes
#define ll long long
#define ld long double
// loops
#define fr(i, z, n) for (ll i = z; i < n; i++)
#define br(i, z, n) for (ll i = z; i > n; i--)
// operations
#define mp make_pair
#define ff first
#define ss second
#define pub push_back
#define all(v) v.begin(), v.end()
// map
#define mi map<ll, ll>
// vectors
#define vi vector<ll>
#define vpi vector<pair<ll, ll>>
// constants
#define pi 3.1415926535897932384626
#define mod 1000000007
#define MAXN 100001
/*notes
Don't use inbuilt fun for power
Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
INT_MAX = 2147483647(aprox 2*10^10)
INT_MIN = -2147483648
LLONG_MAX = 9223372036854775807
LLONG_MIN = -9223372036854775808
__gcd is the function in built for hcf
priority queue is max heap by default
topological sort -> khan's algo use bfs and indegree of node
sssp(positive weighted edges) -> Dijkstras
apsp -> Floydwarshall
MST -> kruskal(DSU)
*/
using namespace std;
// functions
ll power(ll x, ll y) {
ll res = 1;
while (y) {
if (y % 2) {
res *= x;
}
y /= 2;
x *= x;
}
return res;
}
ll power(ll x, ll y, ll z) {
ll res = 1;
while (y) {
if (y % 2) {
res = (res * x) % z;
}
y /= 2;
x = (x * x) % z;
}
return res;
}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.second > b.second);
}
ll ceil(ll x, ll y) { return (x / y) + (x % y != 0); }
ll n, w;
ll v[100][2];
ll dp[100][100001];
ll fun(ll pos, ll limit) {
if (pos == n) {
return 0;
}
ll ans = 0;
if (dp[pos + 1][limit] == -1) {
ans = max(ans, fun(pos + 1, limit));
} else {
ans = max(ans, dp[pos + 1][limit]);
}
if (limit >= v[pos][0]) {
if (dp[pos + 1][limit - v[pos][0]] == -1) {
ans = max(ans, fun(pos + 1, limit - v[pos][0]) + v[pos][1]);
} else {
ans = max(ans, dp[pos + 1][limit - v[pos][0]] + v[pos][1]);
}
}
return dp[pos][limit] = ans;
}
void solve() {
cin >> n >> w;
fr(i, 0, n) {
fr(j, 0, 2) { cin >> v[i][j]; }
}
fr(i, 0, n) {
fr(j, 0, w) { dp[i][j] = -1; }
}
cout << fun(0, w);
}
int main() {
fast();
ll t;
t = 1;
// cin>>t;
fr(i, 0, t) { solve(); }
}
/*
*/ | // author:satwik_bhv1
#include <bits/stdc++.h>
// datatypes
#define ll long long
#define ld long double
// loops
#define fr(i, z, n) for (ll i = z; i < n; i++)
#define br(i, z, n) for (ll i = z; i > n; i--)
// operations
#define mp make_pair
#define ff first
#define ss second
#define pub push_back
#define all(v) v.begin(), v.end()
// map
#define mi map<ll, ll>
// vectors
#define vi vector<ll>
#define vpi vector<pair<ll, ll>>
// constants
#define pi 3.1415926535897932384626
#define mod 1000000007
#define MAXN 100001
/*notes
Don't use inbuilt fun for power
Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
INT_MAX = 2147483647(aprox 2*10^10)
INT_MIN = -2147483648
LLONG_MAX = 9223372036854775807
LLONG_MIN = -9223372036854775808
__gcd is the function in built for hcf
priority queue is max heap by default
topological sort -> khan's algo use bfs and indegree of node
sssp(positive weighted edges) -> Dijkstras
apsp -> Floydwarshall
MST -> kruskal(DSU)
*/
using namespace std;
// functions
ll power(ll x, ll y) {
ll res = 1;
while (y) {
if (y % 2) {
res *= x;
}
y /= 2;
x *= x;
}
return res;
}
ll power(ll x, ll y, ll z) {
ll res = 1;
while (y) {
if (y % 2) {
res = (res * x) % z;
}
y /= 2;
x = (x * x) % z;
}
return res;
}
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
bool sortbysec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.second > b.second);
}
ll ceil(ll x, ll y) { return (x / y) + (x % y != 0); }
ll n, w;
ll v[101][2];
ll dp[101][100001];
ll fun(ll pos, ll limit) {
if (pos == n) {
return 0;
}
ll ans = 0;
if (dp[pos + 1][limit] == -1) {
ans = max(ans, fun(pos + 1, limit));
} else {
ans = max(ans, dp[pos + 1][limit]);
}
if (limit >= v[pos][0]) {
if (dp[pos + 1][limit - v[pos][0]] == -1) {
ans = max(ans, fun(pos + 1, limit - v[pos][0]) + v[pos][1]);
} else {
ans = max(ans, dp[pos + 1][limit - v[pos][0]] + v[pos][1]);
}
}
return dp[pos][limit] = ans;
}
void solve() {
cin >> n >> w;
fr(i, 0, n) {
fr(j, 0, 2) { cin >> v[i][j]; }
}
fr(i, 0, n) {
fr(j, 0, w + 1) { dp[i][j] = -1; }
}
cout << fun(0, w);
}
int main() {
fast();
ll t;
t = 1;
// cin>>t;
fr(i, 0, t) { solve(); }
}
/*
*/ | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 965,407 | 965,406 | u136100045 | cpp |
p03163 | #include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int rec(vector<int> val, vector<int> weight, int i, int w) {
if (i == 0 || w == 0)
return 0;
// if(w < 0) return 0;
if (weight[i - 1] > w) {
rec(val, weight, i - 1, w);
}
return max(val[i - 1] + rec(val, weight, i - 1, w - weight[i - 1]),
rec(val, weight, i - 1, w));
}
int main() {
int n, w;
cin >> n >> w;
vector<int> val(n);
vector<int> weight(n);
for (int i = 0; i < n; i++) {
cin >> weight[i];
cin >> val[i];
}
// cout << "weight" << endl;
// for (auto i : weight)
// cout << i << " ";
// cout << endl;
// cout << "val" << endl;
// for (auto i : val)
// cout << i << " ";
// cout << endl;
vector<vector<int>> dp(n + 1, vector<int>(w + 1, 0));
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 (weight[i - 1] <= j) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - weight[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
// cout << rec(val, weight, n, w);
return 0;
} | #include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int rec(vector<int> val, vector<int> weight, int i, int w) {
if (i == 0 || w == 0)
return 0;
// if(w < 0) return 0;
if (weight[i - 1] > w) {
rec(val, weight, i - 1, w);
}
return max(val[i - 1] + rec(val, weight, i - 1, w - weight[i - 1]),
rec(val, weight, i - 1, w));
}
int main() {
int n, w;
cin >> n >> w;
vector<int> val(n);
vector<int> weight(n);
for (int i = 0; i < n; i++) {
cin >> weight[i];
cin >> val[i];
}
// cout << "weight" << endl;
// for (auto i : weight)
// cout << i << " ";
// cout << endl;
// cout << "val" << endl;
// for (auto i : val)
// cout << i << " ";
// cout << endl;
vector<vector<unsigned long long>> dp(n + 1,
vector<unsigned long long>(w + 1, 0));
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 (weight[i - 1] <= j) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - weight[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
// cout << rec(val, weight, n, w);
return 0;
} | [
"variable_declaration.type.primitive.change"
] | 965,408 | 965,409 | u782653321 | cpp |
p03163 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<int> val(n), wt(n);
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
vector<vector<int>> knap(n + 1, vector<int>(w + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (wt[i - 1] <= j) {
knap[i][j] =
max(knap[i - 1][j], val[i - 1] + knap[i - 1][j - wt[i - 1]]);
} else
knap[i][j] = knap[i - 1][j];
}
}
cout << knap[n][w];
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<int> val(n), wt(n);
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
vector<vector<long long int>> knap(n + 1, vector<long long int>(w + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (wt[i - 1] <= j) {
knap[i][j] =
max(knap[i - 1][j], val[i - 1] + knap[i - 1][j - wt[i - 1]]);
} else
knap[i][j] = knap[i - 1][j];
}
}
cout << knap[n][w];
return 0;
}
| [
"variable_declaration.type.widen.change"
] | 965,410 | 965,411 | u754088473 | cpp |
p03163 | // ุจูุณูู
ู ูฑูููููฐูู ูฑูุฑููุญูู
ููฐูู ูฑูุฑููุญููู
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define el cout << '\n';
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int mx = (int)(1e3) * 2 + 5;
ll n, cap;
ll w[mx], val[mx], dp[mx][mx];
ll solve(ll i, ll weight) {
if (i == n || weight > cap)
return 0;
if (dp[i][weight] != -1)
return dp[i][weight];
ll a = 0, b = 0;
if (weight + w[i] <= cap)
a = val[i] + solve(i + 1, weight + w[i]);
b = solve(i + 1, weight);
return dp[i][weight] = max(a, b);
}
int main() {
IOS
memset(dp, -1, sizeof dp);
cin >> cap >> n;
for (size_t i = 0; i < n; i++) {
cin >> w[i] >> val[i];
}
cout << solve(0, 0);
el
} | // ุจูุณูู
ู ูฑูููููฐูู ูฑูุฑููุญูู
ููฐูู ูฑูุฑููุญููู
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define el cout << '\n';
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int mx = (int)(1e5) + 5;
ll n, cap;
ll w[mx], val[mx], dp[100][mx];
ll solve(ll i, ll weight) {
if (i == n || weight > cap)
return 0;
if (dp[i][weight] != -1)
return dp[i][weight];
ll a = 0, b = 0;
if (weight + w[i] <= cap)
a = val[i] + solve(i + 1, weight + w[i]);
b = solve(i + 1, weight);
return dp[i][weight] = max(a, b);
}
int main() {
IOS
memset(dp, -1, sizeof dp);
cin >> n >> cap;
for (size_t i = 0; i < n; i++) {
cin >> w[i] >> val[i];
}
cout << solve(0, 0);
el
} | [
"literal.number.change",
"expression.operation.binary.change",
"expression.operation.binary.remove",
"identifier.replace.remove",
"literal.replace.add",
"variable_declaration.array_dimensions.change"
] | 965,414 | 965,413 | u454940171 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.