problem_id
stringlengths 6
6
| language
stringclasses 2
values | original_status
stringclasses 3
values | original_src
stringlengths 19
243k
| changed_src
stringlengths 19
243k
| change
stringclasses 3
values | i1
int64 0
8.44k
| i2
int64 0
8.44k
| j1
int64 0
8.44k
| j2
int64 0
8.44k
| error
stringclasses 270
values | stderr
stringlengths 0
226k
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ub upper_bound
#define lb lower_bound
#define int long long
#define endl '\n'
#define ff first
#define ss second
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define si set<int>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define repd(i, a, n) for (int i = a; i > n; --i)
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define Mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << " " << #y << "=" << y << endl;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
int Pow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res *= a;
a *= a;
b /= 2;
}
return res;
}
int MPow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = (res * a) % Mod;
a = (a * a) % Mod;
b /= 2;
}
return res % Mod;
}
int log(int x) { return 64 - __builtin_clzll(x) - 1; }
void c_p_p() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
}
struct Node {
int a, b, c, d;
};
const int Max = 1e5 + 1;
int Dp[100][Max];
int Knapsack(int W[], int V[], int cap, int n) {
if (n == 0 || cap < 0)
return 0;
if (Dp[n][cap] == -1) {
if (W[n] <= cap) {
return Dp[n][cap] = max(V[n] + Knapsack(W, V, cap - W[n], n - 1),
Knapsack(W, V, cap, n - 1));
}
return Dp[n][cap] = Knapsack(W, V, cap, n - 1);
}
return Dp[n][cap];
}
int32_t main() {
c_p_p();
memset(Dp, -1, sizeof(Dp));
int n, cap;
cin >> n >> cap;
int W[n + 1], V[n + 1];
rep(i, 1, n + 1) { cin >> W[i] >> V[i]; }
cout << Knapsack(W, V, cap, n);
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ub upper_bound
#define lb lower_bound
#define int long long
#define endl '\n'
#define ff first
#define ss second
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define si set<int>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define repd(i, a, n) for (int i = a; i > n; --i)
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define Mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << " " << #y << "=" << y << endl;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
int Pow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res *= a;
a *= a;
b /= 2;
}
return res;
}
int MPow(int a, int b) {
int res = 1;
while (b > 0) {
if (b & 1)
res = (res * a) % Mod;
a = (a * a) % Mod;
b /= 2;
}
return res % Mod;
}
int log(int x) { return 64 - __builtin_clzll(x) - 1; }
void c_p_p() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#endif
}
struct Node {
int a, b, c, d;
};
const int Max = 1e5 + 1;
int Dp[101][Max];
int Knapsack(int W[], int V[], int cap, int n) {
if (n == 0 || cap < 0)
return 0;
if (Dp[n][cap] == -1) {
if (W[n] <= cap) {
return Dp[n][cap] = max(V[n] + Knapsack(W, V, cap - W[n], n - 1),
Knapsack(W, V, cap, n - 1));
}
return Dp[n][cap] = Knapsack(W, V, cap, n - 1);
}
return Dp[n][cap];
}
int32_t main() {
c_p_p();
memset(Dp, -1, sizeof(Dp));
int n, cap;
cin >> n >> cap;
int W[n + 1], V[n + 1];
rep(i, 1, n + 1) { cin >> W[i] >> V[i]; }
cout << Knapsack(W, V, cap, n);
return 0;
}
|
replace
| 75 | 76 | 75 | 76 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
vector<long long int> dp(W + 1, 0);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = W; j >= 0; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
vector<long long int> dp(W + 1, 0);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int N, W;
int N_MAX = 100;
int W_MAX = 100000;
vector<int> w(N_MAX), v(N_MAX);
vector<vector<long long>> dp(N_MAX, vector<long long>(W_MAX + 1, 0));
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
cout << dp[N][W] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, W;
int N_MAX = 100;
int W_MAX = 100000;
vector<int> w(N_MAX), v(N_MAX);
vector<vector<long long>> dp(N_MAX + 1, vector<long long>(W_MAX, 0));
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
cout << dp[N][W] << endl;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N, W;
int w[105], v[105];
int cache[105][105];
int dp(int n, int wt) {
if (wt > W)
return -1e15;
if (n == N)
return 0;
if (cache[n][wt] != -1)
return cache[n][wt];
cache[n][wt] = max(dp(n + 1, wt), v[n] + dp(n + 1, wt + w[n]));
return cache[n][wt];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(cache, -1, sizeof(cache));
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
cout << dp(0, 0);
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
int N, W;
int w[105], v[105];
int cache[105][100005];
int dp(int n, int wt) {
if (wt > W)
return -1e15;
if (n == N)
return 0;
if (cache[n][wt] != -1)
return cache[n][wt];
cache[n][wt] = max(dp(n + 1, wt), v[n] + dp(n + 1, wt + w[n]));
return cache[n][wt];
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(cache, -1, sizeof(cache));
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
cout << dp(0, 0);
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[110][100010];
int a[110][2];
int32_t main() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i][0] >> a[i][1];
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i][j - 1];
if (a[j][0] <= i)
dp[i][j] = max(dp[i][j], dp[i - a[j][0]][j - 1] + a[j][1]);
}
}
// for(int i=0;i<=w;i++)
// {
// for(int j=0;j<=n;j++)
// cout << dp[i][j] << " ";
// cout << endl;
// }
cout << dp[w][n] << endl;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
int dp[100010][110];
int a[110][2];
int32_t main() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i][0] >> a[i][1];
for (int i = 1; i <= w; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = dp[i][j - 1];
if (a[j][0] <= i)
dp[i][j] = max(dp[i][j], dp[i - a[j][0]][j - 1] + a[j][1]);
}
}
// for(int i=0;i<=w;i++)
// {
// for(int j=0;j<=n;j++)
// cout << dp[i][j] << " ";
// cout << endl;
// }
cout << dp[w][n] << endl;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint Knapsack(int limit, vector<int> &v, vector<int> &w) {
vector<lint> dyn(limit, -1);
int n = w.size();
dyn[0] = 0;
for (int i = 0; i < n; ++i)
for (int j = limit; j >= w[i]; --j)
if (dyn[j - w[i]] >= 0)
dyn[j] = max(dyn[j], dyn[j - w[i]] + v[i]);
lint result = 0;
for (int i = 0; i <= limit; ++i)
result = max(result, dyn[i]);
return result;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, w;
cin >> n >> w;
vector<int> v(n), c(n);
for (int i = 0; i < n; ++i)
cin >> c[i] >> v[i];
cout << Knapsack(w, v, c) << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint Knapsack(int limit, vector<int> &v, vector<int> &w) {
vector<lint> dyn(limit + 1, -1);
int n = w.size();
dyn[0] = 0;
for (int i = 0; i < n; ++i)
for (int j = limit; j >= w[i]; --j)
if (dyn[j - w[i]] >= 0)
dyn[j] = max(dyn[j], dyn[j - w[i]] + v[i]);
lint result = 0;
for (int i = 0; i <= limit; ++i)
result = max(result, dyn[i]);
return result;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, w;
cin >> n >> w;
vector<int> v(n), c(n);
for (int i = 0; i < n; ++i)
cin >> c[i] >> v[i];
cout << Knapsack(w, v, c) << '\n';
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flp(i, a, b) for (int i = a; i < b; i++)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define blp(i, a, b) for (int i = a; i >= b; i--)
#define lol 1000000007
ll a[101], b[101];
ll c[201][201];
ll dp(ll n, ll w) {
if (c[n][w] != -1) {
return c[n][w];
}
if (n == 0 || w == 0) {
c[n][w] = 0;
return c[n][w];
}
if (b[n - 1] > w) {
c[n][w] = dp(n - 1, w);
} else {
c[n][w] = max(a[n - 1] + dp(n - 1, w - b[n - 1]), dp(n - 1, w));
}
return c[n][w];
}
int main() {
ios;
ll n, w;
cin >> n >> w;
memset(c, -1, sizeof c);
flp(i, 0, n) { cin >> b[i] >> a[i]; }
cout << dp(n, w) << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flp(i, a, b) for (int i = a; i < b; i++)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define blp(i, a, b) for (int i = a; i >= b; i--)
#define lol 1000000007
ll a[101], b[101];
ll c[102][100002];
ll dp(ll n, ll w) {
if (c[n][w] != -1) {
return c[n][w];
}
if (n == 0 || w == 0) {
c[n][w] = 0;
return c[n][w];
}
if (b[n - 1] > w) {
c[n][w] = dp(n - 1, w);
} else {
c[n][w] = max(a[n - 1] + dp(n - 1, w - b[n - 1]), dp(n - 1, w));
}
return c[n][w];
}
int main() {
ios;
ll n, w;
cin >> n >> w;
memset(c, -1, sizeof c);
flp(i, 0, n) { cin >> b[i] >> a[i]; }
cout << dp(n, w) << "\n";
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
ll w[n + 1], v[n + 1];
w[0] = 0;
v[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> w[i] >> v[i];
}
ll dp[n][k];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
if (j == 0 || i == 0)
dp[i][j] = 0;
else if (j >= w[i]) {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][k];
}
|
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main() {
ll n, k;
cin >> n >> k;
ll w[n + 1], v[n + 1];
w[0] = 0;
v[0] = 0;
for (int i = 1; i <= n; ++i) {
cin >> w[i] >> v[i];
}
ll dp[n + 1][k + 1];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= k; ++j) {
if (j == 0 || i == 0)
dp[i][j] = 0;
else if (j >= w[i]) {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][k];
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl '\n'
#define ll long long
#define inf 1000000007
int main() {
fastio;
#ifdef APNA_IO
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
ll n, w;
cin >> n >> w;
ll dp[n + 1][w + 1];
ll arr[n + 1], arr1[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> arr[i] >> arr1[i];
}
for (ll i = 1; i < w + 1; i++) {
if (arr[1] > i)
dp[1][i] = 0;
else
dp[1][i] = arr1[1];
}
for (ll i = 1; i < n + 1; i++) {
if (arr[i] > 1)
dp[i][1] = 0;
else
dp[i][1] = arr1[i];
}
for (ll i = 0; i < n + 1; i++)
dp[i][0] = 0;
for (ll i = 2; i < n + 1; i++) {
for (ll j = 2; j < w + 1; j++) {
dp[i][j] = dp[i - 1][j];
if (j - arr[i] >= 0) {
for (ll k = 1; k < i; k++)
dp[i][j] = max(dp[i][j], arr1[i] + dp[k][j - arr[i]]);
}
}
}
cout << dp[n][w] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl '\n'
#define ll long long
#define inf 1000000007
int main() {
fastio;
#ifdef APNA_IO
freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
#endif
ll n, w;
cin >> n >> w;
ll dp[n + 1][w + 1];
ll arr[n + 1], arr1[n + 1];
for (ll i = 1; i <= n; i++) {
cin >> arr[i] >> arr1[i];
}
for (ll i = 1; i < w + 1; i++) {
if (arr[1] > i)
dp[1][i] = 0;
else
dp[1][i] = arr1[1];
}
for (ll i = 1; i < n + 1; i++) {
if (arr[i] > 1)
dp[i][1] = 0;
else
dp[i][1] = arr1[i];
}
for (ll i = 0; i < n + 1; i++)
dp[i][0] = 0;
for (ll i = 2; i < n + 1; i++) {
for (ll j = 2; j < w + 1; j++) {
dp[i][j] = dp[i - 1][j];
if (j - arr[i] >= 0) {
dp[i][j] = max(dp[i][j], arr1[i] + dp[i - 1][j - arr[i]]);
}
}
}
cout << dp[n][w] << endl;
return 0;
}
|
replace
| 40 | 42 | 40 | 41 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int N = 0;
int W = 0;
int w[100];
long long v[100];
long long dp[110][110] = {0};
int main(void) {
cin >> N >> W;
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 (w[i] <= j) {
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 <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
int N = 0;
int W = 0;
int w[100];
long long v[100];
long long dp[110][1000010] = {0};
int main(void) {
cin >> N >> W;
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 (w[i] <= j) {
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;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fw(x) freopen("x.txt", "w", stdout)
#define For(i, a, b, c) for (int i = a; i < b; i += c)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define mem(a, s) memset(a, s, sizeof a)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x) cout << #x "=" << (x) << endl
#define pb push_back
using namespace std;
// moves
// int dx[]= {0,0,1,-1};/*4 side move*/
// int dy[]= {-1,1,0,0};/*4 side move*/
// int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
// int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
// int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
// int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/
// big_mod
// ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x
//= (x * a)% m;return x;} ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0)
// {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M
// ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
// ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
// ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
// ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
const int mod = 1000000007;
int cost[101];
int wt[101];
ll dp[101][101];
int main() {
fast;
int n, w;
cin >> n >> w;
REP1(i, n) cin >> wt[i] >> cost[i];
REP1(i, n) {
REP1(j, w) {
if (j >= wt[i])
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i]] + cost[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << '\n';
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fw(x) freopen("x.txt", "w", stdout)
#define For(i, a, b, c) for (int i = a; i < b; i += c)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 1; i <= n; i++)
#define mem(a, s) memset(a, s, sizeof a)
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x) cout << #x "=" << (x) << endl
#define pb push_back
using namespace std;
// moves
// int dx[]= {0,0,1,-1};/*4 side move*/
// int dy[]= {-1,1,0,0};/*4 side move*/
// int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
// int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
// int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
// int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/
// big_mod
// ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x
//= (x * a)% m;return x;} ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0)
// {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M
// ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
// ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
// ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
// ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
const int mod = 1000000007;
int cost[101];
int wt[101];
ll dp[101][100001];
int main() {
fast;
int n, w;
cin >> n >> w;
REP1(i, n) cin >> wt[i] >> cost[i];
REP1(i, n) {
REP1(j, w) {
if (j >= wt[i])
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i]] + cost[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << '\n';
return 0;
}
|
replace
| 60 | 61 | 60 | 61 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w[105], f[105];
ll v[105];
signed main() {
ll N, W;
while (cin >> N >> W) {
for (ll i = 1; i <= N; i++)
cin >> w[i] >> v[i];
// 01背包
memset(f, 0, sizeof f);
for (ll i = 1; i <= N; i++) {
for (ll j = W; j >= w[i]; j--)
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
cout << f[W] << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll w[105], f[100005];
ll v[105];
signed main() {
ll N, W;
while (cin >> N >> W) {
for (ll i = 1; i <= N; i++)
cin >> w[i] >> v[i];
// 01背包
memset(f, 0, sizeof f);
for (ll i = 1; i <= N; i++) {
for (ll j = W; j >= w[i]; j--)
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
cout << f[W] << endl;
}
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int n, w;
int const pp = 10e5;
int arr[32][2];
long long dp[30][pp];
long long solve(int idx, int rem) {
if (idx >= n)
return 0;
long long &ret = dp[idx][rem];
if (ret)
return ret;
if (rem - arr[idx][0] >= 0)
ret = arr[idx][1] + solve(idx + 1, rem - arr[idx][0]);
return ret = max(solve(idx + 1, rem), ret);
}
int main() {
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> arr[i][0] >> arr[i][1];
printf("%lld\n", solve(0, w));
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int n, w;
int const pp = 10e5;
int arr[102][2];
long long dp[102][pp];
long long solve(int idx, int rem) {
if (idx >= n)
return 0;
long long &ret = dp[idx][rem];
if (ret)
return ret;
if (rem - arr[idx][0] >= 0)
ret = arr[idx][1] + solve(idx + 1, rem - arr[idx][0]);
return ret = max(solve(idx + 1, rem), ret);
}
int main() {
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> arr[i][0] >> arr[i][1];
printf("%lld\n", solve(0, w));
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
-11
| |
p03163
|
C++
|
Runtime Error
|
// In The Name Of Allah //
#include <bits/stdc++.h>
#define pb emplace_back
#define inf (int)1e9
#define ff first
#define ss second
#define ll long long
#define sp(n) cout << setprecision(n) << fixed
#define hellcat ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define give(x) cout << #x << " " << x << endl
#define debug cout << "dddd" << '\n'
#define debarr(a, n) \
for (int i = 0; i < n; ++i) \
cout << a[i] << ' '; \
cout << endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long
template <class S, class T> inline S smax(S &l, T r) {
return l = max(l, (S)r);
}
template <class S, class T> inline bool smin(S &l, T r) {
return l = min(l, (S)r);
}
const int MAXN = 2e3 + 10;
int dp[MAXN], n, s, mx = 0;
pair<int, int> p[MAXN];
int32_t main() {
hellcat;
cin >> n >> s;
for (int i = 1; i <= n; i++)
cin >> p[i].first >> p[i].second;
for (int i = 1; i <= n; i++)
for (int j = s; j >= p[i].first; j--)
dp[j] = max(dp[j], dp[j - p[i].first] + p[i].second);
cout << dp[s] << '\n';
return 0;
}
|
// In The Name Of Allah //
#include <bits/stdc++.h>
#define pb emplace_back
#define inf (int)1e9
#define ff first
#define ss second
#define ll long long
#define sp(n) cout << setprecision(n) << fixed
#define hellcat ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define give(x) cout << #x << " " << x << endl
#define debug cout << "dddd" << '\n'
#define debarr(a, n) \
for (int i = 0; i < n; ++i) \
cout << a[i] << ' '; \
cout << endl
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define int long long
template <class S, class T> inline S smax(S &l, T r) {
return l = max(l, (S)r);
}
template <class S, class T> inline bool smin(S &l, T r) {
return l = min(l, (S)r);
}
const int MAXN = 2e5 + 10;
int dp[MAXN], n, s, mx = 0;
pair<int, int> p[MAXN];
int32_t main() {
hellcat;
cin >> n >> s;
for (int i = 1; i <= n; i++)
cin >> p[i].first >> p[i].second;
for (int i = 1; i <= n; i++)
for (int j = s; j >= p[i].first; j--)
dp[j] = max(dp[j], dp[j - p[i].first] + p[i].second);
cout << dp[s] << '\n';
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define int ll
using namespace std;
typedef long long ll;
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<pair<int, int>> items;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (a > w)
continue;
items.PB({a, b});
}
int dp[w + 1];
dp[0] = 0;
for (int i = 1; i <= w; i++) {
dp[i] = INT_MIN;
}
for (int i = 0; i < n; i++) {
for (int j = w; j >= items[i].F; j--) {
if (dp[j - items[i].F] == INT_MIN)
continue;
dp[j] = max(dp[j], items[i].S + dp[j - items[i].F]);
}
}
int mmax = -1;
for (int i = 0; i <= w; i++) {
mmax = max(mmax, dp[i]);
}
cout << mmax << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define int ll
using namespace std;
typedef long long ll;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, w;
cin >> n >> w;
vector<pair<int, int>> items;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (a > w)
continue;
items.PB({a, b});
}
int dp[w + 1];
dp[0] = 0;
for (int i = 1; i <= w; i++) {
dp[i] = INT_MIN;
}
for (int i = 0; i < n; i++) {
for (int j = w; j >= items[i].F; j--) {
if (dp[j - items[i].F] == INT_MIN)
continue;
dp[j] = max(dp[j], items[i].S + dp[j - items[i].F]);
}
}
int mmax = -1;
for (int i = 0; i <= w; i++) {
mmax = max(mmax, dp[i]);
}
cout << mmax << "\n";
return 0;
}
|
delete
| 12 | 17 | 12 | 12 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};
int main() {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(N, vector<ll>(1e7 + 1, -1));
dp[0][0] = 0;
dp[0][w[0]] = v[0];
for (int i = 1; i < N; i++) {
for (int j = 0; j <= W; j++) {
dp[i][j] = dp[i - 1][j];
if (j - w[i] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
}
}
ll ans = 0;
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[N - 1][i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};
int main() {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(N, vector<ll>(1e5 + 1, -1));
dp[0][0] = 0;
dp[0][w[0]] = v[0];
for (int i = 1; i < N; i++) {
for (int j = 0; j <= W; j++) {
dp[i][j] = dp[i - 1][j];
if (j - w[i] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + v[i]);
}
}
ll ans = 0;
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[N - 1][i]);
}
cout << ans << endl;
return 0;
}
|
replace
| 15 | 16 | 15 | 16 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int knapsack(int w, int wt[], int val[], int n) {
int dp[n + 1][w + 1];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
return dp[n][w];
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, w;
cin >> n >> w;
int val[n], wt[n];
for (int i = 0; i < n; ++i)
cin >> wt[i] >> val[i];
cout << knapsack(w, wt, val, n);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int knapsack(int w, int wt[], int val[], int n) {
int dp[n + 1][w + 1];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
return dp[n][w];
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
if (fopen("input.txt", "r")) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int n, w;
cin >> n >> w;
int val[n], wt[n];
for (int i = 0; i < n; ++i)
cin >> wt[i] >> val[i];
cout << knapsack(w, wt, val, n);
return 0;
}
|
replace
| 25 | 29 | 25 | 29 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define initialize(array, size, value) \
for (ll i = 0; i < size; i++) \
array[i] = value
#define couta(array, size) \
for (ll i = 0; i < size; i++) \
cout << array[i] << " "
#define debug(x) cout << "x: " << x << endl
#define dbug(x, y) \
cout << "x: " << x << " " \
<< "y: " << y << endl
#define inf (long long int)1e18
#define eps 0.000001
#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define MAXN 1000001
ll spf[MAXN];
ll gcd(ll a, ll b);
ll palindrome(string s);
ll modexp(ll a, ll b, ll m);
void sieve();
ll ceil(ll a, ll b);
vl getFactorization(ll x);
void getZarr(string str, ll Z[]);
vector<ll> prefix_function(string s);
ll n, wtt;
ll w[105], v[105];
ll dp[105][100005];
ll f(ll idx, ll wt) {
if (wt < 0)
return -inf;
else {
if (idx > n)
return 0;
else {
if (dp[idx][wt] != -1)
return dp[idx][wt];
else {
return dp[idx][wt] =
max((v[idx] + f(idx + 1, wt - w[idx])), f(idx + 1, wt));
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// ll n,w;
cin >> n >> wtt;
// ll w[n+1], v[n+1];
loop(i, 1, n + 1) { cin >> w[i] >> v[i]; }
for (ll i = 0; i < 105; i++) {
for (ll j = 0; j < 100005; j++) {
dp[i][j] = -1;
}
}
cout << f(1, wtt);
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
if (b == 0)
return a;
if (a == b)
return a;
if (a > b)
return gcd(a % b, b);
return gcd(a, b % a);
}
ll palindrome(string s) {
ll l = 0;
ll h = s.length() - 1;
while (h > l) {
if (s[l++] != s[h--]) {
return 0;
}
}
return 1;
}
ll modexp(ll a, ll b, ll m) {
if (b == 0)
return 1;
ll temp = modexp(a, b / 2, m);
temp = (temp * temp) % m;
if (b & 1)
return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
return temp;
}
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
vl getFactorization(ll x) {
vl ret;
while (x != 1) {
ret.push_back(spf[x]);
x = x / spf[x];
}
return ret;
}
ll ceil(ll a, ll b) { return a / b + (a % b != 0); }
void getZarr(string str, ll Z[]) {
ll n = str.length();
ll L, R, k;
L = R = 0;
for (ll i = 1; i < n; ++i) {
if (i > R) {
L = R = i;
while (R < n && str[R - L] == str[R])
R++;
Z[i] = R - L;
R--;
} else {
k = i - L;
if (Z[k] < R - i + 1)
Z[i] = Z[k];
else {
L = i;
while (R < n && str[R - L] == str[R])
R++;
Z[i] = R - L;
R--;
}
}
}
}
vector<ll> prefix_function(string s) {
ll n = (ll)s.length();
vector<ll> pi(n);
for (ll i = 1; i < n; i++) {
ll j = pi[i - 1];
while (j > 0 && s[i] != s[j])
j = pi[j - 1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define loop(i, a, b) for (ll i = a; i < b; i++)
#define initialize(array, size, value) \
for (ll i = 0; i < size; i++) \
array[i] = value
#define couta(array, size) \
for (ll i = 0; i < size; i++) \
cout << array[i] << " "
#define debug(x) cout << "x: " << x << endl
#define dbug(x, y) \
cout << "x: " << x << " " \
<< "y: " << y << endl
#define inf (long long int)1e18
#define eps 0.000001
#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define MAXN 1000001
ll spf[MAXN];
ll gcd(ll a, ll b);
ll palindrome(string s);
ll modexp(ll a, ll b, ll m);
void sieve();
ll ceil(ll a, ll b);
vl getFactorization(ll x);
void getZarr(string str, ll Z[]);
vector<ll> prefix_function(string s);
ll n, wtt;
ll w[105], v[105];
ll dp[105][100005];
ll f(ll idx, ll wt) {
if (wt < 0)
return -inf;
else {
if (idx > n)
return 0;
else {
if (dp[idx][wt] != -1)
return dp[idx][wt];
else {
return dp[idx][wt] =
max((v[idx] + f(idx + 1, wt - w[idx])), f(idx + 1, wt));
}
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
// ll n,w;
cin >> n >> wtt;
// ll w[n+1], v[n+1];
loop(i, 1, n + 1) { cin >> w[i] >> v[i]; }
for (ll i = 0; i < 105; i++) {
for (ll j = 0; j < 100005; j++) {
dp[i][j] = -1;
}
}
cout << f(1, wtt);
}
ll gcd(ll a, ll b) {
if (a == 0)
return b;
if (b == 0)
return a;
if (a == b)
return a;
if (a > b)
return gcd(a % b, b);
return gcd(a, b % a);
}
ll palindrome(string s) {
ll l = 0;
ll h = s.length() - 1;
while (h > l) {
if (s[l++] != s[h--]) {
return 0;
}
}
return 1;
}
ll modexp(ll a, ll b, ll m) {
if (b == 0)
return 1;
ll temp = modexp(a, b / 2, m);
temp = (temp * temp) % m;
if (b & 1)
return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a
return temp;
}
void sieve() {
spf[1] = 1;
for (ll i = 2; i < MAXN; i++)
spf[i] = i;
for (ll i = 4; i < MAXN; i += 2)
spf[i] = 2;
for (ll i = 3; i * i < MAXN; i++) {
if (spf[i] == i) {
for (ll j = i * i; j < MAXN; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
vl getFactorization(ll x) {
vl ret;
while (x != 1) {
ret.push_back(spf[x]);
x = x / spf[x];
}
return ret;
}
ll ceil(ll a, ll b) { return a / b + (a % b != 0); }
void getZarr(string str, ll Z[]) {
ll n = str.length();
ll L, R, k;
L = R = 0;
for (ll i = 1; i < n; ++i) {
if (i > R) {
L = R = i;
while (R < n && str[R - L] == str[R])
R++;
Z[i] = R - L;
R--;
} else {
k = i - L;
if (Z[k] < R - i + 1)
Z[i] = Z[k];
else {
L = i;
while (R < n && str[R - L] == str[R])
R++;
Z[i] = R - L;
R--;
}
}
}
}
vector<ll> prefix_function(string s) {
ll n = (ll)s.length();
vector<ll> pi(n);
for (ll i = 1; i < n; i++) {
ll j = pi[i - 1];
while (j > 0 && s[i] != s[j])
j = pi[j - 1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
|
replace
| 63 | 67 | 63 | 67 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (ll i = 0; i < n; i++)
#define endl "\n"
#define of(i, n) for (ll i = n - 1; i >= 0; i--)
#define ll long long
#define vec vector<ll>
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define tr(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
ll mod = 1e9 + 7;
#define umap unordered_map
string t;
ll sub(string s) {
ll l = 0, h = s.length();
ll j = 0;
for (int i = 0; i < s.length() && j < t.length(); i++)
if (t[j] == s[i])
j++;
return (j == t.length());
}
ll check(ll n, string s) {
ll l, h;
l = 0;
h = n - 1;
while (h < s.length()) {
if (sub(s.substr(l, h)))
return 1;
l++;
h++;
}
return 0;
}
ll ab(ll x) {
if (x < 0)
x *= -1;
return x;
}
int main() {
fio;
ll n, w;
cin >> n >> w;
ll dp[n][w];
int wt[n], v[n];
fo(i, n) cin >> wt[i] >> v[i];
fo(i, n + 1) {
fo(j, w + 1) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fo(i, n) for (ll i = 0; i < n; i++)
#define endl "\n"
#define of(i, n) for (ll i = n - 1; i >= 0; i--)
#define ll long long
#define vec vector<ll>
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define tr(container, it) \
for (typeof(container.begin()) it = container.begin(); \
it != container.end(); it++)
ll mod = 1e9 + 7;
#define umap unordered_map
string t;
ll sub(string s) {
ll l = 0, h = s.length();
ll j = 0;
for (int i = 0; i < s.length() && j < t.length(); i++)
if (t[j] == s[i])
j++;
return (j == t.length());
}
ll check(ll n, string s) {
ll l, h;
l = 0;
h = n - 1;
while (h < s.length()) {
if (sub(s.substr(l, h)))
return 1;
l++;
h++;
}
return 0;
}
ll ab(ll x) {
if (x < 0)
x *= -1;
return x;
}
int main() {
fio;
ll n, w;
cin >> n >> w;
ll dp[n + 1][w + 1];
int wt[n], v[n];
fo(i, n) cin >> wt[i] >> v[i];
fo(i, n + 1) {
fo(j, w + 1) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (wt[i - 1] <= j) {
dp[i][j] = max(v[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
}
|
replace
| 55 | 56 | 55 | 56 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define tel(a) \
{ cout << a << "\n"; }
#define tell(a, b) \
{ cout << a << " | " << b << "\n"; }
#define telll(a, b, c) \
{ cout << a << " | " << b << " | " << c << "\n"; }
#define teln(v, n) \
{ \
cout << "v- "; \
rep(i, 0, n) cout << v[i] << " "; \
cout << "\n"; \
}
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::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 trace(...)
#endif
#define M 110
#define N 100010
ll w[M], v[M];
ll dp[M][N];
ll f(ll pos, ll wt) {
if (wt < 0)
return -1 * inf;
if (pos < 0)
return 0;
if (dp[pos][wt] != -1)
return dp[pos][wt];
ll ans = max(f(pos - 1, wt), f(pos - 1, wt - w[pos]) + v[pos]);
trace(pos, wt, ans);
return dp[pos][wt] = ans;
}
int main() {
IOS;
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ll n, W;
cin >> n >> W;
rep(i, 0, n) cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
f(n - 1, W);
ll ans = -1;
rep(i, 0, N) ans = max(ans, dp[n - 1][i]);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define tel(a) \
{ cout << a << "\n"; }
#define tell(a, b) \
{ cout << a << " | " << b << "\n"; }
#define telll(a, b, c) \
{ cout << a << " | " << b << " | " << c << "\n"; }
#define teln(v, n) \
{ \
cout << "v- "; \
rep(i, 0, n) cout << v[i] << " "; \
cout << "\n"; \
}
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::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 trace(...)
#endif
#define M 110
#define N 100010
ll w[M], v[M];
ll dp[M][N];
ll f(ll pos, ll wt) {
if (wt < 0)
return -1 * inf;
if (pos < 0)
return 0;
if (dp[pos][wt] != -1)
return dp[pos][wt];
ll ans = max(f(pos - 1, wt), f(pos - 1, wt - w[pos]) + v[pos]);
// trace(pos,wt,ans);
return dp[pos][wt] = ans;
}
int main() {
IOS;
// freopen("inp.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
ll n, W;
cin >> n >> W;
rep(i, 0, n) cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
f(n - 1, W);
ll ans = -1;
rep(i, 0, N) ans = max(ans, dp[n - 1][i]);
cout << ans;
return 0;
}
|
replace
| 64 | 65 | 64 | 65 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
long long w, w_arr[100], v_arr[100], dp[101]; // (W+1)
memset(dp, 0, sizeof(dp));
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> w_arr[i] >> v_arr[i];
}
for (int i = 0; i < n; i++) {
for (long long j = w; j >= w_arr[i]; j--) {
dp[j] = max(dp[j], v_arr[i] + dp[j - w_arr[i]]);
}
}
cout << dp[w];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
long long w, w_arr[100], v_arr[100], dp[100001]; // (W+1)
memset(dp, 0, sizeof(dp));
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> w_arr[i] >> v_arr[i];
}
for (int i = 0; i < n; i++) {
for (long long j = w; j >= w_arr[i]; j--) {
dp[j] = max(dp[j], v_arr[i] + dp[j - w_arr[i]]);
}
}
cout << dp[w];
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
typedef long long ll;
const ll inf = 1LL << 60;
int n, W;
ll dp[100][100010];
ll w[110];
ll v[110];
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i][j] = dp[i + 1][j];
else {
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
}
}
}
cout << dp[0][W] << endl;
return 0;
}
|
#include <iostream>
using namespace std;
typedef long long ll;
const ll inf = 1LL << 60;
int n, W;
ll dp[110][100010] = {0};
ll w[110];
ll v[110];
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i][j] = dp[i + 1][j];
else {
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
}
}
}
cout << dp[0][W] << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// ok 理解
using namespace std;
using ll = long long;
ll n, W;
ll w[110], v[110];
vector<vector<ll>> dp(110, vector<ll>(110, -1));
ll rec(ll i, ll j) {
if (dp.at(i).at(j) != -1) {
return dp.at(i).at(j);
}
ll res = 0;
if (i == n) {
res = 0;
} else if (j < w[i]) {
res = rec(i + 1, j);
} else {
res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
}
// cout << "res" << i << ',' << j << "=" << res << endl;
return dp.at(i).at(j) = res;
}
int main() {
cin >> n >> W;
for (size_t i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << rec(0, W) << endl;
return 0;
}
|
#include <bits/stdc++.h>
// ok 理解
using namespace std;
using ll = long long;
ll n, W;
ll w[110], v[110];
vector<vector<ll>> dp(110, vector<ll>(100010, -1));
ll rec(ll i, ll j) {
if (dp.at(i).at(j) != -1) {
return dp.at(i).at(j);
}
ll res = 0;
if (i == n) {
res = 0;
} else if (j < w[i]) {
res = rec(i + 1, j);
} else {
res = max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
}
// cout << "res" << i << ',' << j << "=" << res << endl;
return dp.at(i).at(j) = res;
}
int main() {
cin >> n >> W;
for (size_t i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << rec(0, W) << endl;
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#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][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];
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i + 1])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
long long
dp[110][100010]; // dp[i][j]はi番目までの品物を重さjまでに入れたときの最大値
int main() {
int N;
int W;
int v[110], w[110];
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp初期条件
for (int j = 0; j <= W; j++)
dp[0][j] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W];
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03163
|
C++
|
Runtime Error
|
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
#define scan(x) \
do { \
while ((x = getchar_unlocked()) < '0') \
; \
for (x -= '0'; '0' <= (_ = getchar_unlocked()); \
x = (x << 3) + (x << 1) + _ - '0') \
; \
} while (0)
char _;
#define ll long long
#define ull unsigned long long
#define MAXM 10010
#define MAXN 110
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) < (b) ? (b) : (a)
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
#define mii map<int, int>
#define umii unordered_map<int, int>
#define allof(x) x.begin(), x.end()
#define DEBUG 1
// #define NOT_DMOJ 0
#ifdef DEBUG
#define D(x...) printf(x)
#else
#define D(x...)
#endif
using namespace std;
inline int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }
inline int LCM(int a, int b) { return a * b / GCD(a, b); }
inline ll PowMod(ll a, ll b, ll mod) {
ll val = 1;
while (b) {
if (b & 1)
val = (val * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return val;
}
ll N, W;
ll w[MAXN], v[MAXN];
ll DP[2][MAXM];
int main(int argc, char const *argv[]) {
#ifdef NOT_DMOJ
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // NOT_DMOJ
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < N; i++) {
for (int j = 1; j <= W; j++) {
DP[i & 1][j] = max(DP[i & 1][j - 1], DP[(i & 1) ^ 1][j]);
if (j >= w[i]) {
DP[i & 1][j] = max(DP[i & 1][j], DP[(i & 1) ^ 1][j - w[i]] + v[i]);
}
}
}
cout << DP[(N - 1) & 1][W] << "\n";
return 0;
}
/*
* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
|
#pragma GCC optimize "Ofast"
#pragma GCC optimize "unroll-loops"
#pragma GCC target "sse,sse2,sse3,sse4,abm,avx,mmx,popcnt,tune=native"
#include <bits/stdc++.h>
#define scan(x) \
do { \
while ((x = getchar_unlocked()) < '0') \
; \
for (x -= '0'; '0' <= (_ = getchar_unlocked()); \
x = (x << 3) + (x << 1) + _ - '0') \
; \
} while (0)
char _;
#define ll long long
#define ull unsigned long long
#define MAXM 100010
#define MAXN 110
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define min(a, b) (a) < (b) ? (a) : (b)
#define max(a, b) (a) < (b) ? (b) : (a)
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define f first
#define s second
#define mii map<int, int>
#define umii unordered_map<int, int>
#define allof(x) x.begin(), x.end()
#define DEBUG 1
// #define NOT_DMOJ 0
#ifdef DEBUG
#define D(x...) printf(x)
#else
#define D(x...)
#endif
using namespace std;
inline int GCD(int a, int b) { return b == 0 ? a : GCD(b, a % b); }
inline int LCM(int a, int b) { return a * b / GCD(a, b); }
inline ll PowMod(ll a, ll b, ll mod) {
ll val = 1;
while (b) {
if (b & 1)
val = (val * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return val;
}
ll N, W;
ll w[MAXN], v[MAXN];
ll DP[2][MAXM];
int main(int argc, char const *argv[]) {
#ifdef NOT_DMOJ
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif // NOT_DMOJ
cin.sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < N; i++) {
for (int j = 1; j <= W; j++) {
DP[i & 1][j] = max(DP[i & 1][j - 1], DP[(i & 1) ^ 1][j]);
if (j >= w[i]) {
DP[i & 1][j] = max(DP[i & 1][j], DP[(i & 1) ^ 1][j - w[i]] + v[i]);
}
}
}
cout << DP[(N - 1) & 1][W] << "\n";
return 0;
}
/*
* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#define ll long long
#define en "\n"
const ll inf = 1e9;
const ll mod = 1e9 + 7;
using namespace std;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
ll a[100005], b[100005], m, n, dp[100005] = {0};
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
for (int j = m; j > 0; j--) {
if (dp[j] != 0) {
dp[j + a[i]] = max(dp[j + a[i]], b[i] + dp[j]);
}
}
dp[a[i]] = max(dp[a[i]], b[i]);
}
ll mx = -inf * inf;
for (int i = m; i > 0; i--) {
mx = max(mx, dp[i]);
}
cout << mx << endl;
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#define ll long long
#define en "\n"
const ll inf = 1e9;
const ll mod = 1e9 + 7;
using namespace std;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
ll a[100005], b[100005], m, n, dp[300005] = {0};
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; i++) {
for (int j = m; j > 0; j--) {
if (dp[j] != 0) {
dp[j + a[i]] = max(dp[j + a[i]], b[i] + dp[j]);
}
}
dp[a[i]] = max(dp[a[i]], b[i]);
}
ll mx = -inf * inf;
for (int i = m; i > 0; i--) {
mx = max(mx, dp[i]);
}
cout << mx << endl;
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int mx = 1e5 + 123;
#define mem(a, b) memset(a, b, sizeof(a));
int w[120], v[120], W, n;
long long dp[120][mx];
long long solve(int i, int j) {
if (i > n)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
long long left = 0, right = 0;
if (j + w[i] <= W)
3;
left = v[i] + solve(i + 1, j + w[i]);
right = solve(i + 1, j);
return dp[i][j] = max(left, right);
}
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
mem(dp, -1);
cout << solve(1, 0) << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <list>
#include <queue>
#include <vector>
using namespace std;
const int mx = 1e5 + 123;
#define mem(a, b) memset(a, b, sizeof(a));
int w[120], v[120], W, n;
long long dp[120][mx];
long long solve(int i, int j) {
if (i > n)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
long long left = 0, right = 0;
if (j + w[i] <= W)
left = v[i] + solve(i + 1, j + w[i]);
right = solve(i + 1, j);
return dp[i][j] = max(left, right);
}
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
mem(dp, -1);
cout << solve(1, 0) << endl;
return 0;
}
|
replace
| 26 | 28 | 26 | 27 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[123456];
int N, W, price[123], wt[123];
int32_t main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> wt[i] >> price[i];
}
for (int i = 0; i < N; i++) {
for (int j = W - wt[i]; j >= 0; j--) {
dp[j + wt[i]] = max(dp[W + wt[i]], dp[j] + price[i]);
}
}
cout << dp[W] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[123456];
int N, W, price[123], wt[123];
int32_t main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> wt[i] >> price[i];
}
for (int i = 0; i < N; i++) {
for (int j = W - wt[i]; j >= 0; j--) {
dp[j + wt[i]] = max(dp[j + wt[i]], dp[j] + price[i]);
}
}
cout << dp[W] << "\n";
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<long> w(N);
vector<long> v(N);
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
vector<vector<long>> dp(N + 1, vector<long>(W + 1));
dp[0] = vector<long>(W);
for (int i = 0; i < N; i++) {
for (int j = 0; j < W + 1; j++) {
if (j < w[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
}
cout << dp[N][W] << endl;
return 1;
}
|
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, W;
cin >> N >> W;
vector<long> w(N);
vector<long> v(N);
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
vector<vector<long>> dp(N + 1, vector<long>(W + 1));
dp[0] = vector<long>(W);
for (int i = 0; i < N; i++) {
for (int j = 0; j < W + 1; j++) {
if (j < w[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
}
cout << dp[N][W] << endl;
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
1
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
using namespace std;
typedef long long ll;
static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;
//--global--//
//----------//
void print2dArray(vector<vector<ll>> vv, int a) {
rep(i, vv.size()) {
rep(j, a) {
if (i)
cout << " ";
cout << vv[i][j];
}
cout << endl;
}
}
int main(int argc, const char *argv[]) {
// 提出時、消す----//
//--------------//
int n, w;
cin >> n >> w;
vector<vector<ll>> vv(n + 1, vector<ll>(MAX + 1));
vector<ll> W(n);
vector<ll> V(n);
rep(i, n + 1) { fill(vv[i].begin(), vv[i].end(), -1); }
rep(i, n) { cin >> W[i] >> V[i]; }
vv[0][0] = 0;
rep2(i, 1, n + 1) {
vv[i][W[i - 1]] = max(vv[i][W[i - 1]], V[i - 1]);
rep(j, w + 1) {
if (vv[i - 1][j] != -1) {
vv[i][j] = max(vv[i - 1][j], vv[i][j]);
vv[i][j + W[i - 1]] = max(vv[i][j + W[i - 1]], vv[i - 1][j] + V[i - 1]);
}
}
}
// print2dArray(vv, w+1);
ll res = 0;
rep(i, w + 1) { res = max(vv[n][i], res); }
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, s, n) for (int i = s; i < (n); ++i)
using namespace std;
typedef long long ll;
static const int INTINF = (2147483647);
static const ll LLINF = (9223372036854775807);
static const int MAX = 100001;
static const ll MOD = 1000000007;
//--global--//
//----------//
void print2dArray(vector<vector<ll>> vv, int a) {
rep(i, vv.size()) {
rep(j, a) {
if (i)
cout << " ";
cout << vv[i][j];
}
cout << endl;
}
}
int main(int argc, const char *argv[]) {
// 提出時、消す----//
//--------------//
int n, w;
cin >> n >> w;
vector<vector<ll>> vv(n + 1, vector<ll>(MAX + 1));
vector<ll> W(n);
vector<ll> V(n);
rep(i, n + 1) { fill(vv[i].begin(), vv[i].end(), -1); }
rep(i, n) { cin >> W[i] >> V[i]; }
vv[0][0] = 0;
rep2(i, 1, n + 1) {
vv[i][W[i - 1]] = max(vv[i][W[i - 1]], V[i - 1]);
rep(j, w + 1) {
if (vv[i - 1][j] != -1) {
vv[i][j] = max(vv[i - 1][j], vv[i][j]);
if (j + W[i - 1] <= w)
vv[i][j + W[i - 1]] =
max(vv[i][j + W[i - 1]], vv[i - 1][j] + V[i - 1]);
}
}
}
// print2dArray(vv, w+1);
ll res = 0;
rep(i, w + 1) { res = max(vv[n][i], res); }
cout << res << endl;
return 0;
}
|
replace
| 47 | 48 | 47 | 50 |
0
| |
p03163
|
C++
|
Runtime Error
|
/*
@uthor: Amit Kumar
user -->GitHub: drviruses ; CodeChef: dr_virus_ ;
Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define all(vec) vec.begin(), vec.end()
ll google_itr = 1;
#define google(x) cout << "Case #" << x << ":"
#define pi 3.14159265358979323846264338327950L
const ll mod = 1e9 + 7;
const ll inf = 1e18;
void virus() {
ll len, wt;
cin >> len >> wt;
vector<ll> w, val;
for (auto i = 0; i < len; i++) {
ll a, b;
cin >> a >> b;
w.push_back(a);
val.push_back(b);
}
ll dp[len + 1][wt + 1];
for (auto i = 0; i <= len; i++) {
for (auto j = 0; j <= wt; j++) {
if (i == 0 or j == 0)
dp[i][j] = 0;
else if (w[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << (ll)dp[len][wt];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
ll t;
cin >> t;
while (t--) {
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
// cerr << "\nTime: "<<duration.count()<<endl;
// your code goes here
}
return 0;
}
|
/*
@uthor: Amit Kumar
user -->GitHub: drviruses ; CodeChef: dr_virus_ ;
Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// #define ln mp::cpp_int;
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define all(vec) vec.begin(), vec.end()
ll google_itr = 1;
#define google(x) cout << "Case #" << x << ":"
#define pi 3.14159265358979323846264338327950L
const ll mod = 1e9 + 7;
const ll inf = 1e18;
void virus() {
ll len, wt;
cin >> len >> wt;
vector<ll> w, val;
for (auto i = 0; i < len; i++) {
ll a, b;
cin >> a >> b;
w.push_back(a);
val.push_back(b);
}
ll dp[len + 1][wt + 1];
for (auto i = 0; i <= len; i++) {
for (auto j = 0; j <= wt; j++) {
if (i == 0 or j == 0)
dp[i][j] = 0;
else if (w[i - 1] <= j)
dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << (ll)dp[len][wt];
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
ll t = 1;
// cin>>t;
while (t--) {
auto start = high_resolution_clock::now();
virus();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<seconds>(stop - start);
// cerr << "\nTime: "<<duration.count()<<endl;
// your code goes here
}
return 0;
}
|
replace
| 58 | 60 | 58 | 60 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03163
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
long long dp[100][100010] = {0}; // N-1番目までで入れた容量の価値を最大にするもの
long long weight[110], value[110];
int main() {
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 sum_W = 0; sum_W <= W; ++sum_W) {
// i番目の商品を選ぶ
if (sum_W - weight[i] >= 0) {
if (dp[i + 1][sum_W] < dp[i][sum_W - weight[i]] + value[i]) {
dp[i + 1][sum_W] = dp[i][sum_W - weight[i]] + value[i];
}
}
if (dp[i + 1][sum_W] < dp[i][sum_W]) {
dp[i + 1][sum_W] = dp[i][sum_W];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
|
#include <iostream>
using namespace std;
long long dp[110][100010] = {0}; // N-1番目までで入れた容量の価値を最大にするもの
long long weight[110], value[110];
int main() {
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 sum_W = 0; sum_W <= W; ++sum_W) {
// i番目の商品を選ぶ
if (sum_W - weight[i] >= 0) {
if (dp[i + 1][sum_W] < dp[i][sum_W - weight[i]] + value[i]) {
dp[i + 1][sum_W] = dp[i][sum_W - weight[i]] + value[i];
}
}
if (dp[i + 1][sum_W] < dp[i][sum_W]) {
dp[i + 1][sum_W] = dp[i][sum_W];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
ll dp[2][100000 + 100];
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int main() {
int N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
REP(i, N) cin >> w[i] >> v[i];
ll *prev = dp[0], *next = dp[1];
REP(i, N) {
REP(j, W + 1) {
// chmax(next[j], prev[j]);
chmax(next[j + w[i]], prev[j] + v[i]);
chmax(next[j], prev[j]);
}
swap(prev, next);
}
cout << prev[W] << endl;
int t = 10;
}
|
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
ll dp[2][100000 + 100];
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int main() {
int N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
REP(i, N) cin >> w[i] >> v[i];
ll *prev = dp[0], *next = dp[1];
REP(i, N) {
REP(j, W + 1) {
// chmax(next[j], prev[j]);
if (j + w[i] < W + 10)
chmax(next[j + w[i]], prev[j] + v[i]);
chmax(next[j], prev[j]);
}
swap(prev, next);
}
cout << prev[W] << endl;
int t = 10;
}
|
replace
| 24 | 25 | 24 | 26 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
ll N, W;
ll w[105], v[105];
vector<vector<ll>> dp(105, vector<ll>(10005, 0));
void knapsack() {
rep(i, N) rep(j, W) {
if (j + w[i] <= W) {
chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
chmax(dp[i + 1][j], dp[i][j]);
}
}
int main() {
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
knapsack();
ll ans = 0;
rep(i, W + 1) chmax(ans, dp[N][i]);
PRINT(ans);
}
|
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
ll N, W;
ll w[105], v[105];
vector<vector<ll>> dp(105, vector<ll>(100005, 0));
void knapsack() {
rep(i, N) rep(j, W) {
if (j + w[i] <= W) {
chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
chmax(dp[i + 1][j], dp[i][j]);
}
}
int main() {
cin >> N >> W;
rep(i, N) cin >> w[i] >> v[i];
knapsack();
ll ans = 0;
rep(i, W + 1) chmax(ans, dp[N][i]);
PRINT(ans);
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll t[105][10005];
vector<int> wt, val;
ll knapsack(int n, int w) {
if (n == 0 || w == 0)
return 0;
if (t[n][w] != -1)
return t[n][w];
if (wt[n - 1] <= w) {
return t[n][w] = max(val[n - 1] + knapsack(n - 1, w - wt[n - 1]),
knapsack(n - 1, w));
} else
return t[n][w] = knapsack(n - 1, w);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
memset(t, -1, sizeof(t));
int n, w;
cin >> n >> w;
wt.resize(n);
val.resize(n);
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << knapsack(n, w) << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll t[105][100005];
vector<int> wt, val;
ll knapsack(int n, int w) {
if (n == 0 || w == 0)
return 0;
if (t[n][w] != -1)
return t[n][w];
if (wt[n - 1] <= w) {
return t[n][w] = max(val[n - 1] + knapsack(n - 1, w - wt[n - 1]),
knapsack(n - 1, w));
} else
return t[n][w] = knapsack(n - 1, w);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
memset(t, -1, sizeof(t));
int n, w;
cin >> n >> w;
wt.resize(n);
val.resize(n);
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << knapsack(n, w) << "\n";
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03163
|
C++
|
Runtime Error
|
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll, ll>
#define ppp pair<ll, pp>
#define trace(...) \
cout << "Line:" << __LINE__ << " "; \
__f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
typedef tree<pp, null_type, less<pp>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for (ll i = a; i < b; i += 1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld", &x)
ll t = 1, tt;
const ll inf = 1e18, N = 100005;
ll dp[100][N];
inline ll mult(ll x, ll y) {
x %= hell;
y %= hell;
return (1LL * x * y) % hell;
}
inline ll add(ll x, ll y) {
x += y;
return x % hell;
}
inline ll powMod(ll base, ll expo) {
if (base == 0)
return 0;
ll ans = 1;
while (expo) {
if (expo & 1)
ans = mult(ans, base);
base = mult(base, base);
expo >>= 1;
}
return ans;
}
void solve() {
memset(dp, -1, sizeof dp);
ll n, k;
cin >> n >> k;
dp[0][0] = 0;
vector<ll> a(n + 1), b(n + 1);
rep(i, 1, n + 1) {
cin >> a[i] >> b[i];
rep(j, 0, k + 1) {
dp[i][j] = dp[i - 1][j];
if (a[i] <= j and dp[i - 1][j - a[i]] != -1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] + b[i]);
}
}
}
ll ans = 0;
rep(i, 0, k + 1) ans = max(ans, dp[n][i]);
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// cin>>t;
tt = t;
while (t--) {
solve();
if (t)
cout << "\n";
}
return 0;
}
|
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll, ll>
#define ppp pair<ll, pp>
#define trace(...) \
cout << "Line:" << __LINE__ << " "; \
__f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
typedef tree<pp, null_type, less<pp>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for (ll i = a; i < b; i += 1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld", &x)
ll t = 1, tt;
const ll inf = 1e18, N = 100005;
ll dp[105][N];
inline ll mult(ll x, ll y) {
x %= hell;
y %= hell;
return (1LL * x * y) % hell;
}
inline ll add(ll x, ll y) {
x += y;
return x % hell;
}
inline ll powMod(ll base, ll expo) {
if (base == 0)
return 0;
ll ans = 1;
while (expo) {
if (expo & 1)
ans = mult(ans, base);
base = mult(base, base);
expo >>= 1;
}
return ans;
}
void solve() {
memset(dp, -1, sizeof dp);
ll n, k;
cin >> n >> k;
dp[0][0] = 0;
vector<ll> a(n + 1), b(n + 1);
rep(i, 1, n + 1) {
cin >> a[i] >> b[i];
rep(j, 0, k + 1) {
dp[i][j] = dp[i - 1][j];
if (a[i] <= j and dp[i - 1][j - a[i]] != -1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i]] + b[i]);
}
}
}
ll ans = 0;
rep(i, 0, k + 1) ans = max(ans, dp[n][i]);
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// cin>>t;
tt = t;
while (t--) {
solve();
if (t)
cout << "\n";
}
return 0;
}
|
replace
| 35 | 36 | 35 | 36 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
int main() {
int n, w;
cin >> n >> w;
vector<ll> v(n);
vector<ll> m(n);
rep(i, n) cin >> m.at(i) >> v.at(i);
vector<vector<ll>> dp(100, vector<ll>(100000));
for (int i = 0; i < n; i++) {
for (int j = 1; j <= w; j++) {
if (j - m.at(i) >= 0) {
dp.at(i + 1).at(j) =
max(dp.at(i + 1).at(j), dp.at(i).at(j - m.at(i)) + v.at(i));
}
dp.at(i + 1).at(j) = max(dp.at(i + 1).at(j), dp.at(i).at(j));
}
}
cout << dp.at(n).at(w) << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
int main() {
int n, w;
cin >> n >> w;
vector<ll> v(n);
vector<ll> m(n);
rep(i, n) cin >> m.at(i) >> v.at(i);
vector<vector<ll>> dp(110, vector<ll>(100010));
for (int i = 0; i < n; i++) {
for (int j = 1; j <= w; j++) {
if (j - m.at(i) >= 0) {
dp.at(i + 1).at(j) =
max(dp.at(i + 1).at(j), dp.at(i).at(j - m.at(i)) + v.at(i));
}
dp.at(i + 1).at(j) = max(dp.at(i + 1).at(j), dp.at(i).at(j));
}
}
cout << dp.at(n).at(w) << endl;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define from(i, n) for (int i = 1; i <= (int)n; i++)
#define from_j(i, j, n) for (int i = j; i < (int)n; i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int max_value[101][100001] = {0};
int weight[101];
int value[101];
int n, w;
void solve() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (weight[i] <= j) {
int temp = value[i] + max_value[i - 1][j - weight[i]];
max_value[i][j] = max(temp, max_value[i - 1][j]);
} else {
max_value[i][j] = max_value[i - 1][j];
}
// cout<<i<<" "<<j<<" "<<max_value[i][j]<<"\n";
}
}
}
int32_t main() {
c_p_c();
cin >> n >> w;
from(i, n) cin >> weight[i] >> value[i];
// from(i,n)
solve();
cout << max_value[n][w];
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
#define from(i, n) for (int i = 1; i <= (int)n; i++)
#define from_j(i, j, n) for (int i = j; i < (int)n; i++)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int max_value[101][100001] = {0};
int weight[101];
int value[101];
int n, w;
void solve() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (weight[i] <= j) {
int temp = value[i] + max_value[i - 1][j - weight[i]];
max_value[i][j] = max(temp, max_value[i - 1][j]);
} else {
max_value[i][j] = max_value[i - 1][j];
}
// cout<<i<<" "<<j<<" "<<max_value[i][j]<<"\n";
}
}
}
int32_t main() {
c_p_c();
cin >> n >> w;
from(i, n) cin >> weight[i] >> value[i];
// from(i,n)
solve();
cout << max_value[n][w];
return 0;
}
|
delete
| 37 | 41 | 37 | 37 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 112;
ll n, c, w[MN], v[MN], dp[MN][MN];
int main(void) {
cin >> n >> c;
for (ll i = 0; i < n; i++)
cin >> w[i] >> v[i];
for (ll cc = 1; cc <= c; cc++) {
for (ll i = 1; i <= n; i++) {
ll cw = w[i - 1], cv = v[i - 1];
if (cw > cc)
dp[cc][i] = dp[cc][i - 1];
else
dp[cc][i] = max(dp[cc][i - 1], dp[cc - cw][i - 1] + cv);
}
}
cout << dp[c][n] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 112;
const int MW = 100012;
ll n, c, w[MN], v[MN], dp[MW][MN];
int main(void) {
cin >> n >> c;
for (ll i = 0; i < n; i++)
cin >> w[i] >> v[i];
for (ll cc = 1; cc <= c; cc++) {
for (ll i = 1; i <= n; i++) {
ll cw = w[i - 1], cv = v[i - 1];
if (cw > cc)
dp[cc][i] = dp[cc][i - 1];
else
dp[cc][i] = max(dp[cc][i - 1], dp[cc - cw][i - 1] + cv);
}
}
cout << dp[c][n] << "\n";
}
|
replace
| 4 | 5 | 4 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define f first
#define s second
#define MM INT_MAX / 5
#define MIM INT_MIN / 2
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define v vector
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize
#define MAX (int)1e5 + 1
ll vals[101];
int weights[MAX];
ll dp[101];
int main() {
for (int i = 0; i < 101; i++)
dp[i] = -1;
int N, W;
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> weights[i];
cin >> vals[i];
}
dp[0] = 0;
for (int i = 1; i <= N; i++)
for (int j = W; j >= 0; j--) {
if (dp[j] >= 0 && j + weights[i] <= W)
dp[j + weights[i]] = max(dp[j] + vals[i], dp[j + weights[i]]);
}
ll ans = -1;
for (int i = W; i > 0; i--)
ans = max(ans, dp[i]);
cout << ans;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define f first
#define s second
#define MM INT_MAX / 5
#define MIM INT_MIN / 2
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define v vector
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize
#define MAX (int)1e5 + 1
ll vals[101];
int weights[101];
ll dp[MAX];
int main() {
for (int i = 0; i < 101; i++)
dp[i] = -1;
int N, W;
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> weights[i];
cin >> vals[i];
}
dp[0] = 0;
for (int i = 1; i <= N; i++)
for (int j = W; j >= 0; j--) {
if (dp[j] >= 0 && j + weights[i] <= W)
dp[j + weights[i]] = max(dp[j] + vals[i], dp[j + weights[i]]);
}
ll ans = -1;
for (int i = W; i > 0; i--)
ans = max(ans, dp[i]);
cout << ans;
}
|
replace
| 45 | 47 | 45 | 47 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<int, int>
#define mp make_pair
using namespace std;
int n;
ll memo[101][10005];
ll a[105];
ll w[105];
ll solve(int i, int sum) {
if (i == n) {
return 0;
}
ll &ret = memo[i][sum];
if (ret != -1)
return ret;
ret = 0;
if (sum >= w[i]) {
ret = max(ret, a[i] + solve(i + 1, sum - w[i]));
}
ret = max(ret, solve(i + 1, sum));
return ret;
}
int main() {
memset(memo, -1, sizeof(memo));
int x;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> w[i] >> a[i];
}
cout << solve(0, x);
}
|
#include <bits/stdc++.h>
#define pb push_back
#define sc second
#define fr first
#define mk make_pair
#define ll long long
#define ii pair<int, int>
#define mp make_pair
using namespace std;
int n;
ll memo[101][100005];
ll a[105];
ll w[105];
ll solve(int i, int sum) {
if (i == n) {
return 0;
}
ll &ret = memo[i][sum];
if (ret != -1)
return ret;
ret = 0;
if (sum >= w[i]) {
ret = max(ret, a[i] + solve(i + 1, sum - w[i]));
}
ret = max(ret, solve(i + 1, sum));
return ret;
}
int main() {
memset(memo, -1, sizeof(memo));
int x;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> w[i] >> a[i];
}
cout << solve(0, x);
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = (ll)(1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) \
for (auto a_ : x_) \
cerr << a_ << " "; \
cerr << endl;
#define dbg3(x_, sx_) \
rep(i, sx_) cerr << x_[i] << " "; \
cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
//------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, W;
cin >> n >> W;
ll w[n], v[n];
rep(i, n) cin >> w[i] >> v[i];
map<ll, map<ll, ll>> mp;
set<ll> for_search; // 重さ
for_search.insert(W);
rep(i, n) {
set<ll> temp;
for (auto wi : for_search) {
if (wi - w[i] >= 0) {
mp[i + 1][wi - w[i]] = max(mp[i][wi - w[i]], mp[i][wi] + v[i]);
temp.insert(wi - w[i]);
}
mp[i + 1][wi] = max(mp[i + 1][wi], mp[i][wi]);
}
for (auto a : temp)
for_search.insert(a);
}
ll ans = 0;
for (ll i = 0; i <= W; ++i)
ans = max(ans, mp[n][i]);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using multiInt = boost::multiprecision::cpp_int;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_temp>
using smaller_queue = priority_queue<Q_temp, vector<Q_temp>, greater<Q_temp>>;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = (ll)(1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;
#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) \
for (auto a_ : x_) \
cerr << a_ << " "; \
cerr << endl;
#define dbg3(x_, sx_) \
rep(i, sx_) cerr << x_[i] << " "; \
cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};
//------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, W;
cin >> n >> W;
ll w[n], v[n];
rep(i, n) cin >> w[i] >> v[i];
ll mp[n + 1][W + 1] = {};
set<ll> for_search; // 重さ
for_search.insert(W);
rep(i, n) {
set<ll> temp;
for (auto wi : for_search) {
if (wi - w[i] >= 0) {
mp[i + 1][wi - w[i]] = max(mp[i][wi - w[i]], mp[i][wi] + v[i]);
temp.insert(wi - w[i]);
}
mp[i + 1][wi] = max(mp[i + 1][wi], mp[i][wi]);
}
for (auto a : temp)
for_search.insert(a);
}
ll ans = 0;
for (ll i = 0; i <= W; ++i)
ans = max(ans, mp[n][i]);
cout << ans << endl;
return 0;
}
|
replace
| 47 | 48 | 47 | 48 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define maxn 100
#define maxw 10001
int main() {
long long n, w;
cin >> n >> w;
long long dp[maxn][maxw], weight[maxn], val[maxn];
for (long long i = 0; i < n; i++)
cin >> weight[i] >> val[i];
for (long long i = 0; i <= w; i++)
dp[0][i] = 0;
dp[0][w - weight[0]] = val[0];
for (long long i = 1; i < n; i++) {
for (long long j = 0; j <= w; j++) {
if (j + weight[i] > w)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(val[i] + dp[i - 1][j + weight[i]], dp[i - 1][j]);
}
}
long long max = 0;
for (long long i = 0; i <= w; i++) {
if (dp[n - 1][i] > max)
max = dp[n - 1][i];
}
cout << max;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define maxn 100
#define maxw 100001
int main() {
long long n, w;
cin >> n >> w;
long long dp[maxn][maxw], weight[maxn], val[maxn];
for (long long i = 0; i < n; i++)
cin >> weight[i] >> val[i];
for (long long i = 0; i <= w; i++)
dp[0][i] = 0;
dp[0][w - weight[0]] = val[0];
for (long long i = 1; i < n; i++) {
for (long long j = 0; j <= w; j++) {
if (j + weight[i] > w)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(val[i] + dp[i - 1][j + weight[i]], dp[i - 1][j]);
}
}
long long max = 0;
for (long long i = 0; i <= w; i++) {
if (dp[n - 1][i] > max)
max = dp[n - 1][i];
}
cout << max;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
template <class T> inline bool chmax(T &a, const T &b) {
return (a < b) ? a = b, true : false;
}
int main() {
int N;
int W;
std::cin >> N >> W;
std::vector<int> w(N);
std::vector<long long> v(N);
for (int i = 0; i < N; ++i)
std::cin >> w[i] >> v[i];
// dp[i][j] = i 個までで重さ j 以下の場合の価値の最大値
std::vector<std::vector<long long>> dp(N + 7,
std::vector<long long>(W + 7, 0LL));
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= W; ++j) {
chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
chmax(dp[i + 1][j], dp[i][j]);
}
}
std::cout << dp[N][W] << std::endl;
}
|
#include <iostream>
#include <vector>
template <class T> inline bool chmax(T &a, const T &b) {
return (a < b) ? a = b, true : false;
}
int main() {
int N;
int W;
std::cin >> N >> W;
std::vector<int> w(N);
std::vector<long long> v(N);
for (int i = 0; i < N; ++i)
std::cin >> w[i] >> v[i];
// dp[i][j] = i 個までで重さ j 以下の場合の価値の最大値
std::vector<std::vector<long long>> dp(
N + 7, std::vector<long long>(2 * W + 7, 0LL));
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= W; ++j) {
chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
chmax(dp[i + 1][j], dp[i][j]);
}
}
std::cout << dp[N][W] << std::endl;
}
|
replace
| 18 | 20 | 18 | 20 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long dp[610];
int w[610], v[610];
int N, W;
int main() {
cin >> N >> W;
for (int i = 1; i <= N; i++)
cin >> w[i] >> v[i];
dp[0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = W - w[i]; j >= 0; j--) {
dp[j + w[i]] = max(dp[j] + v[i], dp[j + w[i]]);
}
}
cout << dp[W] << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[100100];
int w[100100], v[100100];
int N, W;
int main() {
cin >> N >> W;
for (int i = 1; i <= N; i++)
cin >> w[i] >> v[i];
dp[0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = W - w[i]; j >= 0; j--) {
dp[j + w[i]] = max(dp[j] + v[i], dp[j + w[i]]);
}
}
cout << dp[W] << '\n';
}
|
replace
| 4 | 6 | 4 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define f .first
#define s .second
using namespace std;
using ll = long long;
int n, W;
pair<ll, ll> item[105];
ll dp[10005], maxv;
int main() {
cin >> n >> W;
for (int i = 1; i <= n; ++i) {
cin >> item[i] f >> item[i] s;
}
for (int i = 0; i <= W; ++i) {
dp[i] = -1;
}
sort(item + 1, item + 1 + n);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = W; j >= item[i] f; --j) {
if (dp[j - item[i] f] != -1) {
dp[j] = max(dp[j], dp[j - item[i] f] + item[i] s);
}
}
}
for (int i = 1; i <= W; ++i) {
maxv = max(maxv, dp[i]);
}
cout << maxv << '\n';
return 0;
}
|
#include <bits/stdc++.h>
#define f .first
#define s .second
using namespace std;
using ll = long long;
int n, W;
pair<ll, ll> item[100005];
ll dp[100005], maxv;
int main() {
cin >> n >> W;
for (int i = 1; i <= n; ++i) {
cin >> item[i] f >> item[i] s;
}
for (int i = 0; i <= W; ++i) {
dp[i] = -1;
}
sort(item + 1, item + 1 + n);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = W; j >= item[i] f; --j) {
if (dp[j - item[i] f] != -1) {
dp[j] = max(dp[j], dp[j - item[i] f] + item[i] s);
}
}
}
for (int i = 1; i <= W; ++i) {
maxv = max(maxv, dp[i]);
}
cout << maxv << '\n';
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
const int N = 1e18;
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS;
int n, W, x, y;
cin >> n >> W;
int w[n + 1], v[n + 1], dp[n + 1][W + 1];
for (int i = 1; i <= n; i++) {
cin >> x >> y;
w[i] = x;
v[i] = y;
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= W; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
if (w[i] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
}
cout << dp[n][W] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
const int N = 1e18;
int32_t main() {
IOS;
int n, W, x, y;
cin >> n >> W;
int w[n + 1], v[n + 1], dp[n + 1][W + 1];
for (int i = 1; i <= n; i++) {
cin >> x >> y;
w[i] = x;
v[i] = y;
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= W; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= W; j++) {
if (w[i] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
}
cout << dp[n][W] << endl;
return 0;
}
|
delete
| 14 | 18 | 14 | 14 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
long N, W;
long w[100], v[100];
long dp[100][100000];
int main() {
cin >> N >> W;
for (int i = 0; i < N; ++i)
cin >> w[i] >> v[i];
// initialize
for (int j = 0; j <= W; ++j)
dp[0][j] = 0;
// dp
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= W; ++j) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W] << endl;
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
long N, W;
long w[110], v[110];
long dp[110][100100];
int main() {
cin >> N >> W;
for (int i = 0; i < N; ++i)
cin >> w[i] >> v[i];
// initialize
for (int j = 0; j <= W; ++j)
dp[0][j] = 0;
// dp
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= W; ++j) {
if (j >= w[i])
dp[i + 1][j] = max(dp[i][j - w[i]] + v[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W] << endl;
return 0;
}
|
replace
| 10 | 12 | 10 | 12 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef int in;
#define int long long
int MAX = 1e9;
int MAXEST = 1e18;
int MOD = 1e9 + 7;
int n, w;
int v[105], s[105];
int dp[2][100005];
in main() {
int tc = 1;
// cin>>tc;
while (tc--) {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> s[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i & 1][j] = dp[(i - 1) & 1][j];
if (j >= s[i])
dp[i & 1][j] = max(dp[i & 1][j], dp[(i - 1) & 1][j - s[i]] + v[i]);
}
}
cout << dp[n][w] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef int in;
#define int long long
int MAX = 1e9;
int MAXEST = 1e18;
int MOD = 1e9 + 7;
int n, w;
int v[105], s[105];
int dp[2][100005];
in main() {
int tc = 1;
// cin>>tc;
while (tc--) {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> s[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= w; j++) {
dp[i & 1][j] = dp[(i - 1) & 1][j];
if (j >= s[i])
dp[i & 1][j] = max(dp[i & 1][j], dp[(i - 1) & 1][j - s[i]] + v[i]);
}
}
cout << dp[n & 1][w] << endl;
}
return 0;
}
|
replace
| 28 | 29 | 28 | 29 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[105][105], weight[105], value[105];
int n, cap;
int main() {
cin >> n >> cap;
for (int i = 1; i <= n; i++) {
ll x, y;
cin >> x >> y;
weight[i] = x;
value[i] = y;
}
for (int i = 1; i <= n; i++) {
ll w = weight[i], v = value[i];
for (int j = 1; j <= cap; j++) {
if (j >= w) {
ll hold = dp[i - 1][j - w] + v;
dp[i][j] = dp[i - 1][j] > hold ? dp[i - 1][j] : hold;
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][cap] << endl;
return 0;
}
|
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[105][100005], weight[105], value[105];
int n, cap;
int main() {
cin >> n >> cap;
for (int i = 1; i <= n; i++) {
ll x, y;
cin >> x >> y;
weight[i] = x;
value[i] = y;
}
for (int i = 1; i <= n; i++) {
ll w = weight[i], v = value[i];
for (int j = 1; j <= cap; j++) {
if (j >= w) {
ll hold = dp[i - 1][j - w] + v;
dp[i][j] = dp[i - 1][j] > hold ? dp[i - 1][j] : hold;
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][cap] << endl;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
long long knapsack(int *w, int *v, vector<vector<long long>> &dp, int i,
int maxw) {
if (maxw <= 0)
return 0;
if (i < 0)
return 0;
if (dp[i][maxw] != -1)
return dp[i][maxw];
if (w[i] <= maxw) {
dp[i][maxw] = max(knapsack(w, v, dp, i - 1, maxw),
knapsack(w, v, dp, i - 1, maxw - w[i]) + v[i]);
} else {
dp[i][maxw] = knapsack(w, v, dp, i - 1, maxw);
}
return dp[i][maxw];
}
int main() {
int n;
cin >> n;
int maxw;
cin >> maxw;
vector<long long> t(10001, -1);
vector<vector<long long>> dp(101, t);
int w[n];
int v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(w, v, dp, n - 1, maxw);
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
long long knapsack(int *w, int *v, vector<vector<long long>> &dp, int i,
int maxw) {
if (maxw <= 0)
return 0;
if (i < 0)
return 0;
if (dp[i][maxw] != -1)
return dp[i][maxw];
if (w[i] <= maxw) {
dp[i][maxw] = max(knapsack(w, v, dp, i - 1, maxw),
knapsack(w, v, dp, i - 1, maxw - w[i]) + v[i]);
} else {
dp[i][maxw] = knapsack(w, v, dp, i - 1, maxw);
}
return dp[i][maxw];
}
int main() {
int n;
cin >> n;
int maxw;
cin >> maxw;
vector<long long> t(100001, -1);
vector<vector<long long>> dp(101, t);
int w[n];
int v[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(w, v, dp, n - 1, maxw);
return 0;
}
|
replace
| 28 | 29 | 28 | 29 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
typedef pair<ll, ll> P;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
bool comp(pair<ll, ll> p1, pair<ll, ll> p2) {
if (p1.first < p2.first)
return true;
else if (p1.first == p2.first && p1.second >= p2.second)
return true;
return false;
}
int main() {
ll n, w, i, a, b, j;
cin >> n >> w;
vector<pair<ll, ll>> V;
for (i = 0; i < n; i++) {
cin >> a >> b;
V.push_back(make_pair(a, b));
}
sort(V.begin(), V.end(), comp);
ll DP[n + 1][w + 1];
memset(DP, 0, sizeof(DP));
for (i = 1; i <= n; i++) {
for (j = 1; j <= w; j++) {
if (j >= V[i - 1].first) {
DP[i][j] = max(max(DP[i - 1][j], DP[i][j - 1]),
V[i - 1].second + DP[i - 1][j - V[i - 1].first]);
} else {
DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
}
}
}
/*
for(i=0;i<=n;i++)
{
for(j=0;j<=w;j++)
{
cout<<DP[i][j]<<" ";
}
cout<<endl;
} */
cout << DP[n][w] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
typedef pair<ll, ll> P;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
bool comp(pair<ll, ll> p1, pair<ll, ll> p2) {
if (p1.first < p2.first)
return true;
else if (p1.first == p2.first && p1.second >= p2.second)
return true;
return false;
}
int main() {
ll n, w, i, a, b, j;
cin >> n >> w;
vector<pair<ll, ll>> V;
for (i = 0; i < n; i++) {
cin >> a >> b;
V.push_back(make_pair(a, b));
}
sort(V.begin(), V.end());
ll DP[n + 1][w + 1];
memset(DP, 0, sizeof(DP));
for (i = 1; i <= n; i++) {
for (j = 1; j <= w; j++) {
if (j >= V[i - 1].first) {
DP[i][j] = max(max(DP[i - 1][j], DP[i][j - 1]),
V[i - 1].second + DP[i - 1][j - V[i - 1].first]);
} else {
DP[i][j] = max(DP[i - 1][j], DP[i][j - 1]);
}
}
}
/*
for(i=0;i<=n;i++)
{
for(j=0;j<=w;j++)
{
cout<<DP[i][j]<<" ";
}
cout<<endl;
} */
cout << DP[n][w] << endl;
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long int lmax(long long int a, long long int b) {
if (a < b)
return b;
else
return a;
}
int main() {
long long int n, W;
cin >> n >> W;
vector<long long int> w(n);
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long int>> dp(n + 1, vector<long long int>(W, 0));
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i + 1][j] = lmax(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;
long long int lmax(long long int a, long long int b) {
if (a < b)
return b;
else
return a;
}
int main() {
long long int n, W;
cin >> n >> W;
vector<long long int> w(n);
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<long long int>> dp(n + 1, vector<long long int>(W + 1, 0));
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i + 1][j] = lmax(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;
}
|
replace
| 17 | 18 | 17 | 18 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower);
using namespace std;
typedef vector<vector<lli>> matrix;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;
lli n, w;
lli W[102], V[102];
lli cache[101][N];
lli dp(lli idx, lli weight) {
if (idx > n + 1) {
return 0;
}
lli &ans = cache[idx][weight];
if (ans != -1) {
return ans;
}
if (weight >= W[idx])
ans = max(V[idx] + dp(idx + 1, weight - W[idx]), dp(idx + 1, weight));
else
ans = dp(idx + 1, weight);
return ans;
}
void solve() {
cin >> n >> w;
memset(cache, -1, sizeof cache);
for (int i = 1; i <= n; i++) {
cin >> W[i] >> V[i];
}
lli ans = dp(1, w);
cout << ans;
cout << "\n";
return;
}
/*
*/
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(), a.end(), a.begin(), ::tolower);
using namespace std;
typedef vector<vector<lli>> matrix;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;
lli n, w;
lli W[102], V[102];
lli cache[101][N];
lli dp(lli idx, lli weight) {
if (idx > n) {
return 0;
}
lli &ans = cache[idx][weight];
if (ans != -1) {
return ans;
}
if (weight >= W[idx])
ans = max(V[idx] + dp(idx + 1, weight - W[idx]), dp(idx + 1, weight));
else
ans = dp(idx + 1, weight);
return ans;
}
void solve() {
cin >> n >> w;
memset(cache, -1, sizeof cache);
for (int i = 1; i <= n; i++) {
cin >> W[i] >> V[i];
}
lli ans = dp(1, w);
cout << ans;
cout << "\n";
return;
}
/*
*/
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
replace
| 49 | 50 | 49 | 50 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll s, n;
cin >> s >> n;
ll size[n];
ll value[n];
for (ll i = 0; i < n; i++)
cin >> size[i] >> value[i];
ll dp[n + 1][s + 1];
for (ll i = 0; i < n + 1; i++) {
for (ll j = 0; j < s + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (ll i = 1; i < n + 1; i++) {
for (ll j = 1; j < s + 1; j++) {
if (size[i - 1] <= j) {
// cout<<value[i-1]<<" value "<< dp[i-1][j-size[i-1]]<<endl;
// cout<<value[i-1]+dp[i-1][j-value[i-1]]<<" val "<<dp[i-1][j]<<endl;
dp[i][j] = max(value[i - 1] + dp[i - 1][j - size[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
/*for(ll i=0;i<n+1;i++)
{
for(ll j=0;j<s+1;j++)
{
cout<<dp[i][j]<<" "<<;
}
cout<<endl;
}*/
cout << dp[n][s];
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, s;
cin >> n >> s;
ll size[n];
ll value[n];
for (ll i = 0; i < n; i++)
cin >> size[i] >> value[i];
ll dp[n + 1][s + 1];
for (ll i = 0; i < n + 1; i++) {
for (ll j = 0; j < s + 1; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
}
}
for (ll i = 1; i < n + 1; i++) {
for (ll j = 1; j < s + 1; j++) {
if (size[i - 1] <= j) {
// cout<<value[i-1]<<" value "<< dp[i-1][j-size[i-1]]<<endl;
// cout<<value[i-1]+dp[i-1][j-value[i-1]]<<" val "<<dp[i-1][j]<<endl;
dp[i][j] = max(value[i - 1] + dp[i - 1][j - size[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
// cout<<dp[i][j]<<" ";
}
// cout<<endl;
}
/*for(ll i=0;i<n+1;i++)
{
for(ll j=0;j<s+1;j++)
{
cout<<dp[i][j]<<" "<<;
}
cout<<endl;
}*/
cout << dp[n][s];
return 0;
}
|
replace
| 9 | 11 | 9 | 11 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using llong = long long;
llong N, W;
llong w[105], v[105];
llong dp[105][105];
int main() {
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using llong = long long;
llong N, W;
llong w[105], v[105];
llong dp[105][100005];
int main() {
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N][W] << endl;
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03163
|
C++
|
Runtime Error
|
// #include <stdio.h>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
vector<vector<ll>> dp;
vector<ll> w, v;
ll N, W;
ll res(ll i, ll j) {
if (i >= N) {
return 0;
}
if (dp.at(i).at(j) != -1) {
return dp.at(i).at(j);
}
ll ret;
if (w.at(i) > j) {
ret = res(i + 1, j);
} else {
ret = max(res(i + 1, j), res(i + 1, j - w.at(i)) + v.at(i));
}
return dp.at(i).at(j) = ret;
}
void solve() {
cin >> N >> W;
dp = vector<vector<ll>>(N, vector<ll>(100000, -1));
w = vector<ll>(N);
v = vector<ll>(N);
for (ll i = 0; i < N; i++) {
cin >> w.at(i) >> v.at(i);
}
cout << res(0, W) << endl;
return;
}
int main() {
solve();
return 0;
}
|
// #include <stdio.h>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
vector<vector<ll>> dp;
vector<ll> w, v;
ll N, W;
ll res(ll i, ll j) {
if (i >= N) {
return 0;
}
if (dp.at(i).at(j) != -1) {
return dp.at(i).at(j);
}
ll ret;
if (w.at(i) > j) {
ret = res(i + 1, j);
} else {
ret = max(res(i + 1, j), res(i + 1, j - w.at(i)) + v.at(i));
}
return dp.at(i).at(j) = ret;
}
void solve() {
cin >> N >> W;
dp = vector<vector<ll>>(N, vector<ll>(1000000, -1));
w = vector<ll>(N);
v = vector<ll>(N);
for (ll i = 0; i < N; i++) {
cin >> w.at(i) >> v.at(i);
}
cout << res(0, W) << endl;
return;
}
int main() {
solve();
return 0;
}
|
replace
| 38 | 39 | 38 | 39 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int m = 2000000;
vi arr(105);
vi wrr(105);
int dp[105][100005];
int memo(int n, int w) {
if (n == 0 || w <= 0) {
return dp[n][w] = 0;
}
if (dp[n][w] != -1)
return dp[n][w];
// if(arr[n]>w)
// return dp[n][w]=memo(n-1,w);
return dp[n][w] = max((memo(n - 1, w - arr[n]) + wrr[n]), memo(n - 1, w));
}
int32_t main() {
c_p_c();
memset(dp, -1, sizeof(dp));
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
cin >> wrr[i];
}
int x = memo(n, w);
cout << dp[n][w];
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int m = 2000000;
vi arr(105);
vi wrr(105);
int dp[105][100005];
int memo(int n, int w) {
if (n == 0 || w <= 0) {
return dp[n][w] = 0;
}
if (dp[n][w] != -1)
return dp[n][w];
if (arr[n] > w)
return dp[n][w] = memo(n - 1, w);
return dp[n][w] = max((memo(n - 1, w - arr[n]) + wrr[n]), memo(n - 1, w));
}
int32_t main() {
c_p_c();
memset(dp, -1, sizeof(dp));
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
cin >> wrr[i];
}
int x = memo(n, w);
cout << dp[n][w];
return 0;
}
|
replace
| 46 | 48 | 46 | 48 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int m = 2000000;
vi arr(105);
vi wrr(105);
int dp[105][100005];
int memo(int n, int w) {
if (n == 0 || w <= 0) {
return dp[n][w] = 0;
}
if (arr[n] > w)
return dp[n][w] = memo(n - 1, w);
return dp[n][w] = max((memo(n - 1, w - arr[n]) + wrr[n]), memo(n - 1, w));
}
int32_t main() {
c_p_c();
memset(dp, -1, sizeof(dp));
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
cin >> wrr[i];
}
int x = memo(n, w);
cout << dp[n][w];
return 0;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x) \
int x; \
cin >> x; \
while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int m = 2000000;
vi arr(105);
vi wrr(105);
int dp[105][100005];
int memo(int n, int w) {
if (n == 0 || w <= 0) {
return dp[n][w] = 0;
}
if (dp[n][w] != -1)
return dp[n][w];
if (arr[n] > w)
return dp[n][w] = memo(n - 1, w);
return dp[n][w] = max((memo(n - 1, w - arr[n]) + wrr[n]), memo(n - 1, w));
}
int32_t main() {
c_p_c();
memset(dp, -1, sizeof(dp));
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
cin >> wrr[i];
}
int x = memo(n, w);
cout << dp[n][w];
return 0;
}
|
insert
| 44 | 44 | 44 | 46 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main() {
// 入力
ll N, W;
cin >> N >> W;
ll w[110];
ll v[110];
for (ll i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp,初期化
ll dp[110][1000000] = {
0}; // dp[i][sum_w] =
// i番目未満の品物(iは含まない)を用い、sum_w以下で最大のvalue
// index整理(0始まりとして)
// dp[i] = i番目未満の品物(iは含まない)
// w[i] = i番目の品物の重さ
// v[i] = i番目の品物の価値
// ループ
// dp[i+1][sum_w]へは、
// dp[i][sum_w - w[i]]から遷移する。(ただし、sum_w - w[i] >= 0)
for (ll i = 0; i < N; i++) { // i番目までの品物から選ぶ
for (ll sum_w = 0; sum_w <= W; sum_w++) { // sum_w以下で、選べるか
if (sum_w - w[i] >=
0) { // 今回の品物の重さw[i]を足して、sum_wを超えないかチェック
chmax(dp[i + 1][sum_w],
dp[i][sum_w - w[i]] +
v[i]); // 超えないなら、品物 iの価値(v[i])足してみる
}
chmax(dp[i + 1][sum_w], dp[i][sum_w]); // 選ばない場合
}
}
cout << dp[N][W] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int main() {
// 入力
ll N, W;
cin >> N >> W;
ll w[110];
ll v[110];
for (ll i = 0; i < N; i++)
cin >> w[i] >> v[i];
// dp,初期化
ll dp[110][100100] = {
0}; // dp[i][sum_w] =
// i番目未満の品物(iは含まない)を用い、sum_w以下で最大のvalue
// index整理(0始まりとして)
// dp[i] = i番目未満の品物(iは含まない)
// w[i] = i番目の品物の重さ
// v[i] = i番目の品物の価値
// ループ
// dp[i+1][sum_w]へは、
// dp[i][sum_w - w[i]]から遷移する。(ただし、sum_w - w[i] >= 0)
for (ll i = 0; i < N; i++) { // i番目までの品物から選ぶ
for (ll sum_w = 0; sum_w <= W; sum_w++) { // sum_w以下で、選べるか
if (sum_w - w[i] >=
0) { // 今回の品物の重さw[i]を足して、sum_wを超えないかチェック
chmax(dp[i + 1][sum_w],
dp[i][sum_w - w[i]] +
v[i]); // 超えないなら、品物 iの価値(v[i])足してみる
}
chmax(dp[i + 1][sum_w], dp[i][sum_w]); // 選ばない場合
}
}
cout << dp[N][W] << endl;
}
|
replace
| 33 | 34 | 33 | 34 |
-11
| |
p03163
|
C++
|
Runtime Error
|
// Subhash Suman
// Description :
#include <bits/stdc++.h>
#define ll long long int
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
const int N = 100, W = 1e5 + 5;
ll n, w, dp[N][W], arr1[N], arr2[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> arr1[i] >> arr2[i];
}
for (int i = 1; i <= n; i++) {
for (int wi = 1; wi <= w; wi++) {
if (wi - arr1[i] >= 0) {
dp[i][wi] = max(dp[i][wi], dp[i - 1][wi - arr1[i]] + arr2[i]);
}
dp[i][wi] = max(dp[i][wi], dp[i - 1][wi]);
dp[i][wi] = max(dp[i][wi], dp[i][wi - 1]);
}
}
cout << dp[n][w] << '\n';
return 0;
}
|
// Subhash Suman
// Description :
#include <bits/stdc++.h>
#define ll long long int
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
const int N = 105, W = 1e5 + 5;
ll n, w, dp[N][W], arr1[N], arr2[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> arr1[i] >> arr2[i];
}
for (int i = 1; i <= n; i++) {
for (int wi = 1; wi <= w; wi++) {
if (wi - arr1[i] >= 0) {
dp[i][wi] = max(dp[i][wi], dp[i - 1][wi - arr1[i]] + arr2[i]);
}
dp[i][wi] = max(dp[i][wi], dp[i - 1][wi]);
dp[i][wi] = max(dp[i][wi], dp[i][wi - 1]);
}
}
cout << dp[n][w] << '\n';
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03163
|
C++
|
Runtime Error
|
/*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb emplace_back
#define pf emplace_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 1000000000000000000
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
int result = 1;
while (n > 0) {
if (n % 2 == 1)
result = result * x;
x = x * x;
n = n / 2;
}
return result;
}
int n, w, dp[105][100005];
signed main() {
tezz
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
memset(dp, 0, sizeof(dp));
cin >> n >> w;
vii mat;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
mat.pb(a, b);
}
sort(all(mat));
/*for(auto it:mat) cout<<it.x<<' '<<it.y<<endl;
cout<<endl;*/
dp[0][mat[0].x] = mat[0].y;
for (int i = 1; i < n; i++) {
for (int j = 0; j <= w; j++) {
if (j < mat[i].x) {
dp[i][j] = dp[i - 1][j];
} else if (j == mat[i].x) {
dp[i][j] = max(dp[i - 1][j], mat[i].y);
} else if (j > mat[i].x) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - mat[i].x] + mat[i].y);
}
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<=w;j++) cout<<dp[i][j]<<' ';
cout<<endl;
}*/
int mx = 0;
for (int i = 0; i <= w; i++)
mx = max(mx, dp[n - 1][i]);
cout << mx;
}
|
/*
Author: Racer5x
*************************************** UNAUTHORISED COPYING OF CODE
PROHIBITED **********************************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include <bits/stdc++.h>
#define int long long
#define double long double
#define pb emplace_back
#define pf emplace_front
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int, int>
#define mii map<pii, int>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define x first
#define y second
#define sz(x) (int)x.size()
#define endl '\n'
#define hell 998244353
#define PI 3.141592653589
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 1000000000000000000
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int n) {
int result = 1;
while (n > 0) {
if (n % 2 == 1)
result = result * x;
x = x * x;
n = n / 2;
}
return result;
}
int n, w, dp[105][100005];
signed main() {
tezz
memset(dp, 0, sizeof(dp));
cin >> n >> w;
vii mat;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
mat.pb(a, b);
}
sort(all(mat));
/*for(auto it:mat) cout<<it.x<<' '<<it.y<<endl;
cout<<endl;*/
dp[0][mat[0].x] = mat[0].y;
for (int i = 1; i < n; i++) {
for (int j = 0; j <= w; j++) {
if (j < mat[i].x) {
dp[i][j] = dp[i - 1][j];
} else if (j == mat[i].x) {
dp[i][j] = max(dp[i - 1][j], mat[i].y);
} else if (j > mat[i].x) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - mat[i].x] + mat[i].y);
}
}
}
/*for(int i=0;i<n;i++){
for(int j=0;j<=w;j++) cout<<dp[i][j]<<' ';
cout<<endl;
}*/
int mx = 0;
for (int i = 0; i <= w; i++)
mx = max(mx, dp[n - 1][i]);
cout << mx;
}
|
replace
| 54 | 60 | 54 | 55 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define Rushia_mywife \
ios::sync_with_stdio(0); \
cin.tie(0);
#define rep(i, head, n) for (int i = (head); i < n; i++)
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define mem(x, i) memset((x), (i), sizeof((x)))
#define odd(x) ((x)&1)
#define LG(x) (int)log2((x))
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;
mt19937 mt_rand(time(0));
const int mod = 1000000007;
const int hnum = 998244353;
const ld PI = acos(-1);
#define int long long
int qpow(int x, int powcnt, int tomod) {
int res = 1;
for (; powcnt; powcnt >>= 1, x = (x * x) % tomod)
if (1 & powcnt)
res = (res * x) % tomod;
return (res % tomod);
}
int gcd(int aaa, int bbb) { return (bbb == 0 ? aaa : gcd(bbb, aaa % bbb)); }
int lcm(int aaa, int bbb) { return (aaa / gcd(aaa, bbb)) * bbb; }
int C(int x) { return x * (x - 1) / 2; }
// --------------------------------------**
int n, w;
int a[110];
int c[110];
int dp[110];
void solve() {
cin >> n >> w;
rep(i, 0, n) {
cin >> c[i] >> a[i];
for (int k = w; k >= 0; k--) {
if (k - c[i] < 0)
break;
dp[k] = max(dp[k], dp[k - c[i]] + a[i]);
}
}
cout << dp[w] << '\n';
}
signed main() {
Rushia_mywife
// int t; cin >> t;
// while(t--)
solve();
}
|
#include <bits/stdc++.h>
#define Rushia_mywife \
ios::sync_with_stdio(0); \
cin.tie(0);
#define rep(i, head, n) for (int i = (head); i < n; i++)
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define mem(x, i) memset((x), (i), sizeof((x)))
#define odd(x) ((x)&1)
#define LG(x) (int)log2((x))
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using ld = long double;
mt19937 mt_rand(time(0));
const int mod = 1000000007;
const int hnum = 998244353;
const ld PI = acos(-1);
#define int long long
int qpow(int x, int powcnt, int tomod) {
int res = 1;
for (; powcnt; powcnt >>= 1, x = (x * x) % tomod)
if (1 & powcnt)
res = (res * x) % tomod;
return (res % tomod);
}
int gcd(int aaa, int bbb) { return (bbb == 0 ? aaa : gcd(bbb, aaa % bbb)); }
int lcm(int aaa, int bbb) { return (aaa / gcd(aaa, bbb)) * bbb; }
int C(int x) { return x * (x - 1) / 2; }
// --------------------------------------**
int n, w;
int a[110];
int c[110];
int dp[110000];
void solve() {
cin >> n >> w;
rep(i, 0, n) {
cin >> c[i] >> a[i];
for (int k = w; k >= 0; k--) {
if (k - c[i] < 0)
break;
dp[k] = max(dp[k], dp[k - c[i]] + a[i]);
}
}
cout << dp[w] << '\n';
}
signed main() {
Rushia_mywife
// int t; cin >> t;
// while(t--)
solve();
}
|
replace
| 49 | 50 | 49 | 50 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
// Begin {{{
using namespace std;
#ifndef DEBUG
#define dump(...)
#endif
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
template <class T> inline vector<T> make_v(const T &initvalue, size_t sz) {
return vector<T>(sz, initvalue);
}
template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
return vector<decltype(make_v<T>(initvalue, args...))>(
sz, make_v<T>(initvalue, args...));
}
constexpr size_t operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End
size_t N, W;
vector<int64_t> w(110), v(110);
auto dp = make_v(-1_im, 110, int(1e5) + 5);
intmax_t rec(size_t idx, int64_t weight) {
if (idx >= N)
return 0;
if (weight + w[idx] > W)
return rec(idx + 1, weight);
if (~dp[idx][weight])
return dp[idx][weight];
return max(rec(idx + 1, weight + w[idx]) + v[idx], rec(idx + 1, weight));
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> W;
for (size_t i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
}
cout << rec(0, 0) << "\n";
return 0;
}
|
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
// Begin {{{
using namespace std;
#ifndef DEBUG
#define dump(...)
#endif
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
template <class T> inline vector<T> make_v(const T &initvalue, size_t sz) {
return vector<T>(sz, initvalue);
}
template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
return vector<decltype(make_v<T>(initvalue, args...))>(
sz, make_v<T>(initvalue, args...));
}
constexpr size_t operator""_sz(unsigned long long value) { return value; };
constexpr intmax_t operator""_im(unsigned long long value) { return value; };
constexpr uintmax_t operator""_um(unsigned long long value) { return value; };
// }}} End
size_t N, W;
vector<int64_t> w(110), v(110);
auto dp = make_v(-1_im, 110, int(1e5) + 5);
intmax_t rec(size_t idx, int64_t weight) {
if (idx >= N)
return 0;
if (weight + w[idx] > W)
return rec(idx + 1, weight);
if (~dp[idx][weight])
return dp[idx][weight];
return dp[idx][weight] =
max(rec(idx + 1, weight + w[idx]) + v[idx], rec(idx + 1, weight));
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> W;
for (size_t i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
}
cout << rec(0, 0) << "\n";
return 0;
}
|
replace
| 44 | 45 | 44 | 46 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define intt long long
const int N = 105;
const int NN = 10005;
int n, W;
int v[N], w[N];
intt dp[NN];
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int k = 1; k <= n; k++) {
for (int x = W; x >= 0; x--) {
if (x - w[k] >= 0) {
dp[x] = max(dp[x], v[k] + dp[x - w[k]]);
}
}
}
cout << dp[W] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define intt long long
const int N = 105;
const int NN = 100005;
int n, W;
int v[N], w[N];
intt dp[NN];
int main() {
cin >> n >> W;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int k = 1; k <= n; k++) {
for (int x = W; x >= 0; x--) {
if (x - w[k] >= 0) {
dp[x] = max(dp[x], v[k] + dp[x - w[k]]);
}
}
}
cout << dp[W] << '\n';
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
// It's time to be who I am, rather than who I am supposed to be.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e12;
const int N = 105;
const int W = 1e5 + 5;
int n, total, weight[N], value[N], dp[N][W];
int solve(int item, int remain) {
if (remain < 0)
return -inf;
if (remain == 0 || item == 0)
return 0;
int &ans = dp[item][remain];
if (ans != 0)
return ans;
int take = value[item] + solve(item - 1, remain - weight[item]);
int dont_take = solve(item - 1, remain);
ans = max(take, dont_take);
return ans;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n >> total;
for (int i = 1; i <= n; i++)
cin >> weight[i] >> value[i];
cout << solve(n, total) << '\n';
}
|
// It's time to be who I am, rather than who I am supposed to be.
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e12;
const int N = 105;
const int W = 1e5 + 5;
int n, total, weight[N], value[N], dp[N][W];
int solve(int item, int remain) {
if (remain < 0)
return -inf;
if (remain == 0 || item == 0)
return 0;
int &ans = dp[item][remain];
if (ans != 0)
return ans;
int take = value[item] + solve(item - 1, remain - weight[item]);
int dont_take = solve(item - 1, remain);
ans = max(take, dont_take);
return ans;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> total;
for (int i = 1; i <= n; i++)
cin >> weight[i] >> value[i];
cout << solve(n, total) << '\n';
}
|
delete
| 34 | 39 | 34 | 34 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
ll wt[101], pft[101];
ll n;
ll dp[101][101];
ll solve(ll st_index, ll wt_left) {
if (st_index == n)
return 0;
if (dp[st_index][wt_left] != -1)
return dp[st_index][wt_left];
ll ans = solve(st_index + 1, wt_left);
if (wt[st_index] <= wt_left) {
ans = max(ans, pft[st_index] + solve(st_index + 1, wt_left - wt[st_index]));
}
return dp[st_index][wt_left] = ans;
}
int main() {
ll w;
cin >> n >> w;
memset(wt, 0, sizeof wt);
memset(pft, 0, sizeof pft);
memset(dp, -1, sizeof dp);
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> pft[i];
}
ll ans = solve(0, w);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
ll wt[101], pft[101];
ll n;
ll dp[110][100001];
ll solve(ll st_index, ll wt_left) {
if (st_index == n)
return 0;
if (dp[st_index][wt_left] != -1)
return dp[st_index][wt_left];
ll ans = solve(st_index + 1, wt_left);
if (wt[st_index] <= wt_left) {
ans = max(ans, pft[st_index] + solve(st_index + 1, wt_left - wt[st_index]));
}
return dp[st_index][wt_left] = ans;
}
int main() {
ll w;
cin >> n >> w;
memset(wt, 0, sizeof wt);
memset(pft, 0, sizeof pft);
memset(dp, -1, sizeof dp);
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> pft[i];
}
ll ans = solve(0, w);
cout << ans;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define itc \
ll t; \
cin >> t; \
while (t--)
#define otc \
ll t = 1; \
while (t--)
#define PI 3.141592653589793238
// ang=(PI*ang)/180.0 in radian
#define ll long long int
#define ld long double
#define pb push_back
#define gcd(a, b) __gcd(a, b)
#define fi first
#define se second
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
ll n, w;
ll dp[105][100005];
ll knapsack(ll pos, ll cap, ll ar[][2]) {
if (pos >= n || cap <= 0)
return 0;
if (dp[pos][cap] != -1)
return dp[pos][cap];
if (ar[pos][0] > cap)
dp[pos][cap] = knapsack(pos + 1, cap, ar);
else
dp[pos][cap] = max((ar[pos][1] + knapsack(pos + 1, cap - ar[pos][0], ar)),
knapsack(pos + 1, cap, ar));
return dp[pos][cap];
}
void solve() {
cin >> n >> w;
ll ar[n][2];
for (ll i = 0; i < n; i++)
cin >> ar[i][0] >> ar[i][1];
memset(dp, -1, sizeof(dp));
cout << knapsack(0, w, ar) << endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio otc { solve(); }
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define itc \
ll t; \
cin >> t; \
while (t--)
#define otc \
ll t = 1; \
while (t--)
#define PI 3.141592653589793238
// ang=(PI*ang)/180.0 in radian
#define ll long long int
#define ld long double
#define pb push_back
#define gcd(a, b) __gcd(a, b)
#define fi first
#define se second
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
ll n, w;
ll dp[105][100005];
ll knapsack(ll pos, ll cap, ll ar[][2]) {
if (pos >= n || cap <= 0)
return 0;
if (dp[pos][cap] != -1)
return dp[pos][cap];
if (ar[pos][0] > cap)
dp[pos][cap] = knapsack(pos + 1, cap, ar);
else
dp[pos][cap] = max((ar[pos][1] + knapsack(pos + 1, cap - ar[pos][0], ar)),
knapsack(pos + 1, cap, ar));
return dp[pos][cap];
}
void solve() {
cin >> n >> w;
ll ar[n][2];
for (ll i = 0; i < n; i++)
cin >> ar[i][0] >> ar[i][1];
memset(dp, -1, sizeof(dp));
cout << knapsack(0, w, ar) << endl;
}
int main() {
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio
otc
{*/
solve();
//}
return 0;
}
|
replace
| 50 | 55 | 50 | 59 |
0
| |
p03163
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define MP make_pair
#define S second
#define F first
// #define D cout<<"*\n";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 1000000007
const double pi = 3.14159265358979323846;
int dp[2][100000004];
int knapsack(int value[], int weight[], int n, int W) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
if (i & 1) {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[1][j] = dp[0][j];
else {
dp[1][j] = max(dp[0][j], dp[0][j - weight[i - 1]] + value[i - 1]);
}
}
} else {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[0][j] = dp[1][j];
else {
dp[0][j] = max(dp[1][j], dp[1][j - weight[i - 1]] + value[i - 1]);
}
}
}
}
if (n & 1)
return dp[1][W];
return dp[0][W];
}
signed main() {
fast int t = 1;
// cin>>t;
while (t--) {
int n, W;
cin >> n >> W;
int value[n], weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
cout << knapsack(value, weight, n, W);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PB push_back
#define MP make_pair
#define S second
#define F first
// #define D cout<<"*\n";
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define mod 1000000007
const double pi = 3.14159265358979323846;
int dp[2][1000004];
int knapsack(int value[], int weight[], int n, int W) {
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
if (i & 1) {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[1][j] = dp[0][j];
else {
dp[1][j] = max(dp[0][j], dp[0][j - weight[i - 1]] + value[i - 1]);
}
}
} else {
for (int j = 0; j <= W; j++) {
if (weight[i - 1] > j)
dp[0][j] = dp[1][j];
else {
dp[0][j] = max(dp[1][j], dp[1][j - weight[i - 1]] + value[i - 1]);
}
}
}
}
if (n & 1)
return dp[1][W];
return dp[0][W];
}
signed main() {
fast int t = 1;
// cin>>t;
while (t--) {
int n, W;
cin >> n >> W;
int value[n], weight[n];
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
cout << knapsack(value, weight, n, W);
}
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
MLE
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
int n;
int max_weight;
int w[101];
long long int v[101];
long long int dp[101][100001];
long long int ans = 0;
int main() {
cin >> n >> max_weight;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= max_weight; j++) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if (j + w[i] <= max_weight)
dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
}
for (int i = 0; i <= max_weight; i++) {
if (dp[n][i] >= ans)
ans = dp[n][i];
}
cout << ans << endl;
}
|
#include <iostream>
using namespace std;
int n;
int max_weight;
int w[101];
long long int v[101];
long long int dp[101][100001];
long long int ans = 0;
int main() {
cin >> n >> max_weight;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= max_weight; j++) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if (j + w[i] <= max_weight)
dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
}
for (int i = 0; i <= max_weight; i++) {
if (dp[n][i] >= ans)
ans = dp[n][i];
}
cout << ans << endl;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>
// #include <bits/stdc++.h>
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
const int N = 1e5 + 100;
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
ll dp[200], a[200];
int main() {
int n, W;
scanf("%d%d", &n, &W);
ll w, v;
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &w, &v);
for (int j = W; j >= w; j--)
dp[j] = max(dp[j], dp[j - w] + v);
}
printf("%lld\n", dp[W]);
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <vector>
// #include <bits/stdc++.h>
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
const int N = 1e5 + 100;
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
ll dp[N], a[200];
int main() {
int n, W;
scanf("%d%d", &n, &W);
ll w, v;
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &w, &v);
for (int j = W; j >= w; j--)
dp[j] = max(dp[j], dp[j - w] + v);
}
printf("%lld\n", dp[W]);
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll v[105], weight[105], dp[105][10005], n, CAP;
ll KnapSack(int i, ll w) {
if (i == n) {
return 0;
}
if (dp[i][w] != -1)
return dp[i][w];
ll ans1 = 0, ans2 = 0;
if (w + weight[i] <= CAP) {
ans1 = KnapSack(i + 1, w + weight[i]) + v[i];
}
ans2 = KnapSack(i + 1, w);
return dp[i][w] = max(ans1, ans2);
}
int main() {
memset(dp, -1, sizeof(dp));
cin >> n >> CAP;
for (int i = 0; i < n; i++)
cin >> weight[i] >> v[i];
ll ans = KnapSack(0, 0);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll v[105], weight[105], dp[105][100005], n, CAP;
ll KnapSack(int i, ll w) {
if (i == n) {
return 0;
}
if (dp[i][w] != -1)
return dp[i][w];
ll ans1 = 0, ans2 = 0;
if (w + weight[i] <= CAP) {
ans1 = KnapSack(i + 1, w + weight[i]) + v[i];
}
ans2 = KnapSack(i + 1, w);
return dp[i][w] = max(ans1, ans2);
}
int main() {
memset(dp, -1, sizeof(dp));
cin >> n >> CAP;
for (int i = 0; i < n; i++)
cin >> weight[i] >> v[i];
ll ans = KnapSack(0, 0);
cout << ans << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, CAP, w[105], v[105], dp[105][105];
ll knapsack(ll item, ll weight) {
if (item > n) {
return 0;
}
if (dp[item][weight] != -1)
return dp[item][weight];
ll ans1 = 0;
if (weight + w[item] <= CAP) {
ans1 = knapsack(item + 1, weight + w[item]) + v[item];
}
ll ans2 = knapsack(item + 1, weight);
return dp[item][weight] = max(ans1, ans2);
}
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> CAP;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, -1, sizeof(dp));
ll ans = knapsack(1, 0);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, CAP, w[105], v[105], dp[105][100005];
ll knapsack(ll item, ll weight) {
if (item > n) {
return 0;
}
if (dp[item][weight] != -1)
return dp[item][weight];
ll ans1 = 0;
if (weight + w[item] <= CAP) {
ans1 = knapsack(item + 1, weight + w[item]) + v[item];
}
ll ans2 = knapsack(item + 1, weight);
return dp[item][weight] = max(ans1, ans2);
}
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> CAP;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, -1, sizeof(dp));
ll ans = knapsack(1, 0);
cout << ans << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int INF = 1e9 + 5;
#undef int
int main() {
#define int long long int
int n, w;
cin >> n >> w;
vector<int> weight(n, 0);
vector<int> values(n, 0);
int dp[n + 5][w + 5];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> weight[i];
cin >> values[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 (j >= weight[i - 1]) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight[i]] + values[i - 1]);
}
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int INF = 1e9 + 5;
#undef int
int main() {
#define int long long int
int n, w;
cin >> n >> w;
vector<int> weight(n, 0);
vector<int> values(n, 0);
int dp[n + 5][w + 5];
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
cin >> weight[i];
cin >> values[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 (j >= weight[i - 1]) {
dp[i][j] =
max(dp[i - 1][j], dp[i - 1][j - weight[i - 1]] + values[i - 1]);
}
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
|
replace
| 28 | 29 | 28 | 30 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <cmath>
#include <iostream>
using namespace std;
#define MAXN 120
#define MAXW 100001
long long N, W;
long long w[MAXN], v[MAXN];
long long dp[MAXN][MAXW];
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int i = w[0]; i <= W; i++) {
dp[0][i] = v[0];
}
for (int i = 1; i < N; i++) {
for (int j = 0; j <= W; j++) {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
cout << dp[N - 1][W] << endl;
}
|
#include <cmath>
#include <iostream>
using namespace std;
#define MAXN 120
#define MAXW 100001
long long N, W;
long long w[MAXN], v[MAXN];
long long dp[MAXN][MAXW];
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
for (int i = w[0]; i <= W; i++) {
dp[0][i] = v[0];
}
for (int i = 1; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (w[i] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
}
}
}
cout << dp[N - 1][W] << endl;
}
|
replace
| 22 | 23 | 22 | 27 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO \
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(nullptr)
#define INF (1LL << 62) - 1
#define F first
#define S second
#define pb push_back
ll dp[102][100002];
ll dosomething(ll w, ll n, vector<ll> &wt, vector<ll> &val, ll i) {
if (i >= n || w <= 0)
return 0;
if (dp[i][w] != -1)
return dp[i][w];
if (wt[i] > w)
dp[i][w] = dosomething(w, n, wt, val, i + 1);
else
dp[i][w] = max(dosomething(w, n, wt, val, i + 1),
val[i] + dosomething(w - wt[i], n, wt, val, i + 1));
return dp[i][w];
}
int main() {
FASTIO;
for (ll i = 0; i < 1002; i++)
for (ll j = 0; j < 1002; j++)
dp[i][j] = -1;
ll n, w;
cin >> n >> w;
vector<ll> wt(n), val(n);
for (ll i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << dosomething(w, n, wt, val, 0) << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO \
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(nullptr)
#define INF (1LL << 62) - 1
#define F first
#define S second
#define pb push_back
ll dp[102][100002];
ll dosomething(ll w, ll n, vector<ll> &wt, vector<ll> &val, ll i) {
if (i >= n || w <= 0)
return 0;
if (dp[i][w] != -1)
return dp[i][w];
if (wt[i] > w)
dp[i][w] = dosomething(w, n, wt, val, i + 1);
else
dp[i][w] = max(dosomething(w, n, wt, val, i + 1),
val[i] + dosomething(w - wt[i], n, wt, val, i + 1));
return dp[i][w];
}
int main() {
FASTIO;
for (ll i = 0; i < 102; i++)
for (ll j = 0; j < 100002; j++)
dp[i][j] = -1;
ll n, w;
cin >> n >> w;
vector<ll> wt(n), val(n);
for (ll i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << dosomething(w, n, wt, val, 0) << "\n";
}
|
replace
| 29 | 31 | 29 | 31 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define forb(i, n) for (int i = int(n) - 1; i >= 0; --i)
// #define x first
// #define y second
const int INF = 1e9;
const li INF64 = 4e18;
const int M = 100;
const int N = 100 * 1000 + 100;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = 3.14159265359;
li gcd(li a, li b) { return a == 0 ? b : gcd(b % a, a); }
li dp[M][N];
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> w(n), v(n);
forn(i, n) { cin >> w[i] >> v[i]; }
fore(i, 1, n + 1) {
fore(j, 1, m + 1) {
dp[i][j] = dp[i - 1][j];
if (j - w[i - 1] >= 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
}
cout << dp[n][m] << '\n';
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long li;
typedef unsigned long long uli;
typedef pair<int, int> pii;
typedef long double ld;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fr first
#define sc second
#define pb push_back
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define forb(i, n) for (int i = int(n) - 1; i >= 0; --i)
// #define x first
// #define y second
const int INF = 1e9;
const li INF64 = 4e18;
const int M = 100 + 10;
const int N = 100 * 1000 + 100;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = 3.14159265359;
li gcd(li a, li b) { return a == 0 ? b : gcd(b % a, a); }
li dp[M][N];
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> w(n), v(n);
forn(i, n) { cin >> w[i] >> v[i]; }
fore(i, 1, n + 1) {
fore(j, 1, m + 1) {
dp[i][j] = dp[i - 1][j];
if (j - w[i - 1] >= 0) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
}
cout << dp[n][m] << '\n';
}
|
replace
| 35 | 36 | 35 | 36 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 1; i <= (n); i++)
using ll = long long;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1000000007;
int main() {
ll N, W;
cin >> N >> W;
vector<ll> w(N + 1), v(N + 1);
rep(i, N) cin >> w[i] >> v[i];
vector<vector<ll>> dat(N + 1, vector<ll>(W + 1));
rep(i, N) {
rep(j, W + 1) {
if (w[i] <= j) {
dat[i][j] = max(dat[i - 1][j], dat[i - 1][j - w[i]] + v[i]);
} else
dat[i][j] = dat[i - 1][j];
}
}
cout << dat[N][W];
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 1; i <= (n); i++)
using ll = long long;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1000000007;
int main() {
ll N, W;
cin >> N >> W;
vector<ll> w(N + 1), v(N + 1);
rep(i, N) cin >> w[i] >> v[i];
vector<vector<ll>> dat(N + 1, vector<ll>(W + 1));
rep(i, N) {
rep(j, W) {
if (w[i] <= j) {
dat[i][j] = max(dat[i - 1][j], dat[i - 1][j - w[i]] + v[i]);
} else
dat[i][j] = dat[i - 1][j];
}
}
cout << dat[N][W];
}
|
replace
| 14 | 15 | 14 | 15 |
-6
|
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define INP (a << 50)
using namespace std;
int main() {
int a, b, c, i, j;
cin >> a >> b;
int s[a + 5], ss[a + 5];
long long int sss[a + 5][a + 5];
for (i = 1; i <= a; i++) {
cin >> s[i] >> ss[i];
}
memset(sss, 0, sizeof(sss));
for (i = 1; i <= a; i++) {
for (j = 1; j <= b; j++) {
if (s[i] <= j) {
sss[i][j] = max(sss[i - 1][j], sss[i - 1][j - s[i]] + ss[i]);
} else
sss[i][j] = sss[i - 1][j];
}
}
cout << sss[a][b] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define INP (a << 50)
using namespace std;
int main() {
int a, b, c, i, j;
cin >> a >> b;
int s[a + 5], ss[b + 5];
long long int sss[a + 5][b + 5];
for (i = 1; i <= a; i++) {
cin >> s[i] >> ss[i];
}
memset(sss, 0, sizeof(sss));
for (i = 1; i <= a; i++) {
for (j = 1; j <= b; j++) {
if (s[i] <= j) {
sss[i][j] = max(sss[i - 1][j], sss[i - 1][j - s[i]] + ss[i]);
} else
sss[i][j] = sss[i - 1][j];
}
}
cout << sss[a][b] << endl;
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[201], b[201];
ll n, w;
ll dp[201][201];
ll rec(ll idx, ll weight) {
if (weight > w)
return -1e9;
if (weight == w)
return 0;
if (idx == n)
return 0;
if (dp[idx][weight] != -1)
return dp[idx][weight];
ll op1 = rec(idx + 1, weight + a[idx]) + b[idx];
ll op2 = rec(idx + 1, weight);
return dp[idx][weight] = max(op1, op2);
}
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
memset(dp, -1, sizeof(dp));
cout << rec(0, 0);
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll a[201], b[201];
ll n, w;
ll dp[201][200001];
ll rec(ll idx, ll weight) {
if (weight > w)
return -1e9;
if (weight == w)
return 0;
if (idx == n)
return 0;
if (dp[idx][weight] != -1)
return dp[idx][weight];
ll op1 = rec(idx + 1, weight + a[idx]) + b[idx];
ll op2 = rec(idx + 1, weight);
return dp[idx][weight] = max(op1, op2);
}
int main() {
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
memset(dp, -1, sizeof(dp));
cout << rec(0, 0);
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
/* in the name of allah */
#include <bits/stdc++.h>
using namespace std;
const int N = 100, W = 1e5 + 5;
long long n, w, a[N], v[N], dp[N][W];
void readInput() {
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i] >> v[i];
}
void solve() {
for (int i = 1; i <= n; i++)
for (int j = 0; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= a[i] && dp[i][j] < dp[i - 1][j - a[i]] + v[i])
dp[i][j] = dp[i - 1][j - a[i]] + v[i];
}
cout << dp[n][w] << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
readInput(), solve();
return 0;
}
|
/* in the name of allah */
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5, W = 1e5 + 5;
long long n, w, a[N], v[N], dp[N][W];
void readInput() {
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> a[i] >> v[i];
}
void solve() {
for (int i = 1; i <= n; i++)
for (int j = 0; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j >= a[i] && dp[i][j] < dp[i - 1][j - a[i]] + v[i])
dp[i][j] = dp[i - 1][j - a[i]] + v[i];
}
cout << dp[n][w] << endl;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
readInput(), solve();
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(x, y, z) for (int x = y; x <= z; x++)
#define MSET(x, y) memset(x, y, sizeof(x))
#define M 105
using namespace std;
int n, m, w[M], v[M];
long long dp[10005];
int main() {
while (~scanf("%d %d", &n, &m)) {
REP(i, 1, n) scanf("%d %d", &w[i], &v[i]);
MSET(dp, -1);
dp[0] = 0;
REP(i, 1, n)
for (int j = m; j >= w[i]; j--) if (dp[j - w[i]] != -1) dp[j] =
max(dp[j], dp[j - w[i]] + v[i]);
printf("%lld\n", *max_element(dp, dp + m + 1));
}
return 0;
}
|
#include <bits/stdc++.h>
#define REP(x, y, z) for (int x = y; x <= z; x++)
#define MSET(x, y) memset(x, y, sizeof(x))
#define M 105
using namespace std;
int n, m, w[M], v[M];
long long dp[100005];
int main() {
while (~scanf("%d %d", &n, &m)) {
REP(i, 1, n) scanf("%d %d", &w[i], &v[i]);
MSET(dp, -1);
dp[0] = 0;
REP(i, 1, n)
for (int j = m; j >= w[i]; j--) if (dp[j - w[i]] != -1) dp[j] =
max(dp[j], dp[j - w[i]] + v[i]);
printf("%lld\n", *max_element(dp, dp + m + 1));
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define rep(i, n) reps(i, 0, n)
using namespace std;
using ll = long long;
int main() {
int N, W;
cin >> N >> W;
vector<int> w(N + 1, 0), v(N + 1, 0);
rep(i, N) cin >> w[i + 1] >> v[i + 1];
// dp[101][100000];
ll dp[101][1000];
rep(i, N + 1) {
rep(j, W + 1) { dp[i][j] = 0; }
}
reps(i, 1, N + 1) {
rep(j, W + 1) {
if (j - w[i] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
// rep(i,N+1){
// rep(j,W+1){
// cout << dp[i][j] <<" ";
// }
// cout << endl;
// }
cout << dp[N][W] << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <vector>
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define rep(i, n) reps(i, 0, n)
using namespace std;
using ll = long long;
int main() {
int N, W;
cin >> N >> W;
vector<int> w(N + 1, 0), v(N + 1, 0);
rep(i, N) cin >> w[i + 1] >> v[i + 1];
ll dp[101][100010];
// ll dp[101][1000];
rep(i, N + 1) {
rep(j, W + 1) { dp[i][j] = 0; }
}
reps(i, 1, N + 1) {
rep(j, W + 1) {
if (j - w[i] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
// rep(i,N+1){
// rep(j,W+1){
// cout << dp[i][j] <<" ";
// }
// cout << endl;
// }
cout << dp[N][W] << endl;
return 0;
}
|
replace
| 17 | 19 | 17 | 19 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <climits>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
ll n, w;
ll weight[105], value[105];
ll dp[105][105];
ll solve(ll i, ll j) {
if (i == n + 1)
return 0;
if (j == 0)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (j - weight[i] < 0)
return dp[i][j] = solve(i + 1, j);
else
return dp[i][j] =
max(value[i] + solve(i + 1, j - weight[i]), solve(i + 1, j));
}
int main() {
cin >> n >> w;
for (ll i = 1; i <= n; i++) {
cin >> weight[i] >> value[i];
}
memset(dp, -1, sizeof(dp));
cout << max(solve(1, w - weight[1]), solve(1, w));
return 0;
}
|
#include <climits>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
ll n, w;
ll weight[100005], value[100005];
ll dp[105][100005];
ll solve(ll i, ll j) {
if (i == n + 1)
return 0;
if (j == 0)
return 0;
if (dp[i][j] != -1)
return dp[i][j];
if (j - weight[i] < 0)
return dp[i][j] = solve(i + 1, j);
else
return dp[i][j] =
max(value[i] + solve(i + 1, j - weight[i]), solve(i + 1, j));
}
int main() {
cin >> n >> w;
for (ll i = 1; i <= n; i++) {
cin >> weight[i] >> value[i];
}
memset(dp, -1, sizeof(dp));
cout << max(solve(1, w - weight[1]), solve(1, w));
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;
int main() {
ll n, W;
cin >> n >> W;
vector<ll> w(n + 1, 0), v(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n + 1);
for (int i = 0; i <= n; i++) {
dp[i].resize(W);
}
for (int i = 1; i <= n; i++) {
for (int j = W; j >= 0; j--) {
dp[i][j] =
max(dp[i - 1][j], (j - w[i] >= 0 ? dp[i - 1][j - w[i]] + v[i] : 0));
}
}
cout << dp[n][W] << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;
int main() {
ll n, W;
cin >> n >> W;
vector<ll> w(n + 1, 0), v(n + 1, 0);
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n + 1);
for (int i = 0; i <= n; i++) {
dp[i].resize(W + 1, 0);
}
for (int i = 1; i <= n; i++) {
for (int j = W; j >= 0; j--) {
dp[i][j] =
max(dp[i - 1][j], (j - w[i] >= 0 ? dp[i - 1][j - w[i]] + v[i] : 0));
}
}
cout << dp[n][W] << endl;
return 0;
}
|
replace
| 31 | 32 | 31 | 32 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
const int INF = (int)1e9 + 9;
const int maxn = (int)1e6 + 6;
// const mod = (int) 1e9 + 7;
using namespace std;
signed main() {
int N, W;
cin >> N >> W;
vector<int> v(N), w(N);
vector<vector<int>> dp(N + 1, vector<int>(W + 1));
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
dp[0][w[0]] = v[0];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]]) + v[i];
}
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
int ans = 0;
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[N - 1][i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
const int INF = (int)1e9 + 9;
const int maxn = (int)1e6 + 6;
// const mod = (int) 1e9 + 7;
using namespace std;
signed main() {
int N, W;
cin >> N >> W;
vector<int> v(N), w(N);
vector<vector<int>> dp(N + 1, vector<int>(W + 1));
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
}
dp[0][w[0]] = v[0];
for (int i = 1; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j >= w[i]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]]) + v[i];
}
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
int ans = 0;
for (int i = 0; i <= W; i++) {
ans = max(ans, dp[N - 1][i]);
}
cout << ans << endl;
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int N, W, w[100], v[100];
long long dp[109][10009];
int main() {
cin >> N >> W;
for (int i = 0; i < N; ++i)
cin >> w[i] >> v[i];
for (int j = 0; j <= W; ++j)
dp[0][j] = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= W; ++j) {
if (j + w[i] <= W) {
dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[N][W] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int N, W, w[100], v[100];
long long dp[109][100009];
int main() {
cin >> N >> W;
for (int i = 0; i < N; ++i)
cin >> w[i] >> v[i];
for (int j = 0; j <= W; ++j)
dp[0][j] = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= W; ++j) {
if (j + w[i] <= W) {
dp[i + 1][j + w[i]] = max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
}
}
cout << dp[N][W] << endl;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
const int maxm = 1e5 + 10;
typedef long long ll;
int w[maxn], c[maxn];
ll dp[maxn];
void solve(int n, int m) {
for (int i = 1; i <= n; i++)
for (int j = m; j >= w[i]; j--)
dp[j] = max(dp[j], dp[j - w[i]] + (ll)c[i]);
}
int main(void) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> w[i] >> c[i];
solve(n, m);
cout << dp[m] << "\n";
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
const int maxm = 1e5 + 10;
typedef long long ll;
int w[maxn], c[maxn];
ll dp[maxm];
void solve(int n, int m) {
for (int i = 1; i <= n; i++)
for (int j = m; j >= w[i]; j--)
dp[j] = max(dp[j], dp[j - w[i]] + (ll)c[i]);
}
int main(void) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> w[i] >> c[i];
solve(n, m);
cout << dp[m] << "\n";
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define frst first
#define sec second
#define fast cin.tie(0), ios_base ::sync_with_stdio(0)
#define db double
#define mod 1000000007
void online_judge() {
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
ll dp[101][100001];
ll solve1(ll wt[], ll p[], ll n, ll w) {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (i == 0 || j == 0) {
dp[i][j] == 0;
continue;
}
dp[i][j] = dp[i - 1][j];
if (j >= wt[i - 1]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - wt[i - 1]] + p[i - 1]);
}
}
}
////cout << dp[n][w] << endl;
return dp[n][w];
}
void go() {
ll n, w;
cin >> n >> w;
ll wt[n], p[n];
for (int i = 0; i < n; ++i)
cin >> wt[i] >> p[i];
// memset(dp , -1 , sizeof dp);
cout << solve1(wt, p, n, w);
}
int main() {
fast;
online_judge();
// cout << 2332;
go();
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define frst first
#define sec second
#define fast cin.tie(0), ios_base ::sync_with_stdio(0)
#define db double
#define mod 1000000007
void online_judge() {
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
}
ll dp[101][100001];
ll solve1(ll wt[], ll p[], ll n, ll w) {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= w; ++j) {
if (i == 0 || j == 0) {
dp[i][j] == 0;
continue;
}
dp[i][j] = dp[i - 1][j];
if (j >= wt[i - 1]) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - wt[i - 1]] + p[i - 1]);
}
}
}
////cout << dp[n][w] << endl;
return dp[n][w];
}
void go() {
ll n, w;
cin >> n >> w;
ll wt[n], p[n];
for (int i = 0; i < n; ++i)
cin >> wt[i] >> p[i];
// memset(dp , -1 , sizeof dp);
cout << solve1(wt, p, n, w);
}
int main() {
fast;
/// online_judge();
// cout << 2332;
go();
}
|
replace
| 46 | 47 | 46 | 47 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
long long n, m;
cin >> n >> m;
long long arr[n][2];
for (long long i = 0; i < n; i++) {
cin >> arr[i][0] >> arr[i][1];
}
long long dp[n + 1][m + 1];
for (long long j = 0; j < m + 1; j++) {
for (long long i = 0; i < n + 1; i++) {
dp[i][j] = 0;
}
}
for (long long i = 1; i < n + 1; i++) {
for (long long j = 0; j < m + 1; j++) {
if (arr[i - 1][0] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] =
max(dp[i - 1][j], arr[i - 1][1] + dp[i - 1][j - arr[i - 1][0]]);
}
}
}
cout << arr[n][m];
return 0;
}
|
#include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
long long n, m;
cin >> n >> m;
long long arr[n][2];
for (long long i = 0; i < n; i++) {
cin >> arr[i][0] >> arr[i][1];
}
long long dp[n + 1][m + 1];
for (long long j = 0; j < m + 1; j++) {
for (long long i = 0; i < n + 1; i++) {
dp[i][j] = 0;
}
}
for (long long i = 1; i < n + 1; i++) {
for (long long j = 0; j < m + 1; j++) {
if (arr[i - 1][0] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] =
max(dp[i - 1][j], arr[i - 1][1] + dp[i - 1][j - arr[i - 1][0]]);
}
}
}
cout << dp[n][m] << endl;
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#ifndef bhartiya
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target
// ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;
#ifdef bhartiya
#define endl '\n'
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define pb push_back
#define bitc __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second
#define swap(a, b) \
{ \
a = a ^ b; \
b = a ^ b; \
a = a ^ b; \
}
#define fr(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (ll i = (a), _b = (b); i >= _b; i--)
#define inf 200000000000000ll
// #define inf 10000000000ll
#define mod 1000000007ll
// #define mod 998244353ll
#define eps 1e-7
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const ll maxn = 100005;
ll dp[105][maxn];
bool vis[105][maxn];
ll v[maxn];
ll we[maxn];
void recur(ll i, ll w) {
if (i < 0)
return;
else if (w == 0)
return;
if (vis[i][w])
return;
ll a = 0, b = 0;
recur(i - 1, w);
b = i > 0 ? dp[i - 1][w] : 0;
if (we[i] <= w) {
recur(i - 1, w - we[i]);
a = i > 0 ? dp[i - 1][w - we[i]] + v[i] : v[i];
}
dp[i][w] = max(a, b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
// cin.exceptions(cin.failbit);
#ifdef bhartiya
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin>>t;
while (t--) {
ll n, w;
cin >> n >> w;
rep(i, n) { cin >> we[i] >> v[i]; }
recur(n - 1, w);
cout << dp[n - 1][w];
}
}
|
#ifndef bhartiya
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target
// ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;
#ifdef bhartiya
#define endl '\n'
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define pb push_back
#define bitc __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second
#define swap(a, b) \
{ \
a = a ^ b; \
b = a ^ b; \
a = a ^ b; \
}
#define fr(i, a, b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (ll i = (a), _b = (b); i >= _b; i--)
#define inf 200000000000000ll
// #define inf 10000000000ll
#define mod 1000000007ll
// #define mod 998244353ll
#define eps 1e-7
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
const ll maxn = 100005;
ll dp[105][maxn];
bool vis[105][maxn];
ll v[maxn];
ll we[maxn];
void recur(ll i, ll w) {
if (i < 0)
return;
else if (w == 0)
return;
if (vis[i][w])
return;
vis[i][w] = true;
ll a = 0, b = 0;
recur(i - 1, w);
b = i > 0 ? dp[i - 1][w] : 0;
if (we[i] <= w) {
recur(i - 1, w - we[i]);
a = i > 0 ? dp[i - 1][w - we[i]] + v[i] : v[i];
}
dp[i][w] = max(a, b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
// cin.exceptions(cin.failbit);
#ifdef bhartiya
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin>>t;
while (t--) {
ll n, w;
cin >> n >> w;
rep(i, n) { cin >> we[i] >> v[i]; }
recur(n - 1, w);
cout << dp[n - 1][w];
}
}
|
insert
| 70 | 70 | 70 | 71 |
TLE
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, W1, w[100001] = {0}, j, temp, temp2, max1;
cin >> n >> W1;
for (int i = 0; i < W1; i++) {
cin >> temp >> temp2;
j = W1;
while (j - temp >= 0) {
if (w[j - temp]) {
w[j] = max(w[j], w[j - temp] + temp2);
}
j--;
}
if (w[temp] < temp2) {
w[temp] = temp2;
}
}
max1 = w[0];
for (int i = 1; i <= W1; i++) {
if (max1 < w[i]) {
max1 = w[i];
}
}
cout << max1;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, W1, w[100001] = {0}, j, temp, temp2, max1;
cin >> n >> W1;
for (int i = 0; i < n; i++) {
cin >> temp >> temp2;
j = W1;
while (j - temp >= 0) {
if (w[j - temp]) {
w[j] = max(w[j], w[j - temp] + temp2);
}
j--;
}
if (w[temp] < temp2) {
w[temp] = temp2;
}
}
max1 = w[0];
for (int i = 1; i <= W1; i++) {
if (max1 < w[i]) {
max1 = w[i];
}
}
cout << max1;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long int res[103], i, j, a, b, n, x;
int main() {
cin >> n >> x;
for (i = 0; i < n; i++) {
scanf("%lld%lld", &a, &b);
for (j = x - a; j >= 0; j--)
res[j + a] = max(res[j + a], res[j] + b);
}
cout << res[x];
}
|
#include <bits/stdc++.h>
using namespace std;
long long int res[100001], i, j, a, b, n, x;
int main() {
cin >> n >> x;
for (i = 0; i < n; i++) {
scanf("%lld%lld", &a, &b);
for (j = x - a; j >= 0; j--)
res[j + a] = max(res[j + a], res[j] + b);
}
cout << res[x];
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int, int>
#define vi vector<int>
#define umapi unordered_map<int, int>
const int m = 998244353;
using namespace std;
void FIO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main() {
FIO();
int n, mx;
cin >> n >> mx;
int w[n], v[n], dp[mx + 1];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= mx; i++) {
dp[i] = -1;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = mx; j >= 0; j--) {
if (dp[j] != -1 && j + w[i] <= mx)
dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
}
}
int ret = dp[0];
for (int i = 0; i <= mx; i++) {
ret = max(ret, dp[i]);
}
cout << ret << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int, int>
#define vi vector<int>
#define umapi unordered_map<int, int>
const int m = 998244353;
using namespace std;
void FIO() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main() {
// FIO();
int n, mx;
cin >> n >> mx;
int w[n], v[n], dp[mx + 1];
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i <= mx; i++) {
dp[i] = -1;
}
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = mx; j >= 0; j--) {
if (dp[j] != -1 && j + w[i] <= mx)
dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
}
}
int ret = dp[0];
for (int i = 0; i <= mx; i++) {
ret = max(ret, dp[i]);
}
cout << ret << "\n";
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << '[' << #x << " is: " << x << "] " \
<< "\n";
#define sor(v) sort(v.begin(), v.end())
#define rsor(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define print(v) \
for (auto f : v) \
cout << f << " ";
#define printpair(v) \
for (auto f : v) \
cout << f.first << " " << f.second << endl;
#define int long long
vector<int> wt, v;
vector<vector<int>> dp(1e2, vector<int>(1e5, -1));
int n, w;
int calc(int idx, int c) {
if (idx == 0 || c == 0)
return dp[idx][c] = 0;
if (dp[idx][c] != -1)
return dp[idx][c];
int firstc = -1, secondc = -1;
if (c < wt[idx])
return dp[idx][c] = calc(idx - 1, c);
else {
firstc = v[idx] + calc(idx - 1, c - wt[idx]);
secondc = calc(idx - 1, c);
}
return dp[idx][c] = max(firstc, secondc);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> w;
v.resize(n + 1), wt.resize(n + 1);
for (int x = 1; x <= n; x++)
cin >> wt[x] >> v[x];
cout << calc(n, w);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << '[' << #x << " is: " << x << "] " \
<< "\n";
#define sor(v) sort(v.begin(), v.end())
#define rsor(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define print(v) \
for (auto f : v) \
cout << f << " ";
#define printpair(v) \
for (auto f : v) \
cout << f.first << " " << f.second << endl;
#define int long long
vector<int> wt, v;
vector<vector<int>> dp(1e2 + 1, vector<int>(1e5 + 1, -1));
int n, w;
int calc(int idx, int c) {
if (idx == 0 || c == 0)
return dp[idx][c] = 0;
if (dp[idx][c] != -1)
return dp[idx][c];
int firstc = -1, secondc = -1;
if (c < wt[idx])
return dp[idx][c] = calc(idx - 1, c);
else {
firstc = v[idx] + calc(idx - 1, c - wt[idx]);
secondc = calc(idx - 1, c);
}
return dp[idx][c] = max(firstc, secondc);
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> w;
v.resize(n + 1), wt.resize(n + 1);
for (int x = 1; x <= n; x++)
cin >> wt[x] >> v[x];
cout << calc(n, w);
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << '[' << #x << " is: " << x << "] " \
<< "\n";
#define sor(v) sort(v.begin(), v.end())
#define rsor(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define print(v) \
for (auto f : v) \
cout << f << " ";
#define printpair(v) \
for (auto f : v) \
cout << f.first << " " << f.second << endl;
#define int long long
vector<int> wt, v;
vector<vector<int>> dp(1e2, vector<int>(1e5, -1));
int n, w;
int calc(int idx, int c) {
int res;
if (idx == 0 || c == 0)
return dp[idx][c] = 0;
if (dp[idx][c] != -1)
return dp[idx][c];
int firstc = -1, secondc = -1;
if (c < wt[idx])
res = calc(idx - 1, c);
else {
firstc = v[idx] + calc(idx - 1, c - wt[idx]);
secondc = calc(idx - 1, c);
res = max(firstc, secondc);
}
return dp[idx][c] = res;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> w;
v.resize(n + 1), wt.resize(n + 1);
for (int x = 1; x <= n; x++)
cin >> wt[x] >> v[x];
cout << calc(n, w);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << '[' << #x << " is: " << x << "] " \
<< "\n";
#define sor(v) sort(v.begin(), v.end())
#define rsor(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define print(v) \
for (auto f : v) \
cout << f << " ";
#define printpair(v) \
for (auto f : v) \
cout << f.first << " " << f.second << endl;
#define int long long
vector<int> wt, v;
vector<vector<int>> dp(1e2 + 1, vector<int>(1e5 + 1, -1));
int n, w;
int calc(int idx, int c) {
int res;
if (idx == 0 || c == 0)
return dp[idx][c] = 0;
if (dp[idx][c] != -1)
return dp[idx][c];
int firstc = -1, secondc = -1;
if (c < wt[idx])
res = calc(idx - 1, c);
else {
firstc = v[idx] + calc(idx - 1, c - wt[idx]);
secondc = calc(idx - 1, c);
res = max(firstc, secondc);
}
return dp[idx][c] = res;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> w;
v.resize(n + 1), wt.resize(n + 1);
for (int x = 1; x <= n; x++)
cin >> wt[x] >> v[x];
cout << calc(n, w);
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 5;
const int MAXNN = 1e5 + 7;
const int INF = 1e9 + 7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define F first
#define S second
ll poww(ll a, ll b, ll md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
ll MOD(ll a) { return ((a % INF) + INF) % INF; }
ll inv(ll a) { return poww(a, INF - 2, INF); }
ll w[MAXN], val[MAXN], dp[MAXN][MAXN];
int main() {
fast_io;
// cout << fixed << setprecision(15);
int n, cap;
cin >> n >> cap;
for (int i = 1; i <= n; ++i)
cin >> w[i] >> val[i];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= cap; ++j) {
dp[i][j] = dp[i - 1][j];
if (j >= w[i])
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + val[i]);
}
}
cout << dp[n][cap];
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 5;
const int MAXNN = 1e5 + 7;
const int INF = 1e9 + 7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define F first
#define S second
ll poww(ll a, ll b, ll md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
ll MOD(ll a) { return ((a % INF) + INF) % INF; }
ll inv(ll a) { return poww(a, INF - 2, INF); }
ll w[MAXN], val[MAXN], dp[MAXN][MAXNN];
int main() {
fast_io;
// cout << fixed << setprecision(15);
int n, cap;
cin >> n >> cap;
for (int i = 1; i <= n; ++i)
cin >> w[i] >> val[i];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= cap; ++j) {
dp[i][j] = dp[i - 1][j];
if (j >= w[i])
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i]] + val[i]);
}
}
cout << dp[n][cap];
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
ll an[101][100001];
ll maxwt(ll W, ll n, ll w[], ll v[]) {
if (n == 0 || W == 0) {
return 0;
}
if (an[n][W] > -1)
return an[n][W];
if (w[n] > W) {
an[n][W] = maxwt(W, n - 1, w, v);
} else {
an[n][W] = max(maxwt(W, n - 1, w, v), v[n] + maxwt(W - w[n], n - 1, w, v));
}
return an[n][W];
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, W, i, j, k, l;
cin >> n >> W;
for (i = 0; i < 101; i++) {
for (j = 0; j < 100001; j++) {
an[i][j] = -1;
}
}
ll w[n + 1], v[n + 1];
for (i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
k = maxwt(W, n, w, v);
cout << k;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
#define ll long long int
#define ps push_back
#define fs first
#define sc second
#define mkp make_pair
#define mod 1000000007
ll an[101][100001];
ll maxwt(ll W, ll n, ll w[], ll v[]) {
if (n == 0 || W == 0) {
return 0;
}
if (an[n][W] > -1)
return an[n][W];
if (w[n] > W) {
an[n][W] = maxwt(W, n - 1, w, v);
} else {
an[n][W] = max(maxwt(W, n - 1, w, v), v[n] + maxwt(W - w[n], n - 1, w, v));
}
return an[n][W];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, W, i, j, k, l;
cin >> n >> W;
for (i = 0; i < 101; i++) {
for (j = 0; j < 100001; j++) {
an[i][j] = -1;
}
}
ll w[n + 1], v[n + 1];
for (i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
k = maxwt(W, n, w, v);
cout << k;
return 0;
}
|
delete
| 27 | 31 | 27 | 27 |
-11
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define ll long long
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
int n, W;
ll w[100005], v[100005], memo[105][100005];
using namespace std;
ll dp(int i, int free_weight) {
if (memo[i][free_weight] != -1) {
return memo[i][free_weight];
}
if (i == n) {
return 0;
}
ll ret1 = 0, ret2;
if (free_weight - w[i] >= 0)
ret1 = v[i] + dp(i + 1, free_weight - w[i]);
ret2 = dp(i + 1, free_weight);
return max(ret1, ret2);
}
int main() {
scanf("%d%d", &n, &W);
for (int i = 0; i < n; ++i) {
scanf("%lld%lld", &w[i], &v[i]);
}
memset(memo, -1, sizeof memo);
printf("%lld", dp(0, W));
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl;
int n, W;
ll w[100005], v[100005], memo[105][100005];
using namespace std;
ll dp(int i, int free_weight) {
if (memo[i][free_weight] != -1) {
return memo[i][free_weight];
}
if (i == n) {
return 0;
}
ll ret1 = 0, ret2;
if (free_weight - w[i] >= 0)
ret1 = v[i] + dp(i + 1, free_weight - w[i]);
ret2 = dp(i + 1, free_weight);
return memo[i][free_weight] = max(ret1, ret2);
}
int main() {
scanf("%d%d", &n, &W);
for (int i = 0; i < n; ++i) {
scanf("%lld%lld", &w[i], &v[i]);
}
memset(memo, -1, sizeof memo);
printf("%lld", dp(0, W));
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
TLE
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.