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 <iostream>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<ll, int>
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vpii vector<pii>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
int n, k;
cin >> n >> k;
vi a;
vi b;
int x, y;
int sum = 0;
Fr(i, 0, n - 1) {
cin >> x >> y;
a.pb(x);
b.pb(y);
sum += x;
}
vvi dp(n + 1, vi(sum + 1, -1));
dp[0][0] = 0;
ll ans = 0;
Fr(i, 1, n) {
Fr(j, 0, min(sum, k)) {
dp[i][j] = dp[i - 1][j];
if (j - a[i - 1] >= 0 && dp[i - 1][j - a[i - 1]] != -1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i - 1]] + b[i - 1]);
}
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#include <iostream>
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<ll, int>
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vpii vector<pii>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>>t;
while (t--) {
int n, k;
cin >> n >> k;
vi a;
vi b;
int x, y;
int sum = 0;
Fr(i, 0, n - 1) {
cin >> x >> y;
a.pb(x);
b.pb(y);
sum += x;
}
vvi dp(n + 1, vi(min(k + 1, sum + 1), -1));
dp[0][0] = 0;
ll ans = 0;
Fr(i, 1, n) {
Fr(j, 0, min(sum, k)) {
dp[i][j] = dp[i - 1][j];
if (j - a[i - 1] >= 0 && dp[i - 1][j - a[i - 1]] != -1) {
dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i - 1]] + b[i - 1]);
}
ans = max(ans, dp[i][j]);
}
}
cout << ans << endl;
}
return 0;
}
|
replace
| 39 | 40 | 39 | 40 |
0
| |
p03163
|
C++
|
Runtime Error
|
//
// Created by Hideaki Imamura on 2020-03-15.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define EPS (1e-7)
// # define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
ll N, W;
ll w[110], v[110];
int main() {
cin >> N >> W;
for (int i = 0; i < N; ++i)
cin >> w[i] >> v[i];
vector<ll> dp(N + 1, 0);
for (int i = 0; i < N; ++i) {
for (int j = W; j >= 0; --j) {
if (j - w[i] >= 0)
chmax(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
|
//
// Created by Hideaki Imamura on 2020-03-15.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define EPS (1e-7)
// # define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
ll N, W;
ll w[110], v[110];
int main() {
cin >> N >> W;
for (int i = 0; i < N; ++i)
cin >> w[i] >> v[i];
vector<ll> dp(W + 1, 0);
for (int i = 0; i < N; ++i) {
for (int j = W; j >= 0; --j) {
if (j - w[i] >= 0)
chmax(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
|
replace
| 39 | 40 | 39 | 40 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long long W;
cin >> N >> W;
long long v[110], w[110];
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
long long dp[110][110];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j - w[i] >= 0)
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
long long W;
cin >> N >> W;
long long v[110], w[110];
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
long long dp[110][100010];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
if (j - w[i] >= 0)
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
else
dp[i + 1][j] = dp[i][j];
}
}
cout << dp[N][W] << endl;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ll long long int
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define MOD 1000000007
#define pb push_back
#define S second
#define F first
#define P pair<ll, ll>
#define PI 3.1415926535897932384626433832795028
// #define ordered_set tree<ll, null_type,less_equal<>,
// rb_tree_tag,tree_order_statistics_node_update>
int mul(int a, int b) { return (long long)a * b % MOD; }
int power(int a, int b) {
int ans = 1;
while (b > 0) {
if (b & 1)
ans = mul(ans, a);
a = mul(a, a);
b >>= 1;
}
return ans;
}
// bitset<400000010> b;
// ll n=100000;
ll p[1000100] = {0};
vector<ll> v[1000000];
void sieve(ll n) {
for (ll i = 2; i * i <= n; i++) {
if (!p[i])
// primes.push_back(i);
for (ll j = i; j <= n; j += i) {
if (i != j)
;
p[j] = 1;
}
}
}
// ll nextPowerOf2(ll n)
// {
// ll p = 1;
// if (n && !(n & (n - 1)))
// return n;
// while (p < n)
// p <<= 1;
// return p;
// }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll factorial(ll n) {
if (n == 0)
return 1;
return n * factorial(n - 1);
}
struct segmenttree {
vector<int> st;
int n;
void init(int _n) {
n = _n;
st.clear();
st.resize(4 * _n, 0);
}
void update(int l, int r, int indup, int val, int node) {
if (l == r) {
st[node] += val;
return;
} else {
int mid = (l + r) / 2;
if (indup >= l && indup <= mid) {
update(l, mid, indup, val, node * 2 + 1);
} else {
update(mid + 1, r, indup, val, node * 2 + 2);
}
st[node] = st[2 * node + 1] + st[2 * node + 2];
}
}
int query(int si, int se, int l, int r, int node) {
if (se < l || si > r || l > r) {
return 0;
}
if (si >= l && se <= r) {
return st[node];
}
int mid = (si + se) / 2;
int q1 = query(si, mid, l, r, node * 2 + 1);
int q2 = query(mid + 1, se, l, r, node * 2 + 2);
return q1 + q2;
}
int query(int l, int r) { return query(0, n - 1, l, r, 0); }
void update(int index, int val) { update(0, n - 1, index, val, 0); }
} tree;
bool chkcow(ll n, vector<ll> &a, ll k, ll mis) {
ll sum = 0;
for (ll i = 0; i < n; i++) {
if (a[i] > mis)
sum += a[i] - mis;
if (sum >= k)
return true;
}
return false;
}
struct cmp {
bool operator()(const pair<ll, ll> &a, const pair<ll, ll> &b) const {
ll lena = a.S - a.F;
ll lenb = b.S - b.F;
if (lena == lenb)
return a.F < b.F;
return lena > lenb;
}
};
bool isPerfect(int N) {
if ((sqrt(N) - floor(sqrt(N))) != 0)
return false;
return true;
}
int32_t main() {
fast
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n, w;
cin >> n >> w;
ll a[n], b[n];
for (ll i = 0; i < n; i++) {
cin >> b[i];
cin >> a[i];
}
ll dp[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (b[i - 1] <= j) {
dp[i][j] = max(dp[i - 1][j - b[i - 1]] + a[i - 1], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
#define ll long long int
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define MOD 1000000007
#define pb push_back
#define S second
#define F first
#define P pair<ll, ll>
#define PI 3.1415926535897932384626433832795028
// #define ordered_set tree<ll, null_type,less_equal<>,
// rb_tree_tag,tree_order_statistics_node_update>
int mul(int a, int b) { return (long long)a * b % MOD; }
int power(int a, int b) {
int ans = 1;
while (b > 0) {
if (b & 1)
ans = mul(ans, a);
a = mul(a, a);
b >>= 1;
}
return ans;
}
// bitset<400000010> b;
// ll n=100000;
ll p[1000100] = {0};
vector<ll> v[1000000];
void sieve(ll n) {
for (ll i = 2; i * i <= n; i++) {
if (!p[i])
// primes.push_back(i);
for (ll j = i; j <= n; j += i) {
if (i != j)
;
p[j] = 1;
}
}
}
// ll nextPowerOf2(ll n)
// {
// ll p = 1;
// if (n && !(n & (n - 1)))
// return n;
// while (p < n)
// p <<= 1;
// return p;
// }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll factorial(ll n) {
if (n == 0)
return 1;
return n * factorial(n - 1);
}
struct segmenttree {
vector<int> st;
int n;
void init(int _n) {
n = _n;
st.clear();
st.resize(4 * _n, 0);
}
void update(int l, int r, int indup, int val, int node) {
if (l == r) {
st[node] += val;
return;
} else {
int mid = (l + r) / 2;
if (indup >= l && indup <= mid) {
update(l, mid, indup, val, node * 2 + 1);
} else {
update(mid + 1, r, indup, val, node * 2 + 2);
}
st[node] = st[2 * node + 1] + st[2 * node + 2];
}
}
int query(int si, int se, int l, int r, int node) {
if (se < l || si > r || l > r) {
return 0;
}
if (si >= l && se <= r) {
return st[node];
}
int mid = (si + se) / 2;
int q1 = query(si, mid, l, r, node * 2 + 1);
int q2 = query(mid + 1, se, l, r, node * 2 + 2);
return q1 + q2;
}
int query(int l, int r) { return query(0, n - 1, l, r, 0); }
void update(int index, int val) { update(0, n - 1, index, val, 0); }
} tree;
bool chkcow(ll n, vector<ll> &a, ll k, ll mis) {
ll sum = 0;
for (ll i = 0; i < n; i++) {
if (a[i] > mis)
sum += a[i] - mis;
if (sum >= k)
return true;
}
return false;
}
struct cmp {
bool operator()(const pair<ll, ll> &a, const pair<ll, ll> &b) const {
ll lena = a.S - a.F;
ll lenb = b.S - b.F;
if (lena == lenb)
return a.F < b.F;
return lena > lenb;
}
};
bool isPerfect(int N) {
if ((sqrt(N) - floor(sqrt(N))) != 0)
return false;
return true;
}
int32_t main() {
fast
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
ll n,
w;
cin >> n >> w;
ll a[n], b[n];
for (ll i = 0; i < n; i++) {
cin >> b[i];
cin >> a[i];
}
ll dp[n + 1][w + 1];
for (ll i = 0; i <= n; i++) {
for (ll j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (b[i - 1] <= j) {
dp[i][j] = max(dp[i - 1][j - b[i - 1]] + a[i - 1], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][w] << endl;
return 0;
}
|
replace
| 137 | 142 | 137 | 143 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for (ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for (ll ii = (ss); ii >= (ll)(ee); --ii)
#define VALS(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
#define IAMSPEED \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define pb push_back
#define pf push_front
#define INF 1234567890ll
#define EPS (1e-7)
#define PI (acos((ld)-1.0))
#define ll long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
typedef pair<int, int> pi;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << '\n';
err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(ll x) {
stringstream s;
s << x;
return s.str();
}
ll stl(string x) {
stringstream s(x);
ll temp;
s >> temp;
return temp;
}
const int MOD = 1e9 + 7;
ll val[505], weight[505], dp[505];
int main() {
IAMSPEED
ll n, w;
cin >> n >> w;
for (ll i = 0; i < n; i++) {
cin >> weight[i] >> val[i];
}
for (ll i = 0; i < n; i++) {
for (ll j = w; j >= weight[i]; j--) {
dp[j] = max(dp[j], val[i] + dp[j - weight[i]]);
}
}
cout << dp[w];
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for (ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for (ll ii = (ss); ii >= (ll)(ee); --ii)
#define VALS(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
#define IAMSPEED \
ios_base::sync_with_stdio(false); \
cin.tie(0);
#define pb push_back
#define pf push_front
#define INF 1234567890ll
#define EPS (1e-7)
#define PI (acos((ld)-1.0))
#define ll long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
typedef pair<int, int> pi;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << '\n';
err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(ll x) {
stringstream s;
s << x;
return s.str();
}
ll stl(string x) {
stringstream s(x);
ll temp;
s >> temp;
return temp;
}
const int MOD = 1e9 + 7;
ll val[505], weight[505], dp[100005];
int main() {
IAMSPEED
ll n, w;
cin >> n >> w;
for (ll i = 0; i < n; i++) {
cin >> weight[i] >> val[i];
}
for (ll i = 0; i < n; i++) {
for (ll j = w; j >= weight[i]; j--) {
dp[j] = max(dp[j], val[i] + dp[j - weight[i]]);
}
}
cout << dp[w];
}
|
replace
| 46 | 47 | 46 | 47 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> dp(101, vector<long long>(1e5 + 1, -1));
long long sol(vector<vector<long long>> a, int i, int k) {
int n = a.size();
if (i >= n)
return 0;
if (dp[i][k] != -1)
return dp[i][k];
long long ans = sol(a, i + 1, k);
if (a[i][0] <= k)
ans = max(ans, sol(a, i + 1, k - a[i][0]) + a[i][1]);
return dp[i][k] = ans;
}
int main() {
int n, k;
cin >> n >> k;
vector<vector<long long>> a(n, vector<long long>(2));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++)
cin >> a[i][j];
}
dp[0][8] = sol(a, 0, k);
cout << dp[0][8] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> dp(101, vector<long long>(1e5 + 1, -1));
long long sol(vector<vector<long long>> &a, int i, int k) {
int n = a.size();
if (i >= n)
return 0;
if (dp[i][k] != -1)
return dp[i][k];
long long ans = sol(a, i + 1, k);
if (a[i][0] <= k)
ans = max(ans, sol(a, i + 1, k - a[i][0]) + a[i][1]);
return dp[i][k] = ans;
}
int main() {
int n, k;
cin >> n >> k;
vector<vector<long long>> a(n, vector<long long>(2));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++)
cin >> a[i][j];
}
dp[0][8] = sol(a, 0, k);
cout << dp[0][8] << endl;
}
|
replace
| 4 | 5 | 4 | 5 |
TLE
| |
p03163
|
C++
|
Time Limit Exceeded
|
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#define __clock__
#else
#pragma GCC optimize("Ofast")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;
// tourist set
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end
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;
}
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << '\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair
void no() {
p_no();
exit(0);
}
void yes() {
p_yes();
exit(0);
}
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);
ll memo[110][100100];
ll N, C;
VI W, V;
ll rec(ll i, ll c) {
if (i == N) {
return 0;
}
// i番目を選ぶ
ll a;
if (c >= W[i]) {
a = rec(i + 1, c - W[i]) + V[i];
} else {
a = 0;
}
// i番目を選ばない
ll b = rec(i + 1, c);
ll ans = max(a, b);
return memo[i][c] = ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// input
cin >> N >> C;
W.resize(N);
V.resize(N);
rep(i, N) { cin >> W[i] >> V[i]; }
ll ans = rec(0, C);
p(ans);
return 0;
}
|
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#define __clock__
#else
#pragma GCC optimize("Ofast")
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;
using PII = pair<ll, ll>;
// tourist set
template <typename A, typename B> string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N> string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end
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;
}
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << '\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())
#define MP make_pair
void no() {
p_no();
exit(0);
}
void yes() {
p_yes();
exit(0);
}
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);
ll memo[110][100100];
ll N, C;
VI W, V;
ll rec(ll i, ll c) {
if (memo[i][c])
return memo[i][c];
if (i == N) {
return 0;
}
// i番目を選ぶ
ll a;
if (c >= W[i]) {
a = rec(i + 1, c - W[i]) + V[i];
} else {
a = 0;
}
// i番目を選ばない
ll b = rec(i + 1, c);
ll ans = max(a, b);
return memo[i][c] = ans;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// input
cin >> N >> C;
W.resize(N);
V.resize(N);
rep(i, N) { cin >> W[i] >> V[i]; }
ll ans = rec(0, C);
p(ans);
return 0;
}
|
insert
| 142 | 142 | 142 | 144 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long dp[100][100005];
int main() {
int n, w;
long long m[105], v[105];
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> m[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= w; j++) {
if (m[i] <= j) {
dp[i + 1][j] = max(dp[i][j - m[i]] + v[i], dp[i][j]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
cout << dp[n][w] << '\n';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[105][100005];
int main() {
int n, w;
long long m[105], v[105];
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> m[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= w; j++) {
if (m[i] <= j) {
dp[i + 1][j] = max(dp[i][j - m[i]] + v[i], dp[i][j]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
cout << dp[n][w] << '\n';
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long int n, w;
cin >> n >> w;
long long int weight[n + 1], value[n + 1];
for (long long int i = 1; i <= n; i++)
cin >> weight[i] >> value[i];
long long int ans[n + 1][w + 1];
for (long long int i = 0; i <= n; i++)
ans[i][0] = 0;
for (long long int i = 0; i <= w; i++)
ans[0][i] = 0;
for (long long int i = 1; i <= n; i++) {
for (long long int j = 1; j <= w; j++) {
if ((j - weight[i]) >= 0) {
long long int fake = j - weight[i];
ans[i][j] = max(ans[i - 1][j], ans[i - 1][fake] + value[i]);
} else
ans[i][j] = ans[i - 1][j];
}
}
cout << ans[n][w] << endl;
return 1;
}
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long int n, w;
cin >> n >> w;
long long int weight[n + 1], value[n + 1];
for (long long int i = 1; i <= n; i++)
cin >> weight[i] >> value[i];
long long int ans[n + 1][w + 1];
for (long long int i = 0; i <= n; i++)
ans[i][0] = 0;
for (long long int i = 0; i <= w; i++)
ans[0][i] = 0;
for (long long int i = 1; i <= n; i++) {
for (long long int j = 1; j <= w; j++) {
if ((j - weight[i]) >= 0) {
long long int fake = j - weight[i];
ans[i][j] = max(ans[i - 1][j], ans[i - 1][fake] + value[i]);
} else
ans[i][j] = ans[i - 1][j];
}
}
cout << ans[n][w] << endl;
// return 1;
}
|
replace
| 23 | 24 | 23 | 24 |
1
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
#include <stdio.h>
#define Re register int
int N, W, w[105], v[105];
long long f[10005];
template <typename T> inline void read(T &var) {
T x = 0;
int w = 0;
char ch = 0;
while (!isdigit(ch))
w |= ch == '-', ch = getchar();
while (isdigit(ch))
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
var = w ? -x : x;
}
int main(int argc, char const *argv[]) {
read(N), read(W);
for (Re i = 1; i <= N; ++i)
read(w[i]), read(v[i]);
for (Re i = 1; i <= N; ++i)
for (Re j = W; j >= w[i]; --j)
f[j] = std::max(f[j], f[j - w[i]] + v[i]);
printf("%lld\n", f[W]);
return 0;
}
|
#include <iostream>
#include <stdio.h>
#define Re register int
int N, W, w[105], v[105];
long long f[100005];
template <typename T> inline void read(T &var) {
T x = 0;
int w = 0;
char ch = 0;
while (!isdigit(ch))
w |= ch == '-', ch = getchar();
while (isdigit(ch))
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
var = w ? -x : x;
}
int main(int argc, char const *argv[]) {
read(N), read(W);
for (Re i = 1; i <= N; ++i)
read(w[i]), read(v[i]);
for (Re i = 1; i <= N; ++i)
for (Re j = W; j >= w[i]; --j)
f[j] = std::max(f[j], f[j - w[i]] + v[i]);
printf("%lld\n", f[W]);
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define INF 1000000000
#define MAXN 110
#define MAXW 110
using namespace std;
int N, W;
long long dp[MAXW];
long long v[MAXN];
int w[MAXN];
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 = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W];
return 0;
}
|
#include <bits/stdc++.h>
#define INF 1000000000
#define MAXN 110
#define MAXW 110000
using namespace std;
int N, W;
long long dp[MAXW];
long long v[MAXN];
int w[MAXN];
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 = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W];
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define peso first
#define beneficio second
int n, m;
vector<pair<int, int>> num(100001);
long long dp[10005];
int main() {
cin >> n >> m;
for (int qq = 1; qq <= n; qq++) {
cin >> num[qq].peso >> num[qq].beneficio;
}
dp[0] = 0;
for (int qq = 1; qq <= n; qq++) {
for (int ww = m; ww >= num[qq].peso; ww--) {
dp[ww] = max(dp[ww], dp[ww - num[qq].peso] + num[qq].beneficio);
}
}
cout << dp[m];
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define peso first
#define beneficio second
int n, m;
vector<pair<int, int>> num(100001);
long long dp[100005];
int main() {
cin >> n >> m;
for (int qq = 1; qq <= n; qq++) {
cin >> num[qq].peso >> num[qq].beneficio;
}
dp[0] = 0;
for (int qq = 1; qq <= n; qq++) {
for (int ww = m; ww >= num[qq].peso; ww--) {
dp[ww] = max(dp[ww], dp[ww - num[qq].peso] + num[qq].beneficio);
}
}
cout << dp[m];
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define fastIO \
ios::sync_with_stdio(false); \
cin.tie(0);
#define ll long long
#define f(i, l, r) for (i = l; i < r; i++)
#define fd(i, l, r) for (i = l; i > r; i--)
#define mod 1000000007
#define pb push_back
using namespace std;
typedef pair<int, int> pi;
int main() {
fastIO int test = 1;
// cin >> test;
while (test--) {
int n, w;
cin >> n >> w;
int weight[n], i, j;
long int value[n];
f(i, 0, n) cin >> weight[i] >> value[i];
ll knapsack[n + 1][w + 1];
f(i, 0, n + 1) {
f(j, 0, w + 1) {
if (i == 0 || j == 0)
knapsack[i][j] = 0;
else if (weight[i - 1] <= w)
knapsack[i][j] =
max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]],
knapsack[i - 1][j]);
else
knapsack[i][j] = knapsack[i - 1][j];
}
}
cout << knapsack[n][w];
}
}
|
#include <bits/stdc++.h>
#define fastIO \
ios::sync_with_stdio(false); \
cin.tie(0);
#define ll long long
#define f(i, l, r) for (i = l; i < r; i++)
#define fd(i, l, r) for (i = l; i > r; i--)
#define mod 1000000007
#define pb push_back
using namespace std;
typedef pair<int, int> pi;
int main() {
fastIO int test = 1;
// cin >> test;
while (test--) {
int n, w;
cin >> n >> w;
int weight[n], i, j;
long int value[n];
f(i, 0, n) cin >> weight[i] >> value[i];
ll knapsack[n + 1][w + 1];
f(i, 0, n + 1) {
f(j, 0, w + 1) {
if (i == 0 || j == 0)
knapsack[i][j] = 0;
else if (weight[i - 1] <= j)
knapsack[i][j] =
max(value[i - 1] + knapsack[i - 1][j - weight[i - 1]],
knapsack[i - 1][j]);
else
knapsack[i][j] = knapsack[i - 1][j];
}
}
cout << knapsack[n][w];
}
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n, wt;
cin >> n >> wt;
vector<int> w(n + 1), v(n + 1);
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
vector<vector<int>> dp(n, vector<int>(wt + 1));
for (int i = 1; i <= n; i++)
for (int j = 0; j < wt + 1; j++)
dp[i][j] =
max(dp[i - 1][j], (j >= w[i] ? dp[i - 1][j - w[i]] + v[i] : -1));
cout << dp[n][wt];
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
int n, wt;
cin >> n >> wt;
vector<int> w(n + 1), v(n + 1);
for (int i = 1; i <= n; i++)
cin >> w[i] >> v[i];
vector<vector<int>> dp(n + 1, vector<int>(wt + 1));
for (int i = 1; i <= n; i++)
for (int j = 0; j < wt + 1; j++)
dp[i][j] =
max(dp[i - 1][j], (j >= w[i] ? dp[i - 1][j - w[i]] + v[i] : -1));
cout << dp[n][wt];
}
|
replace
| 9 | 10 | 9 | 10 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
int n, w;
long long greutate[105] = {0}, cost[105] = {0};
long long matrice[105][105] = {0};
void read() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
greutate[i] = x;
cost[i] = y;
}
}
void solve() {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= w; j++) {
matrice[i][j] = matrice[i - 1][j];
if (j >= greutate[i]) {
if (matrice[i - 1][j] > matrice[i - 1][j - greutate[i]] + cost[i])
matrice[i][j] = matrice[i - 1][j];
else
matrice[i][j] = matrice[i - 1][j - greutate[i]] + cost[i];
}
}
}
int main() {
read();
solve();
cout << matrice[n][w];
}
|
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
int n, w;
long long greutate[1000005] = {0}, cost[1000005] = {0};
long long matrice[105][1000005] = {0};
void read() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
greutate[i] = x;
cost[i] = y;
}
}
void solve() {
for (int i = 1; i <= n; i++)
for (int j = 1; j <= w; j++) {
matrice[i][j] = matrice[i - 1][j];
if (j >= greutate[i]) {
if (matrice[i - 1][j] > matrice[i - 1][j - greutate[i]] + cost[i])
matrice[i][j] = matrice[i - 1][j];
else
matrice[i][j] = matrice[i - 1][j - greutate[i]] + cost[i];
}
}
}
int main() {
read();
solve();
cout << matrice[n][w];
}
|
replace
| 5 | 7 | 5 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int N = 103;
long long weight[N], value[N], n, w;
long long dp[N][N];
long long solve(long long taille, long long w) {
if (taille < 0)
return 0;
if (dp[taille][w] != -1)
return dp[taille][w];
if (weight[taille - 1] > w)
return dp[taille][w] = solve(taille - 1, w);
else
return dp[taille][w] = max(solve(taille - 1, w - weight[taille - 1]) +
value[taille - 1],
solve(taille - 1, w));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
long long ans = solve(n, w);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 103;
long long weight[N], value[N], n, w;
long long dp[N][100003];
long long solve(long long taille, long long w) {
if (taille < 0)
return 0;
if (dp[taille][w] != -1)
return dp[taille][w];
if (weight[taille - 1] > w)
return dp[taille][w] = solve(taille - 1, w);
else
return dp[taille][w] = max(solve(taille - 1, w - weight[taille - 1]) +
value[taille - 1],
solve(taille - 1, w));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
long long ans = solve(n, w);
cout << ans;
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
#define nmax 101
using namespace std;
ifstream fin("p.in");
ofstream fout("p.out");
struct object {
long long val, g;
} obj[nmax];
int n, g_max;
long long sol;
long long val_curr[nmax][nmax * nmax];
int main() {
cin >> n >> g_max;
for (int i = 1; i <= n; i++)
cin >> obj[i].g >> obj[i].val;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= g_max; j++) {
if (obj[i].g <= j)
val_curr[i][j] =
max(obj[i].val + val_curr[i - 1][j - obj[i].g], val_curr[i - 1][j]);
else
val_curr[i][j] = val_curr[i - 1][j];
}
cout << val_curr[n][g_max];
return 0;
}
|
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
#define nmax 101
using namespace std;
ifstream fin("p.in");
ofstream fout("p.out");
struct object {
long long val, g;
} obj[nmax];
int n, g_max;
long long sol;
long long val_curr[nmax][nmax * nmax * 10];
int main() {
cin >> n >> g_max;
for (int i = 1; i <= n; i++)
cin >> obj[i].g >> obj[i].val;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= g_max; j++) {
if (obj[i].g <= j)
val_curr[i][j] =
max(obj[i].val + val_curr[i - 1][j - obj[i].g], val_curr[i - 1][j]);
else
val_curr[i][j] = val_curr[i - 1][j];
}
cout << val_curr[n][g_max];
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const ll INF = 1e9;
inline ll read() {
ll X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
ll dp[105][10005];
ll v[105];
ll w[105];
int main() {
ll n, c;
cin >> n >> c;
for (ll i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= c; 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];
}
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= c; j++) {
ans = max(dp[i][j], ans);
}
}
cout << ans;
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const ll INF = 1e9;
inline ll read() {
ll X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch))
X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
ll dp[105][100005];
ll v[105];
ll w[105];
int main() {
ll n, c;
cin >> n >> c;
for (ll i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= c; 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];
}
}
ll ans = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= c; j++) {
ans = max(dp[i][j], ans);
}
}
cout << ans;
return 0;
}
|
replace
| 35 | 36 | 35 | 36 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// #include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define ones(n) __builtin_popcount(n)
#define ONES(n) __builtin_popcountll(n)
using namespace std;
// using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> ii;
typedef pair<long long, pair<int, int>> iii;
typedef pair<ii, ii> iiii;
const double PI = acos(-1.0), EPS = 1e-6;
const int N = 100005, M = 102, mod = 998244353, mxLog = 20;
int n, w;
int W[M], V[M];
long long memo[M][N];
long long solve(int i, int cur_w) {
if (i == n)
return 0;
long long &ret = memo[i][cur_w];
if (~ret)
return ret;
ret = solve(i + 1, cur_w);
if (cur_w + W[i] <= w) {
ret = max(ret, solve(i + 1, cur_w + W[i]) + V[i]);
}
return ret;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "rt", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(7),
cout << fixed;
cin >> n >> w;
for (int i = 0; i < n; ++i) {
cin >> W[i] >> V[i];
}
memset(memo, -1, sizeof memo);
cout << solve(0, 0) << '\n';
return 0;
}
|
#include <bits/stdc++.h>
// #include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define ones(n) __builtin_popcount(n)
#define ONES(n) __builtin_popcountll(n)
using namespace std;
// using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<int, int> ii;
typedef pair<long long, pair<int, int>> iii;
typedef pair<ii, ii> iiii;
const double PI = acos(-1.0), EPS = 1e-6;
const int N = 100005, M = 102, mod = 998244353, mxLog = 20;
int n, w;
int W[M], V[M];
long long memo[M][N];
long long solve(int i, int cur_w) {
if (i == n)
return 0;
long long &ret = memo[i][cur_w];
if (~ret)
return ret;
ret = solve(i + 1, cur_w);
if (cur_w + W[i] <= w) {
ret = max(ret, solve(i + 1, cur_w + W[i]) + V[i]);
}
return ret;
}
int main() {
#ifndef ONLINE_JUDGE
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(7),
cout << fixed;
cin >> n >> w;
for (int i = 0; i < n; ++i) {
cin >> W[i] >> V[i];
}
memset(memo, -1, sizeof memo);
cout << solve(0, 0) << '\n';
return 0;
}
|
replace
| 40 | 41 | 40 | 41 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int maxi = 105;
long long M[maxi][2], dp[maxi][maxi];
long long f(int n, int s) {
if (n < 0 || s <= 0)
return 0;
if (dp[n][s] != -1)
return dp[n][s];
if (s - M[n][0] < 0)
return dp[n][s] = f(n - 1, s);
return dp[n][s] = max(M[n][1] + f(n - 1, s - M[n][0]), f(n - 1, s));
}
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> M[i][0] >> M[i][1];
memset(dp, -1, sizeof(dp));
cout << f(n - 1, w);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxi = 1e5 + 10;
long long M[105][2], dp[105][maxi];
long long f(int n, int s) {
if (n < 0 || s <= 0)
return 0;
if (dp[n][s] != -1)
return dp[n][s];
if (s - M[n][0] < 0)
return dp[n][s] = f(n - 1, s);
return dp[n][s] = max(M[n][1] + f(n - 1, s - M[n][0]), f(n - 1, s));
}
int main() {
int n, w;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> M[i][0] >> M[i][1];
memset(dp, -1, sizeof(dp));
cout << f(n - 1, w);
return 0;
}
|
replace
| 2 | 4 | 2 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
int a[111], wi[111];
long long dp[111111];
bool d[111111];
int main() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> wi[i] >> a[i];
}
d[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = w; j >= 0; j--) {
if (d[j] == 1) {
d[j + wi[i]] = 1;
dp[j + wi[i]] = max(dp[j + wi[i]], dp[j] + a[i]);
}
}
}
long long m = 0;
for (int i = 1; i <= w; i++) {
m = max(dp[i], m);
}
cout << m;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int a[111], wi[111];
long long dp[111111];
bool d[111111];
int main() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> wi[i] >> a[i];
}
d[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = w; j >= 0; j--) {
if (d[j] == 1 && j + wi[i] <= w) {
d[j + wi[i]] = 1;
dp[j + wi[i]] = max(dp[j + wi[i]], dp[j] + a[i]);
}
}
}
long long m = 0;
for (int i = 1; i <= w; i++) {
m = max(dp[i], m);
}
cout << m;
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define N 100005
#define M 10000000000
#define endl "\n"
using namespace std;
int m;
int Wt;
int wt[101];
long long val[101];
long long dp[100][N];
long long maxCost(int n, int W) {
if (n - 1 < 0)
return 0;
if (W == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W)
return dp[n][W] = max(val[n - 1] + maxCost(n - 1, W - wt[n - 1]),
maxCost(n - 1, W));
else
return dp[n][W] = maxCost(n - 1, W);
}
int32_t main() {
cin >> m >> Wt;
for (int i = 0; i < m; ++i) {
cin >> wt[i] >> val[i];
}
memset(dp, -1, sizeof(dp));
cout << maxCost(m, Wt) << endl;
}
|
#include <bits/stdc++.h>
#define N 100005
#define M 10000000000
#define endl "\n"
using namespace std;
int m;
int Wt;
int wt[101];
long long val[101];
long long dp[101][N];
long long maxCost(int n, int W) {
if (n - 1 < 0)
return 0;
if (W == 0)
return 0;
if (dp[n][W] != -1)
return dp[n][W];
if (wt[n - 1] <= W)
return dp[n][W] = max(val[n - 1] + maxCost(n - 1, W - wt[n - 1]),
maxCost(n - 1, W));
else
return dp[n][W] = maxCost(n - 1, W);
}
int32_t main() {
cin >> m >> Wt;
for (int i = 0; i < m; ++i) {
cin >> wt[i] >> val[i];
}
memset(dp, -1, sizeof(dp));
cout << maxCost(m, Wt) << endl;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03163
|
C++
|
Runtime Error
|
// In the name of God:)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
long long dp[MAXN], w[MAXN], v[MAXN];
int main() {
long long n, mw;
long long ans = 0;
scanf("%lld%lld", &n, &mw);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", w + i, v + i);
for (int j = mw; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
ans = max(ans, dp[j]);
}
}
printf("%lld\n", ans);
}
|
// In the name of God:)
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long dp[MAXN], w[MAXN], v[MAXN];
int main() {
long long n, mw;
long long ans = 0;
scanf("%lld%lld", &n, &mw);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", w + i, v + i);
for (int j = mw; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
ans = max(ans, dp[j]);
}
}
printf("%lld\n", ans);
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
template <typename T> inline int Chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline int Chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
T sum = 0;
int fl = 1, ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
fl = -1;
for (; isdigit(ch); ch = getchar())
sum = (sum << 3) + (sum << 1) + ch - '0';
return sum * fl;
}
const int maxn = 100 + 5;
int n, W;
int dp[maxn];
struct node {
int w;
int v;
} a[maxn];
inline void Solve() {
for (int i = 1; i <= n; i++) {
for (int j = W; j >= a[i].w; j--) {
dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
}
printf("%lld\n", dp[W]);
}
inline void Input() {
n = read<int>();
W = read<int>();
for (int i = 1; i <= n; i++) {
a[i].w = read<int>();
a[i].v = read<int>();
}
}
signed main() {
Input();
Solve();
return 0;
}
|
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
template <typename T> inline int Chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T> inline int Chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
T sum = 0;
int fl = 1, ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
fl = -1;
for (; isdigit(ch); ch = getchar())
sum = (sum << 3) + (sum << 1) + ch - '0';
return sum * fl;
}
const int maxn = 100000 + 5;
int n, W;
int dp[maxn];
struct node {
int w;
int v;
} a[maxn];
inline void Solve() {
for (int i = 1; i <= n; i++) {
for (int j = W; j >= a[i].w; j--) {
dp[j] = max(dp[j], dp[j - a[i].w] + a[i].v);
}
}
printf("%lld\n", dp[W]);
}
inline void Input() {
n = read<int>();
W = read<int>();
for (int i = 1; i <= n; i++) {
a[i].w = read<int>();
a[i].v = read<int>();
}
}
signed main() {
Input();
Solve();
return 0;
}
|
replace
| 28 | 29 | 28 | 29 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mfill(x, y) memset(x, y, sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
// typedef pair<int, int> mpair;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int n, m;
ul w[101], v[101];
ul dt[100][100001];
ul dp(int p, int nw) {
ul res = 0;
if (dt[p][nw] != -1) {
return dt[p][nw];
}
if (p == n) {
res = 0;
} else if (w[p] + nw > m) {
res = dp(p + 1, nw);
} else {
res = max(dp(p + 1, nw), v[p] + dp(p + 1, nw + w[p]));
}
return dt[p][nw] = res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
memset(dt, -1, sizeof(dt));
rep(i, n) { cin >> w[i] >> v[i]; }
cout << dp(0, 0) << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mfill(x, y) memset(x, y, sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
// typedef pair<int, int> mpair;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int n, m;
ul w[101], v[101];
ul dt[101][100001];
ul dp(int p, int nw) {
ul res = 0;
if (dt[p][nw] != -1) {
return dt[p][nw];
}
if (p == n) {
res = 0;
} else if (w[p] + nw > m) {
res = dp(p + 1, nw);
} else {
res = max(dp(p + 1, nw), v[p] + dp(p + 1, nw + w[p]));
}
return dt[p][nw] = res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
memset(dt, -1, sizeof(dt));
rep(i, n) { cin >> w[i] >> v[i]; }
cout << dp(0, 0) << endl;
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll n, W;
ll weight[110], value[110];
ll dp[110][100010];
int main() {
int i, w;
cin >> n >> W;
for (i = 0; i < n; ++i)
cin >> weight[i] >> value[i];
for (w = 0; w <= W; w++)
dp[w][0] = 0;
for (i = 0; i < n; i++) {
for (w = 0; w <= W; w++) {
if (weight[i] <= w)
dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + value[i]);
else
dp[i + 1][w] = dp[i][w];
}
}
cout << dp[n][W] << endl;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll n, W;
ll weight[110], value[110];
ll dp[110][100010];
int main() {
int i, w;
cin >> n >> W;
for (i = 0; i < n; ++i)
cin >> weight[i] >> value[i];
for (w = 0; w <= W; w++)
dp[0][w] = 0;
for (i = 0; i < n; i++) {
for (w = 0; w <= W; w++) {
if (weight[i] <= w)
dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + value[i]);
else
dp[i + 1][w] = dp[i][w];
}
}
cout << dp[n][W] << endl;
}
|
replace
| 20 | 21 | 20 | 21 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 105, W = 1e5 + 10;
inline char get() {
static char buf[10000], *S = buf, *T = buf;
if (S == T) {
T = (S = buf) + fread(buf, 1, 100000, stdin);
if (S == T)
return EOF;
}
return *S++;
}
inline void read(int &x) {
static char c;
x = 0;
int sgn = 0;
for (c = get(); c < '0' || c > '9'; c = get())
if (c == '-')
sgn = 1;
for (; c >= '0' && c <= '9'; c = get())
x = x * 10 + c - '0';
if (sgn)
x = -x;
}
int n, totw;
ll dp[W];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read(n);
read(totw);
for (int i = 0; i < n; i++) {
int w, v;
read(w);
read(v);
for (int j = totw; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << *max_element(dp, dp + W) << nl;
return 0;
}
|
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 105, W = 1e5 + 10;
inline char get() {
static char buf[10000], *S = buf, *T = buf;
if (S == T) {
T = (S = buf) + fread(buf, 1, 10000, stdin);
if (S == T)
return EOF;
}
return *S++;
}
inline void read(int &x) {
static char c;
x = 0;
int sgn = 0;
for (c = get(); c < '0' || c > '9'; c = get())
if (c == '-')
sgn = 1;
for (; c >= '0' && c <= '9'; c = get())
x = x * 10 + c - '0';
if (sgn)
x = -x;
}
int n, totw;
ll dp[W];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read(n);
read(totw);
for (int i = 0; i < n; i++) {
int w, v;
read(w);
read(v);
for (int j = totw; j >= w; j--) {
dp[j] = max(dp[j], dp[j - w] + v);
}
}
cout << *max_element(dp, dp + W) << nl;
return 0;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
// THIS IS MY NINJA WAY
#include <algorithm>
#include <bits/stdc++.h>
#include <ctime>
#include <vector>
#define str string
#define dbl double
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll pair<ll, ll>
#define vll vector<pll>
#define sl set<ll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define fast \
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \
srand(time(NULL));
#define fr(i, a, b) for (long long i = a; i < b; i++)
#define nfr(i, a, b) for (long long i = a; i <= b; i++)
#define psl pair<str, ll>
#define pls pair<ll, str>
#define pss pair<str, str>
#define ALL(a) a.begin(), a.end()
#define stl stack<ll>
#define coml complex<ll>
#define INF 0x3f3f3f3f3f3f3f3f
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
const ll MOD = 1e9 + 7;
using namespace std;
ll knapSack(ll W, vl wt, vl val, ll n) {
if (n == 0 || W == 0)
return 0;
if (wt[n - 1] > W)
return knapSack(W, wt, val, n - 1);
else
return max(val[n - 1] + knapSack(W - wt[n - 1], wt, val, n - 1),
knapSack(W, wt, val, n - 1));
}
int main() {
fast
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w" , stdout);
#endif*/
ll n,
W;
cin >> n >> W;
vl wt(n), val(n);
fr(i, 0, n) { cin >> wt[i] >> val[i]; }
cout << knapSack(W, wt, val, n);
return 0;
}
|
// THIS IS MY NINJA WAY
#include <algorithm>
#include <bits/stdc++.h>
#include <ctime>
#include <vector>
#define str string
#define dbl double
#define ll long long
#define vl vector<ll>
#define vs vector<str>
#define pll pair<ll, ll>
#define vll vector<pll>
#define sl set<ll>
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
#define fast \
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \
srand(time(NULL));
#define fr(i, a, b) for (long long i = a; i < b; i++)
#define nfr(i, a, b) for (long long i = a; i <= b; i++)
#define psl pair<str, ll>
#define pls pair<ll, str>
#define pss pair<str, str>
#define ALL(a) a.begin(), a.end()
#define stl stack<ll>
#define coml complex<ll>
#define INF 0x3f3f3f3f3f3f3f3f
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
const ll MOD = 1e9 + 7;
using namespace std;
ll knapSack(ll W, vl wt, vl val, ll n) {
ll K[n + 1][W + 1];
fr(i, 0, n + 1) {
fr(j, 0, W + 1) {
if (i == 0 || j == 0)
K[i][j] = 0;
else if (wt[i - 1] <= j)
K[i][j] = max(val[i - 1] + K[i - 1][j - wt[i - 1]], K[i - 1][j]);
else
K[i][j] = K[i - 1][j];
}
}
return K[n][W];
}
int main() {
fast
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r" , stdin);
freopen("output.txt", "w" , stdout);
#endif*/
ll n,
W;
cin >> n >> W;
vl wt(n), val(n);
fr(i, 0, n) { cin >> wt[i] >> val[i]; }
cout << knapSack(W, wt, val, n);
return 0;
}
|
replace
| 37 | 44 | 37 | 49 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, W;
cin >> n >> W;
long long w[n + 1], v[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
long long mat[n + 1][W + 1];
memset(mat, 0, sizeof(mat));
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j <= W; j++) {
if (!i || !j) {
mat[i][j] = 0;
} else if (j > w[i]) {
mat[i][j] = mat[i - 1][j];
} else {
mat[i][j] = max(mat[i - 1][j], v[i] + mat[i - 1][j - w[i]]);
}
}
}
cout << mat[n][W] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, W;
cin >> n >> W;
long long w[n + 1], v[n + 1];
for (long long i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
long long mat[n + 1][W + 1];
memset(mat, 0, sizeof(mat));
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j <= W; j++) {
if (!i || !j) {
mat[i][j] = 0;
} else if (j < w[i]) {
mat[i][j] = mat[i - 1][j];
} else {
mat[i][j] = max(mat[i - 1][j], v[i] + mat[i - 1][j - w[i]]);
}
}
}
cout << mat[n][W] << endl;
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int fINF = 0x3f3f3f3f;
const int nINF = 1 << 31;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;
/////////////////////////////////////////////////////////////////////
const int N = 100 + 10, C = 1e5 + 10;
int n, c, v[N], w[N];
ll dp[N][C];
signed main() {
ios::sync_with_stdio(false);
// cout << fixed << setprecision(7);
memset(dp, -1, sizeof(dp));
cin >> n >> c;
FOR(i, 1, n) cin >> w[i] >> v[i];
dp[0][c] = 0;
FOR(i, 1, n) {
FORD(j, c, 0) {
if (dp[i - 1][j] != -1) {
if (j - w[i] >= 0)
dp[i][j - w[i]] = max(dp[i][j - w[j]], dp[i - 1][j] + v[i]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
}
ll ans = 0;
FOR(i, 0, c) ans = max(ans, dp[n][i]);
cout << ans << endl;
return 0;
}
// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)
// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int fINF = 0x3f3f3f3f;
const int nINF = 1 << 31;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;
/////////////////////////////////////////////////////////////////////
const int N = 100 + 10, C = 1e5 + 10;
int n, c, v[N], w[N];
ll dp[N][C];
signed main() {
ios::sync_with_stdio(false);
// cout << fixed << setprecision(7);
memset(dp, -1, sizeof(dp));
cin >> n >> c;
FOR(i, 1, n) cin >> w[i] >> v[i];
dp[0][c] = 0;
FOR(i, 1, n) {
FORD(j, c, 0) {
if (dp[i - 1][j] != -1) {
if (j - w[i] >= 0)
dp[i][j - w[i]] = max(dp[i][j - w[i]], dp[i - 1][j] + v[i]);
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
}
ll ans = 0;
FOR(i, 0, c) ans = max(ans, dp[n][i]);
cout << ans << endl;
return 0;
}
// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)
// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
|
replace
| 52 | 53 | 52 | 53 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
// Problem : E - Knapsack 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int, int>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repe(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (int i = b; i >= a; i--)
#define maxn 105
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
int inv(int a, int b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; }
int mp[105][100005];
int n, w;
pp arr[maxn];
int fun(int l, int wt) {
if (l == 0 || wt == 0)
return 0;
if (mp[l][w] != -1)
return mp[l][w];
int x = 0;
if (arr[l].ff <= wt)
x = arr[l].ss + fun(l - 1, wt - arr[l].ff);
x = max(x, fun(l - 1, wt));
mp[l][wt] = x;
return x;
}
void solve() {
memset(mp, -1, sizeof(mp));
cin >> n >> w;
repe(i, 1, n) {
int x, y;
cin >> x >> y;
arr[i] = {x, y};
}
cout << fun(n, w);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
|
// Problem : E - Knapsack 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int, int>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repe(i, a, b) for (int i = a; i <= b; i++)
#define repr(i, a, b) for (int i = b; i >= a; i--)
#define maxn 105
#define ss second
#define ff first
#define all(a) a.begin(), a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
int inv(int a, int b) { return 1 < a ? b - inv(b % a, a) * b / a : 1; }
int mp[105][100005];
int n, w;
pp arr[maxn];
int fun(int l, int wt) {
if (l == 0 || wt == 0)
return 0;
if (mp[l][wt] != -1)
return mp[l][wt];
int x = 0;
if (arr[l].ff <= wt)
x = arr[l].ss + fun(l - 1, wt - arr[l].ff);
x = max(x, fun(l - 1, wt));
mp[l][wt] = x;
return x;
}
void solve() {
memset(mp, -1, sizeof(mp));
cin >> n >> w;
repe(i, 1, n) {
int x, y;
cin >> x >> y;
arr[i] = {x, y};
}
cout << fun(n, w);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
|
replace
| 38 | 40 | 38 | 40 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h> // g++ -std=c++14 -o a a.cpp
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main() {
int N, W;
cin >> N >> W;
ll weight[101] = {0};
ll value[101] = {0};
ll vmax[101][10001] = {0};
rep(i, N) {
int wi, vi;
cin >> wi >> vi;
weight[i] = wi;
value[i] = vi;
}
rep(j, W + 1) {
if (j < weight[N - 1]) {
vmax[N - 1][j] = 0;
} else {
vmax[N - 1][j] = value[N - 1];
}
}
for (int i = N - 2; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < weight[i]) {
vmax[i][j] = vmax[i + 1][j];
} else {
vmax[i][j] = max(vmax[i + 1][j], value[i] + vmax[i + 1][j - weight[i]]);
}
}
}
// rep(i, N) {
// rep(j, W + 1) {
// DEBUG(i);
// DEBUG(j);
// DEBUG(vmax[i][j]);
// }
// }
cout << vmax[0][W] << endl;
}
|
#include <bits/stdc++.h> // g++ -std=c++14 -o a a.cpp
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repto(i, n) for (int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main() {
int N, W;
cin >> N >> W;
ll weight[101] = {0};
ll value[101] = {0};
ll vmax[101][100001] = {0};
rep(i, N) {
int wi, vi;
cin >> wi >> vi;
weight[i] = wi;
value[i] = vi;
}
rep(j, W + 1) {
if (j < weight[N - 1]) {
vmax[N - 1][j] = 0;
} else {
vmax[N - 1][j] = value[N - 1];
}
}
for (int i = N - 2; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < weight[i]) {
vmax[i][j] = vmax[i + 1][j];
} else {
vmax[i][j] = max(vmax[i + 1][j], value[i] + vmax[i + 1][j - weight[i]]);
}
}
}
// rep(i, N) {
// rep(j, W + 1) {
// DEBUG(i);
// DEBUG(j);
// DEBUG(vmax[i][j]);
// }
// }
cout << vmax[0][W] << endl;
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int n, w;
long a[101][2];
long dp[101][100001];
long solve(int n, int w) { // cout<<n<<" "<<w<<endl;
if (w < 0)
return (-a[n + 1][1] - 1);
if (n == 1) {
if (a[1][0] <= w) {
dp[1][w] = a[1][1];
} else
dp[1][w] = 0; //-a[n+1][1]-1;
return dp[1][w];
} // basecase
else {
dp[n][w] = max(solve(n - 1, w), solve(n - 1, w - a[n][0]) + a[n][1]);
return dp[n][w];
}
}
int main() {
// your code goes here
cin >> n >> w;
for (int i = 1; i <= n; ++i)
cin >> a[i][0] >> a[i][1];
cout << solve(n, w);
/*for(int i=1;i<=n;++i){
for(int j=1;j<=w;++j){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
}
|
#include <bits/stdc++.h>
using namespace std;
int n, w;
long a[101][2];
long dp[101][100001];
long solve(int n, int w) { // cout<<n<<" "<<w<<endl;
if (w < 0)
return (-a[n + 1][1] - 1);
if (n == 1) {
if (a[1][0] <= w) {
dp[1][w] = a[1][1];
} else
dp[1][w] = 0; //-a[n+1][1]-1;
return dp[1][w];
} // basecase
if (dp[n][w])
return dp[n][w];
else {
dp[n][w] = max(solve(n - 1, w), solve(n - 1, w - a[n][0]) + a[n][1]);
return dp[n][w];
}
}
int main() {
// your code goes here
cin >> n >> w;
for (int i = 1; i <= n; ++i)
cin >> a[i][0] >> a[i][1];
cout << solve(n, w);
/*for(int i=1;i<=n;++i){
for(int j=1;j<=w;++j){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
}
|
insert
| 16 | 16 | 16 | 18 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> p;
const int maxn = 100000 + 10;
ll dp[110][maxn];
int n;
vector<p> snacks;
ll dfs(int step, int restSize) {
if (step == n or restSize == 0)
return 0;
if (dp[step][restSize] != -1)
return dp[step][restSize];
ll value = 0;
if (restSize >= snacks[step].first) {
value = max(value, dfs(step + 1, restSize - snacks[step].first) +
snacks[step].second);
}
value = max(value, dfs(step + 1, restSize));
return dp[step][restSize] = value;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int w;
cin >> n >> w;
snacks.resize(n);
for (int i = 0; i < maxn; i++)
for (int j = 0; j < 110; j++)
dp[i][j] = -1;
for (int i = 0; i < n; i++)
cin >> snacks[i].first >> snacks[i].second;
cout << dfs(0, w) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> p;
const int maxn = 100000 + 10;
ll dp[110][maxn];
int n;
vector<p> snacks;
ll dfs(int step, int restSize) {
if (step == n or restSize == 0)
return 0;
if (dp[step][restSize] != -1)
return dp[step][restSize];
ll value = 0;
if (restSize >= snacks[step].first) {
value = max(value, dfs(step + 1, restSize - snacks[step].first) +
snacks[step].second);
}
value = max(value, dfs(step + 1, restSize));
return dp[step][restSize] = value;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int w;
cin >> n >> w;
snacks.resize(n);
for (int i = 0; i < maxn; i++)
for (int j = 0; j < 110; j++)
dp[j][i] = -1;
for (int i = 0; i < n; i++)
cin >> snacks[i].first >> snacks[i].second;
cout << dfs(0, w) << endl;
return 0;
}
|
replace
| 41 | 42 | 41 | 42 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
int N, G, p[5005], w[5005], a[10005], b[10005], i, j;
int main() {
// ifstream cin("rucsac.in");
cin >> N >> G;
for (i = 1; i <= N; i++) {
cin >> w[i] >> p[i];
}
for (i = 1; i <= N; ++i) {
for (j = 1; j <= G; ++j) {
if (w[i] > j)
a[j] = b[j];
else {
a[j] = max(b[j], b[j - w[i]] + p[i]);
}
}
for (j = 1; j <= G; ++j)
b[j] = a[j];
}
cout << a[G];
}
|
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
int N, G, i, j;
long long p[105], w[105], a[100005], b[100005];
int main() {
// ifstream cin("rucsac.in");
cin >> N >> G;
for (i = 1; i <= N; i++) {
cin >> w[i] >> p[i];
}
for (i = 1; i <= N; ++i) {
for (j = 1; j <= G; ++j) {
if (w[i] > j)
a[j] = b[j];
else {
a[j] = max(b[j], b[j - w[i]] + p[i]);
}
}
for (j = 1; j <= G; ++j)
b[j] = a[j];
}
cout << a[G];
}
|
replace
| 5 | 7 | 5 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long int num, w;
int wat[100000 + 5];
int val[100000 + 5];
long long dp[1000][1000];
long long knapsack(long long wt, long long n) {
long long &ret = dp[wt][n];
if (wt == 0 || n == 0)
return 0;
if (ret != -1)
return ret;
ret = 0;
if (wat[n - 1] > wt)
ret = knapsack(wt, n - 1);
else {
ret = max(ret, max((val[n - 1] + knapsack(wt - wat[n - 1], n - 1)),
knapsack(wt, n - 1)));
}
return ret;
}
int main() {
cin >> num >> w;
for (int i = 0; i < num; i++) {
scanf("%lld %lld", &wat[i], &val[i]);
}
memset(dp, -1, sizeof dp);
long long ans = knapsack(w, num);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int num, w;
int wat[100000 + 5];
int val[100000 + 5];
long long dp[100010][105];
long long knapsack(long long wt, long long n) {
long long &ret = dp[wt][n];
if (wt == 0 || n == 0)
return 0;
if (ret != -1)
return ret;
ret = 0;
if (wat[n - 1] > wt)
ret = knapsack(wt, n - 1);
else {
ret = max(ret, max((val[n - 1] + knapsack(wt - wat[n - 1], n - 1)),
knapsack(wt, n - 1)));
}
return ret;
}
int main() {
cin >> num >> w;
for (int i = 0; i < num; i++) {
scanf("%lld %lld", &wat[i], &val[i]);
}
memset(dp, -1, sizeof dp);
long long ans = knapsack(w, num);
cout << ans << endl;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// 解説AC
int main() {
ll n, w;
cin >> n >> w;
vector<vector<ll>> item(n + 1, vector<ll>(2, 0));
vector<vector<ll>> dp(n + 1, vector<ll>(w, 0));
for (size_t i = 1; i <= n; i++) //[i][0]が重さ [i][1]が価値
{
cin >> item[i][0] >> item[i][1];
}
for (size_t i = 1; i <= n; i++) // 1-indexed
{
// 品物iを選んだとして、選んだ方が価値が大きくなるならdp[i][w]を更新
for (size_t j = 0; j <= w; j++) {
if (j >= item[i][0]) {
ll weight = item[i][0];
ll value = item[i][1];
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight] + value);
} else {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
// 今までと、そのアイテムの重さ
}
cout << dp[n][w] << endl;
/*
rep(i,n+1)
{ cout<<"dp["<<i<<"] : ";
rep(j,w+1)
{
cout << dp[i][j] <<" ";
}
cout<<endl;
}*/
return 0;
}
|
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// 解説AC
int main() {
ll n, w;
cin >> n >> w;
vector<vector<ll>> item(n + 1, vector<ll>(2, 0));
vector<vector<ll>> dp(n + 1, vector<ll>(w + 1, 0));
for (size_t i = 1; i <= n; i++) //[i][0]が重さ [i][1]が価値
{
cin >> item[i][0] >> item[i][1];
}
for (size_t i = 1; i <= n; i++) // 1-indexed
{
// 品物iを選んだとして、選んだ方が価値が大きくなるならdp[i][w]を更新
for (size_t j = 0; j <= w; j++) {
if (j >= item[i][0]) {
ll weight = item[i][0];
ll value = item[i][1];
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weight] + value);
} else {
dp[i][j] = max(dp[i][j], dp[i - 1][j]);
}
}
// 今までと、そのアイテムの重さ
}
cout << dp[n][w] << endl;
/*
rep(i,n+1)
{ cout<<"dp["<<i<<"] : ";
rep(j,w+1)
{
cout << dp[i][j] <<" ";
}
cout<<endl;
}*/
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long dp[10002], w[102], v[102];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = m; j - w[i] >= 0; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
long long ans = 0;
for (int i = 0; i <= m; i++) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long dp[100002], w[102], v[102];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < n; i++) {
for (int j = m; j - w[i] >= 0; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
long long ans = 0;
for (int i = 0; i <= m; i++) {
ans = max(ans, dp[i]);
}
cout << ans << endl;
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int w[105], val[105];
long long dp[10005];
int main() {
int t, m, res = -1;
scanf("%d%d", &m, &t);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &w[i], &val[i]);
}
for (int i = 1; i <= m; i++) {
for (int j = t; j >= 0; j--) {
if (j >= w[i]) {
dp[j] = max(dp[j - w[i]] + val[i], dp[j]);
}
}
}
printf("%lld\n", dp[t]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int w[105], val[105];
long long dp[100005];
int main() {
int t, m, res = -1;
scanf("%d%d", &m, &t);
for (int i = 1; i <= m; i++) {
scanf("%d%d", &w[i], &val[i]);
}
for (int i = 1; i <= m; i++) {
for (int j = t; j >= 0; j--) {
if (j >= w[i]) {
dp[j] = max(dp[j - w[i]] + val[i], dp[j]);
}
}
}
printf("%lld\n", dp[t]);
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// #define ll long long
long long int dp[10005][10005];
// int val[100005];
// int wt[100005];
long long int fun(long long int w, long long int n, long long int val[],
long long int wt[]) {
if (w == 0 || n == 0)
return 0;
if (wt[n - 1] > w)
return dp[w][n] = fun(w, n - 1, val, wt);
if (dp[w][n] != -1)
return dp[w][n];
return dp[w][n] = max(fun(w - wt[n - 1], n - 1, val, wt) + val[n - 1],
fun(w, n - 1, val, wt));
}
int main() {
long long int n, w;
cin >> n >> w;
memset(dp, -1, sizeof(dp));
long long int val[n + 1];
long long int wt[n + 1];
for (long long int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
}
cout << fun(w, n, val, wt);
}
|
#include <bits/stdc++.h>
using namespace std;
// #define ll long long
long long int dp[100005][105];
// int val[100005];
// int wt[100005];
long long int fun(long long int w, long long int n, long long int val[],
long long int wt[]) {
if (w == 0 || n == 0)
return 0;
if (wt[n - 1] > w)
return dp[w][n] = fun(w, n - 1, val, wt);
if (dp[w][n] != -1)
return dp[w][n];
return dp[w][n] = max(fun(w - wt[n - 1], n - 1, val, wt) + val[n - 1],
fun(w, n - 1, val, wt));
}
int main() {
long long int n, w;
cin >> n >> w;
memset(dp, -1, sizeof(dp));
long long int val[n + 1];
long long int wt[n + 1];
for (long long int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
}
cout << fun(w, n, val, wt);
}
|
replace
| 3 | 4 | 3 | 4 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n, w, dp[107];
int main() {
cin >> n >> w;
for (ll i = 0; i < n; ++i) {
ll weight, value;
cin >> weight >> value;
for (ll j = w - weight; j >= 0; --j) {
dp[j + weight] = max(dp[j + weight], dp[j] + value);
}
}
cout << dp[w] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n, w, dp[100007];
int main() {
cin >> n >> w;
for (ll i = 0; i < n; ++i) {
ll weight, value;
cin >> weight >> value;
for (ll j = w - weight; j >= 0; --j) {
dp[j + weight] = max(dp[j + weight], dp[j] + value);
}
}
cout << dp[w] << endl;
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define MOD int(1e9 + 9)
#define PI 3.1415926535898
using namespace std;
int main(int argc, char const *argv[]) {
ll dp[1001][100001], val[101], w[101], n, W;
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> val[i];
}
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= W; j++) {
if (i == 0 && j == 0)
dp[i][j] = 0;
if (j < w[i - 1]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]);
}
}
}
cout << dp[n][W] << endl;
}
|
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define MOD int(1e9 + 9)
#define PI 3.1415926535898
using namespace std;
int main(int argc, char const *argv[]) {
ll dp[101][100001], val[101], w[101], n, W;
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> val[i];
}
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= W; j++) {
if (i == 0 && j == 0)
dp[i][j] = 0;
if (j < w[i - 1]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], val[i - 1] + dp[i - 1][j - w[i - 1]]);
}
}
}
cout << dp[n][W] << endl;
}
|
replace
| 7 | 8 | 7 | 8 |
-11
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <memory>
#include <numeric>
#include <array>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <ostream>
#include <type_traits>
#include <utility>
#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
#endif
using namespace std;
using u64 = uint64_t;
using i64 = int64_t;
using u32 = uint32_t;
using vi = vector<int>;
using vi64 = vector<i64>;
#define seq(i, a, b) for (int i = (a); i < (b); ++i)
#define rev(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) (x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) \
{ cerr << #x << ": " << x << endl; }
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, maxw;
cin >> n >> maxw;
vi64 dp(maxw + 1);
dp[0] = 0;
seq(_, 1, maxw + 1) {
int w, v;
cin >> w >> v;
rev(i, 0, maxw - w + 1) { dp[i + w] = max(dp[i] + v, dp[i + w]); }
}
cout << dp[maxw] << endl;
}
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <memory>
#include <numeric>
#include <array>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <ostream>
#include <type_traits>
#include <utility>
#ifdef ONLINE_JUDGE
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2")
#endif
using namespace std;
using u64 = uint64_t;
using i64 = int64_t;
using u32 = uint32_t;
using vi = vector<int>;
using vi64 = vector<i64>;
#define seq(i, a, b) for (int i = (a); i < (b); ++i)
#define rev(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define sz(x) (x.size())
#define all(x) x.begin(), x.end()
#define dbg(x) \
{ cerr << #x << ": " << x << endl; }
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, maxw;
cin >> n >> maxw;
vi64 dp(maxw + 1);
dp[0] = 0;
seq(_, 0, n) {
int w, v;
cin >> w >> v;
rev(i, 0, maxw - w + 1) { dp[i + w] = max(dp[i] + v, dp[i + w]); }
}
cout << dp[maxw] << endl;
}
|
replace
| 49 | 50 | 49 | 50 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5, maxw = 100;
int n, W;
int w[maxn];
int v[maxn];
int dp[maxw][maxn];
int32_t main() {
scanf("%lld%lld", &n, &W);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &w[i], &v[i]);
}
for (int i = 0; i <= W; i++) {
if (i >= w[0]) {
dp[i][0] = v[0];
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (w[i] <= j) {
dp[j][i] = max(v[i] + dp[j - w[i]][i - 1], dp[j][i - 1]);
} else {
dp[j][i] = dp[j][i - 1];
}
}
}
printf("%lld\n", dp[W][n - 1]);
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 100 + 10, maxw = 1e5 + 10;
int n, W;
int w[maxn];
int v[maxn];
int dp[maxw][maxn];
int32_t main() {
scanf("%lld%lld", &n, &W);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", &w[i], &v[i]);
}
for (int i = 0; i <= W; i++) {
if (i >= w[0]) {
dp[i][0] = v[0];
}
}
for (int i = 1; i < n; i++) {
for (int j = 0; j <= W; j++) {
if (w[i] <= j) {
dp[j][i] = max(v[i] + dp[j - w[i]][i - 1], dp[j][i - 1]);
} else {
dp[j][i] = dp[j][i - 1];
}
}
}
printf("%lld\n", dp[W][n - 1]);
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int MAX = 100005;
const int INF = 1e9 + 7;
typedef long long ll;
ll dp[105][MAX] = {0};
int main() {
cin.tie(0);
ios::sync_with_stdio(0); // この2行はより速度を向上させる
// 追加2, 以降 cin の入力元が 'input.txt' になる
// 提出時に消す!!
std::ifstream in("sample.txt");
std::cin.rdbuf(in.rdbuf());
int N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
dp[i + 1][j] = dp[i][j];
if (j - w[i] >= 0) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
}
}
}
cout << dp[N][W] << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
const int MAX = 100005;
const int INF = 1e9 + 7;
typedef long long ll;
ll dp[105][MAX] = {0};
int main() {
cin.tie(0);
ios::sync_with_stdio(0); // この2行はより速度を向上させる
// 追加2, 以降 cin の入力元が 'input.txt' になる
// 提出時に消す!!
// std::ifstream in("sample.txt");
// std::cin.rdbuf(in.rdbuf());
int N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
dp[i + 1][j] = dp[i][j];
if (j - w[i] >= 0) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
}
}
}
cout << dp[N][W] << endl;
return 0;
}
|
replace
| 62 | 64 | 62 | 64 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
void rwf() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int N = 105, mxW = 1e5 + 5;
int n, W, w[N], v[N];
int dp[N][mxW];
int solve(int wr, int m) {
if (m == 0 || wr == 0)
return 0;
if (dp[m][wr] != -1)
return dp[m][wr];
if (wr - w[m] < 0)
return dp[m][wr] = solve(wr, m - 1);
return dp[m][wr] = max(solve(wr, m - 1), v[m] + solve(wr - w[m], m - 1));
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
rwf();
cin >> n >> W;
memset(&dp, -1, sizeof(dp));
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
int ans = solve(W, n);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
void rwf() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
const int N = 105, mxW = 1e5 + 5;
int n, W, w[N], v[N];
int dp[N][mxW];
int solve(int wr, int m) {
if (m == 0 || wr == 0)
return 0;
if (dp[m][wr] != -1)
return dp[m][wr];
if (wr - w[m] < 0)
return dp[m][wr] = solve(wr, m - 1);
return dp[m][wr] = max(solve(wr, m - 1), v[m] + solve(wr - w[m], m - 1));
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// rwf();
cin >> n >> W;
memset(&dp, -1, sizeof(dp));
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
int ans = solve(W, n);
cout << ans;
return 0;
}
|
replace
| 37 | 38 | 37 | 38 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
ll max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll lowbit(ll x) { return x & (-x); }
ll prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= int(sqrt(x)); i++) {
if (x % i == 0)
return false;
}
return true;
}
bool cmp(ll a, ll b) { return a > b; }
ll gcd(ll a, ll b) {
ll r;
while (b > 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
inline int readint() {
char c = getchar();
int w = 1;
int x = 0;
while (!isdigit(c))
(c == '-') && (w = -w), c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
x *= w;
return x;
}
inline ll readll() {
char c = getchar();
ll w = 1;
ll x = 0;
while (!isdigit(c))
(c == '-') && (w = -w), c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
x *= w;
return x;
}
void fl(string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll n, W;
const int MAXN = 110;
ll w[MAXN], v[MAXN], dp[10010];
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 = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
/* stuff to remember
* int overflow, array bounds
* special cases (n=1? n=0?)
* do something instead of nothing and stay organized
* USE STATIC ARRAYS
* DEFINING ARRAYS BEFORE main()
* DO NOT DEFINE ARRAYS IN main()
* USE INT INSTEAD OF LL,NOTICE THE MLE
*/
|
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
ll max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll lowbit(ll x) { return x & (-x); }
ll prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= int(sqrt(x)); i++) {
if (x % i == 0)
return false;
}
return true;
}
bool cmp(ll a, ll b) { return a > b; }
ll gcd(ll a, ll b) {
ll r;
while (b > 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
inline int readint() {
char c = getchar();
int w = 1;
int x = 0;
while (!isdigit(c))
(c == '-') && (w = -w), c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
x *= w;
return x;
}
inline ll readll() {
char c = getchar();
ll w = 1;
ll x = 0;
while (!isdigit(c))
(c == '-') && (w = -w), c = getchar();
while (isdigit(c))
x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
x *= w;
return x;
}
void fl(string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll n, W;
const int MAXN = 110;
ll w[MAXN], v[MAXN], dp[100100];
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 = W; j >= w[i]; j--) {
dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
}
}
cout << dp[W] << endl;
return 0;
}
/* stuff to remember
* int overflow, array bounds
* special cases (n=1? n=0?)
* do something instead of nothing and stay organized
* USE STATIC ARRAYS
* DEFINING ARRAYS BEFORE main()
* DO NOT DEFINE ARRAYS IN main()
* USE INT INSTEAD OF LL,NOTICE THE MLE
*/
|
replace
| 92 | 93 | 92 | 93 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n) {
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
for (size_t k = 0; k < n; k++) {
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); }
ll powMod(ll a, ll p) {
if (p == 0) {
return 1;
} else if (p % 2 == 0) {
ll half = powMod(a, p / 2);
return mulMod(half, half);
} else {
return mulMod(powMod(a, p - 1), a);
}
}
ll dp[110][100100] = {0};
void solve(long long N, long long W, std::vector<long long> w,
std::vector<long long> v) {
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
dp[i + 1][j] = max(dp[i + i][j], dp[i][j]);
if (j - w[i] >= 0) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
}
}
}
cout << dp[N][W] << endl;
}
int main() {
long long N;
scanf("%lld", &N);
long long W;
scanf("%lld", &W);
std::vector<long long> w(N);
std::vector<long long> v(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &w[i]);
scanf("%lld", &v[i]);
}
solve(N, W, std::move(w), std::move(v));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const int INF = 1e9;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n) {
for (size_t i = 0; i < n; i++) {
for (size_t j = 0; j < n; j++) {
for (size_t k = 0; k < n; k++) {
dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
}
}
}
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); }
ll powMod(ll a, ll p) {
if (p == 0) {
return 1;
} else if (p % 2 == 0) {
ll half = powMod(a, p / 2);
return mulMod(half, half);
} else {
return mulMod(powMod(a, p - 1), a);
}
}
ll dp[110][100100] = {0};
void solve(long long N, long long W, std::vector<long long> w,
std::vector<long long> v) {
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
if (j - w[i] >= 0) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
}
}
}
cout << dp[N][W] << endl;
}
int main() {
long long N;
scanf("%lld", &N);
long long W;
scanf("%lld", &W);
std::vector<long long> w(N);
std::vector<long long> v(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &w[i]);
scanf("%lld", &v[i]);
}
solve(N, W, std::move(w), std::move(v));
return 0;
}
|
replace
| 49 | 50 | 49 | 50 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int floor(int a, int b) { return (a + b - 1) / b; };
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
int dp[100][100001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << setiosflags(ios::fixed);
int n, W;
cin >> n >> W;
vi w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
rep(i, n) rep(j, W + 1) {
if (j - w[i] < 0)
dp[i + 1][j] = dp[i][j];
else {
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
cout << dp[n][W] << en;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int floor(int a, int b) { return (a + b - 1) / b; };
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
ll dp[101][100001];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << setiosflags(ios::fixed);
int n, W;
cin >> n >> W;
vi w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
rep(i, n) rep(j, W + 1) {
if (j - w[i] < 0)
dp[i + 1][j] = dp[i][j];
else {
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
cout << dp[n][W] << en;
}
|
replace
| 40 | 41 | 40 | 41 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) \
for (auto x : a) \
cout << x << ' '; \
cout << '\n';
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define OTP(s) cout << s << endl;
#define FOR(i, j, k, l) for (int i = j; i < k; i += l)
#define REP(i, j) FOR(i, 0, j, 1)
inline ll add(ll a, ll b) {
a += b;
if (a >= MOD)
a -= MOD;
return a;
}
inline ll sub(ll a, ll b) {
a -= b;
if (a < 0)
a += MOD;
return a;
}
inline ll mul(ll a, ll b) { return (ll)((ll)a * b % MOD); }
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
ll min(ll a, ll b) { return a > b ? b : a; }
ll max(ll a, ll b) { return a > b ? a : b; }
ll n, w;
ll dp[100][100001];
ll we[200], v[200];
int main() {
IOS cin >> n >> w;
REP(i, n) { cin >> we[i + 1] >> v[i + 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 (we[i] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - we[i]]);
}
}
}
// REP(i,n+1)
// {
// REP(j,w+1)
// {
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[n][w] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define MOD 1000000007
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define prv(a) \
for (auto x : a) \
cout << x << ' '; \
cout << '\n';
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define OTP(s) cout << s << endl;
#define FOR(i, j, k, l) for (int i = j; i < k; i += l)
#define REP(i, j) FOR(i, 0, j, 1)
inline ll add(ll a, ll b) {
a += b;
if (a >= MOD)
a -= MOD;
return a;
}
inline ll sub(ll a, ll b) {
a -= b;
if (a < 0)
a += MOD;
return a;
}
inline ll mul(ll a, ll b) { return (ll)((ll)a * b % MOD); }
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
ll min(ll a, ll b) { return a > b ? b : a; }
ll max(ll a, ll b) { return a > b ? a : b; }
ll n, w;
ll dp[200][100001];
ll we[200], v[200];
int main() {
IOS cin >> n >> w;
REP(i, n) { cin >> we[i + 1] >> v[i + 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 (we[i] > j) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - we[i]]);
}
}
}
// REP(i,n+1)
// {
// REP(j,w+1)
// {
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[n][w] << endl;
}
|
replace
| 50 | 51 | 50 | 51 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < (n); i++)
#define rrep(i, m, n) for (int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x, y) cout << (x) << " " << (y) << endl;
#define printa(x, n) \
for (int i = 0; i < n; i++) { \
cout << (x[i]) << " "; \
} \
cout << endl;
#define printa2(x, m, n) \
for (int i = 0; i < m; i++) { \
for (int j = 0; j < n; j++) { \
cout << x[i][j] << " "; \
} \
cout << endl; \
}
#define printp(x, n) \
for (int i = 0; i < n; i++) { \
cout << "(" << x[i].first << ", " << x[i].second << ") "; \
} \
cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct {
ll to;
ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll dp[110][100010] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, W;
ll w[110], v[110];
cin >> N >> W;
rep(i, 0, N) cin >> w[i] >> v[i];
ll dp[10010] = {};
rep(i, 0, N) {
rrep(j, W, w[i]) { dp[j] = max(dp[j], dp[j - w[i]] + v[i]); }
}
print(dp[W]);
// ll N,W;
// ll w[110], v[110];
// cin >> N >> W;
// rep(i,0,N){
// cin >> w[i] >> v[i];
// }
// rep(i,0,N){
// rep(j,0,W+1){
// if(j - w[i] >= 0){
// dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
// }else{
// dp[i+1][j] = dp[i][j];
// }
// }
// }
// print(dp[N][W]);
}
|
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < (n); i++)
#define rrep(i, m, n) for (int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x, y) cout << (x) << " " << (y) << endl;
#define printa(x, n) \
for (int i = 0; i < n; i++) { \
cout << (x[i]) << " "; \
} \
cout << endl;
#define printa2(x, m, n) \
for (int i = 0; i < m; i++) { \
for (int j = 0; j < n; j++) { \
cout << x[i][j] << " "; \
} \
cout << endl; \
}
#define printp(x, n) \
for (int i = 0; i < n; i++) { \
cout << "(" << x[i].first << ", " << x[i].second << ") "; \
} \
cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct {
ll to;
ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll dp[110][100010] = {};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, W;
ll w[110], v[110];
cin >> N >> W;
rep(i, 0, N) cin >> w[i] >> v[i];
ll dp[100010] = {};
rep(i, 0, N) {
rrep(j, W, w[i]) { dp[j] = max(dp[j], dp[j - w[i]] + v[i]); }
}
print(dp[W]);
// ll N,W;
// ll w[110], v[110];
// cin >> N >> W;
// rep(i,0,N){
// cin >> w[i] >> v[i];
// }
// rep(i,0,N){
// rep(j,0,W+1){
// if(j - w[i] >= 0){
// dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
// }else{
// dp[i+1][j] = dp[i][j];
// }
// }
// }
// print(dp[N][W]);
}
|
replace
| 40 | 41 | 40 | 41 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int n;
int peso[1000];
long long int valor[1000];
long long int dp[100][100001];
int calculado[100][100001];
long long int solve(int ind, int aguenta) {
if (ind == n && aguenta >= 0) {
return 0LL;
}
/*if(calculado[ind][aguenta] == true){
return dp[ind][aguenta];
}*/
long long int ans = solve(ind + 1, aguenta);
if (peso[ind] <= aguenta) {
ans = max(ans, valor[ind] + solve(ind + 1, aguenta - peso[ind]));
}
calculado[ind][aguenta] = true;
dp[ind][aguenta] = ans;
return ans;
}
int main() {
int k;
cin >> n >> k;
memset(calculado, 0, sizeof calculado);
for (int i = 0; i < n; i++) {
cin >> peso[i] >> valor[i];
}
cout << solve(0, k) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
int peso[1000];
long long int valor[1000];
long long int dp[100][100001];
int calculado[100][100001];
long long int solve(int ind, int aguenta) {
if (ind == n && aguenta >= 0) {
return 0LL;
}
if (calculado[ind][aguenta] == true) {
return dp[ind][aguenta];
}
long long int ans = solve(ind + 1, aguenta);
if (peso[ind] <= aguenta) {
ans = max(ans, valor[ind] + solve(ind + 1, aguenta - peso[ind]));
}
calculado[ind][aguenta] = true;
dp[ind][aguenta] = ans;
return ans;
}
int main() {
int k;
cin >> n >> k;
memset(calculado, 0, sizeof calculado);
for (int i = 0; i < n; i++) {
cin >> peso[i] >> valor[i];
}
cout << solve(0, k) << endl;
return 0;
}
|
replace
| 12 | 15 | 12 | 15 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define LOCAL 1
#define UPLOAD 2
#define ll long long
const long long INF = 1LL << 60;
template <class T = long long> T input() {
T x;
cin >> x;
return x;
}
template <class T> void output(T x) { cout << x << endl; }
#define debug(x) cerr << #x << ": " << x << '\n';
#define debugBit(x, n) cerr << #x << ": " << std::bitset<n>(x) << '\n';
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
const long long mod = 1e9 + 7;
int main() {
#if ENVIRONMENT == LOCAL
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
ll N = input();
ll W = input();
std::vector<std::pair<ll, ll>> values;
for (int i = 0; i < N; i++) {
values.push_back({input(), input()});
}
vector<vector<ll>> dp(N + 1, vector<ll>(W));
for (ll i = 0; i < N; i++) {
for (ll w = 0; w <= W; w++) {
if (values[i].first <= w) {
chmax(dp[i + 1][w], dp[i][w - values[i].first] + values[i].second);
}
chmax(dp[i + 1][w], dp[i][w]);
}
}
output(dp[N][W]);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define LOCAL 1
#define UPLOAD 2
#define ll long long
const long long INF = 1LL << 60;
template <class T = long long> T input() {
T x;
cin >> x;
return x;
}
template <class T> void output(T x) { cout << x << endl; }
#define debug(x) cerr << #x << ": " << x << '\n';
#define debugBit(x, n) cerr << #x << ": " << std::bitset<n>(x) << '\n';
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
const long long mod = 1e9 + 7;
int main() {
#if ENVIRONMENT == LOCAL
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
ll N = input();
ll W = input();
std::vector<std::pair<ll, ll>> values;
for (int i = 0; i < N; i++) {
values.push_back({input(), input()});
}
vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
for (ll i = 0; i < N; i++) {
for (ll w = 0; w <= W; w++) {
if (values[i].first <= w) {
chmax(dp[i + 1][w], dp[i][w - values[i].first] + values[i].second);
}
chmax(dp[i + 1][w], dp[i][w]);
}
}
output(dp[N][W]);
return 0;
}
|
replace
| 55 | 56 | 55 | 56 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <cstring>
#include <iostream>
using namespace std;
struct Item {
long long val;
int wgt;
};
long long dp[100][100002];
Item *obj;
long long knapsck(int n, int w) {
if (n == 0 || w < 0)
return 0ll;
if (dp[n][w] != -1)
return dp[n][w];
long long a = -1;
if (w - obj[n - 1].wgt >= 0)
a = knapsck(n - 1, w - obj[n - 1].wgt) + obj[n - 1].val;
long long b = knapsck(n - 1, w);
return dp[n][w] = max(a, b);
}
int main() {
int n, w;
cin >> n >> w;
memset(dp, -1, sizeof(dp));
obj = new Item[n];
for (int i = 0; i < n; i++)
cin >> obj[i].wgt >> obj[i].val;
cout << knapsck(n, w);
return 0;
}
|
#include <cstring>
#include <iostream>
using namespace std;
struct Item {
long long val;
int wgt;
};
long long dp[101][100002];
Item *obj;
long long knapsck(int n, int w) {
if (n == 0 || w < 0)
return 0ll;
if (dp[n][w] != -1)
return dp[n][w];
long long a = -1;
if (w - obj[n - 1].wgt >= 0)
a = knapsck(n - 1, w - obj[n - 1].wgt) + obj[n - 1].val;
long long b = knapsck(n - 1, w);
return dp[n][w] = max(a, b);
}
int main() {
int n, w;
cin >> n >> w;
memset(dp, -1, sizeof(dp));
obj = new Item[n];
for (int i = 0; i < n; i++)
cin >> obj[i].wgt >> obj[i].val;
cout << knapsck(n, w);
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define MAXN 10005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;
int n, k, w[MAXN], v[MAXN];
LL ans, f[MAXN];
int main() {
scanf("%d%d", &n, &k);
for (rint i = 1; i <= n; ++i)
scanf("%d%d", &w[i], &v[i]);
for (rint i = 1; i <= n; ++i) {
for (rint j = k; j >= w[i]; j--)
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
for (rint i = 0; i <= k; ++i)
ans = max(f[i], ans);
printf("%lld\n", ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define MAXN 100005
#define INF 0x3f3f3f3f
#define rint register int
#define LL long long
#define LD long double
using namespace std;
int n, k, w[MAXN], v[MAXN];
LL ans, f[MAXN];
int main() {
scanf("%d%d", &n, &k);
for (rint i = 1; i <= n; ++i)
scanf("%d%d", &w[i], &v[i]);
for (rint i = 1; i <= n; ++i) {
for (rint j = k; j >= w[i]; j--)
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
for (rint i = 0; i <= k; ++i)
ans = max(f[i], ans);
printf("%lld\n", ans);
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = a; i < b; ++i)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, W;
cin >> N >> W;
vector<ll> weights(N + 1), values(N + 1);
for (int i = 1; i <= N; ++i)
cin >> weights[i] >> values[i];
vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
for (int i = 0; i <= W; ++i)
dp[0][i] = 0;
for (int i = 1; i <= N; ++i) {
for (int j = 1; i <= W; ++j) {
if (weights[i] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + values[i]);
}
}
cout << dp[N][W] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i, a, b) for (int i = a; i < b; ++i)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll N, W;
cin >> N >> W;
vector<ll> weights(N + 1), values(N + 1);
for (int i = 1; i <= N; ++i)
cin >> weights[i] >> values[i];
vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
for (int i = 0; i <= W; ++i)
dp[0][i] = 0;
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= W; ++j) {
if (weights[i] > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - weights[i]] + values[i]);
}
}
cout << dp[N][W] << "\n";
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (n - 1); i >= (a); i--)
#define F first
#define S second
#define maxx(a, b) a = max(a, b)
#define minn(a, b) a = min(a, b)
#define db(x) cerr << #x << " = " << x << endl
#define N 1111111
#define mod 1000000007
#define rt return
#define inf 12345678908761
using namespace std;
ll a[111111], w[111], v[111];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("Ulug'bek","r",stdin);
// freopen("Abdimanabov","w",stdout);
int n, W;
cin >> n >> W;
rep(i, 1, n + 1) cin >> w[i] >> v[i];
memset(a + 1, -1, sizeof a);
rep(i, 1, n + 1) per(j, w[i], W + 1) if (a[j - w[i]] != -1)
maxx(a[j], a[j - w[i]] + v[i]);
cout << *max_element(a, a + W + 1);
rt 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
typedef double ld;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define per(i, a, n) for (ll i = (n - 1); i >= (a); i--)
#define F first
#define S second
#define maxx(a, b) a = max(a, b)
#define minn(a, b) a = min(a, b)
#define db(x) cerr << #x << " = " << x << endl
#define N 1111111
#define mod 1000000007
#define rt return
#define inf 12345678908761
using namespace std;
ll a[111111], w[111], v[111];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("Ulug'bek","r",stdin);
// freopen("Abdimanabov","w",stdout);
int n, W;
cin >> n >> W;
rep(i, 1, n + 1) cin >> w[i] >> v[i];
memset(a, -1, sizeof a);
a[0] = 0;
rep(i, 1, n + 1) per(j, w[i], W + 1) if (a[j - w[i]] != -1)
maxx(a[j], a[j - w[i]] + v[i]);
cout << *max_element(a, a + W + 1);
rt 0;
}
|
replace
| 33 | 34 | 33 | 35 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <cstdlib>
#include <iostream>
#include <limits>
using namespace std;
int imax = std::numeric_limits<int>::max();
long long dp[100][100002], i, j, n, k, w, vi[100], wi[100];
int main() {
// cout<<"P:";
cin >> n >> w;
for (i = 1; i <= n; i++)
cin >> wi[i] >> vi[i];
for (i = 1; i <= n; i++) {
for (j = 0; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j - wi[i] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - wi[i]] + vi[i]);
}
}
/*
for(i=1;i<=n;i++)
{
for(j=1;j<=w;j++)
cout<<dp[i][j]<<" ";
cout<<"\n";
}
*/
cout << dp[n][w];
return 0;
}
|
#include <cstdlib>
#include <iostream>
#include <limits>
using namespace std;
int imax = std::numeric_limits<int>::max();
long long dp[101][100002], i, j, n, k, w, vi[101], wi[101];
int main() {
// cout<<"P:";
cin >> n >> w;
for (i = 1; i <= n; i++)
cin >> wi[i] >> vi[i];
for (i = 1; i <= n; i++) {
for (j = 0; j <= w; j++) {
dp[i][j] = dp[i - 1][j];
if (j - wi[i] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - wi[i]] + vi[i]);
}
}
/*
for(i=1;i<=n;i++)
{
for(j=1;j<=w;j++)
cout<<dp[i][j]<<" ";
cout<<"\n";
}
*/
cout << dp[n][w];
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
// using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
// const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) {
return a.second < b.second;
} // End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;
int n;
ll W;
ll w[120], v[120];
ll dp[120][120];
ll rec(int i, int j) {
if (dp[i][j] >= 0)
return dp[i][j];
ll res;
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]);
return dp[i][j] = res;
}
int main(void) {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
printf("%lld\n", rec(0, W));
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
// using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
// const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) {
return a.second < b.second;
} // End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;
int n;
ll W;
ll w[120], v[120];
ll dp[120][100010];
ll rec(int i, int j) {
if (dp[i][j] >= 0)
return dp[i][j];
ll res;
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]);
return dp[i][j] = res;
}
int main(void) {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
printf("%lld\n", rec(0, W));
return 0;
}
|
replace
| 20 | 21 | 20 | 21 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
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;
}
// using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) {
return a.second < b.second;
} // End sort (Interval scheduling problem)
int n, W;
ll w[110], v[110];
ll dp[110][110];
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 (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]);
}
}
}
printf("%lld\n", dp[n][W]);
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
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;
}
// using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) {
return a.second < b.second;
} // End sort (Interval scheduling problem)
int n, W;
ll w[110], v[110];
ll dp[110][100010];
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 (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]);
}
}
}
printf("%lld\n", dp[n][W]);
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define int ll
#define print(x) cerr << (#x) << "is " << x << "\n"
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 1e5 + 10;
int n, w, dp[110][N];
int a[110][2];
int dfs(int in, int we) {
if (we < 0) {
return INT_MIN;
}
if (we == 0)
return 0;
if (in == n) {
if (we - a[n][0] >= 0) {
return a[n][1];
} else {
return 0;
}
}
int &ans = dp[in][we];
if (ans != -1)
return ans;
ans = 0;
return ans =
max({ans, dfs(in + 1, we - a[in][0]) + a[in][1], dfs(in + 1, we)});
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin >> n >> w;
f(i, 1, n + 1) { cin >> a[i][0] >> a[i][1]; }
f(i, 1, n + 1) {
f(j, 0, w + 10) { dp[i][j] = -1; }
}
cout << dfs(1, w) << '\n';
// f(i,1,n+1){
// f(j,0,w+1){
// cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
// }
// }
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i, x, n) for (int i = x; i < n; i++)
#define all(c) c.begin(), c.end()
#define int ll
#define print(x) cerr << (#x) << "is " << x << "\n"
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7, N = 1e5 + 10;
int n, w, dp[110][N];
int a[110][2];
int dfs(int in, int we) {
if (we < 0) {
return INT_MIN;
}
if (we == 0)
return 0;
if (in == n) {
if (we - a[n][0] >= 0) {
return a[n][1];
} else {
return 0;
}
}
int &ans = dp[in][we];
if (ans != -1)
return ans;
ans = 0;
return ans =
max({ans, dfs(in + 1, we - a[in][0]) + a[in][1], dfs(in + 1, we)});
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
cin >> n >> w;
f(i, 1, n + 1) { cin >> a[i][0] >> a[i][1]; }
f(i, 1, n + 1) {
f(j, 0, w + 10) { dp[i][j] = -1; }
}
cout << dfs(1, w) << '\n';
// f(i,1,n+1){
// f(j,0,w+1){
// cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
// }
// }
return 0;
}
|
replace
| 41 | 45 | 41 | 45 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
#define ll long long
using namespace std;
int main() {
int n, c;
cin >> n >> c;
ll wt[103], v[103];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[103][103];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= c; j++) {
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][c];
}
|
#include <iostream>
#define ll long long
using namespace std;
int main() {
int n, c;
cin >> n >> c;
ll wt[103], v[103];
for (int i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
}
ll dp[103][c + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= c; j++) {
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][c];
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int w[100], v[100];
int n, W;
long long dp[100][100001];
long long solve(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
long long res;
if (i == n)
res = 0;
else if (j < w[i])
res = solve(i + 1, j);
else
res = max(solve(i + 1, j), solve(i + 1, j - w[i]) + v[i]);
return dp[i][j] = res;
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
long long ans = solve(0, W);
cout << ans << endl;
}
|
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int w[100], v[100];
int n, W;
long long dp[101][100001];
long long solve(int i, int j) {
if (dp[i][j] != -1)
return dp[i][j];
long long res;
if (i == n)
res = 0;
else if (j < w[i])
res = solve(i + 1, j);
else
res = max(solve(i + 1, j), solve(i + 1, j - w[i]) + v[i]);
return dp[i][j] = res;
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> w[i] >> v[i];
memset(dp, -1, sizeof(dp));
long long ans = solve(0, W);
cout << ans << endl;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define EPS 1e-7
#define LLMAX 9223372036854775807
#define INTMAX 2147483647
#define ULLMAX 18446744073709551615
#define precision(n) cout << setprecision(n) << fixed
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define forr(i, t, n) for (int i = t; i < n; ++i)
#define rforr(i, t, n) (int i = n - 1; i >= t; --i)
#define rfor(i, n) for (int i = n - 1; i >= 0; --i)
#define rmod(x, y) (((x % y) + y) % y)
#define pb push_back
#define emp emplace_back
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 101;
const int MAXW = 1e5 + 1;
// STRUCTS
// OPERATORS
// GLOBALS
int n, cap;
ll dp[MAXN + 1][MAXW + 1];
int w[MAXN], v[MAXN];
// FUNCTIONS
/*
ll dyn()
{
forn(i, n+1)
{
forn(j, cap+1)
{
if (i == 0 or j == 0) dp[i][j] = 0;
else if (j<w[i-1]) dp[i][j] = dp[i-1][j];
else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] +
ll(v[i-1]));
}
}
return dp[n][cap];
}*/
ll td(int curn, int curw, ll curs) {
if (curn == 0 or curw == 0)
return curs;
if (dp[curn][curw] != -1)
return dp[curn][curw];
if (curw - w[curn - 1] >= 0) {
dp[curn][curw] =
max(td(curn - 1, curw, curs),
ll(v[curn - 1]) + td(curn - 1, curw - w[curn - 1], curs));
} else
dp[curn][curw] = td(curn - 1, curw, curs);
return dp[curn][curw];
}
// PROBLEM:
// LINK:
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("_input.txt", "r", stdin);
freopen("_output.txt", "w", stdout);
#endif
memset(dp, -1, sizeof(dp));
cin >> n >> cap;
forn(i, n) cin >> w[i] >> v[i];
cout << td(n, cap, 0);
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define EPS 1e-7
#define LLMAX 9223372036854775807
#define INTMAX 2147483647
#define ULLMAX 18446744073709551615
#define precision(n) cout << setprecision(n) << fixed
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define forr(i, t, n) for (int i = t; i < n; ++i)
#define rforr(i, t, n) (int i = n - 1; i >= t; --i)
#define rfor(i, n) for (int i = n - 1; i >= 0; --i)
#define rmod(x, y) (((x % y) + y) % y)
#define pb push_back
#define emp emplace_back
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 101;
const int MAXW = 1e5 + 1;
// STRUCTS
// OPERATORS
// GLOBALS
int n, cap;
ll dp[MAXN + 1][MAXW + 1];
int w[MAXN], v[MAXN];
// FUNCTIONS
/*
ll dyn()
{
forn(i, n+1)
{
forn(j, cap+1)
{
if (i == 0 or j == 0) dp[i][j] = 0;
else if (j<w[i-1]) dp[i][j] = dp[i-1][j];
else dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] +
ll(v[i-1]));
}
}
return dp[n][cap];
}*/
ll td(int curn, int curw, ll curs) {
if (curn == 0 or curw == 0)
return curs;
if (dp[curn][curw] != -1)
return dp[curn][curw];
if (curw - w[curn - 1] >= 0) {
dp[curn][curw] =
max(td(curn - 1, curw, curs),
ll(v[curn - 1]) + td(curn - 1, curw - w[curn - 1], curs));
} else
dp[curn][curw] = td(curn - 1, curw, curs);
return dp[curn][curw];
}
// PROBLEM:
// LINK:
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
memset(dp, -1, sizeof(dp));
cin >> n >> cap;
forn(i, n) cin >> w[i] >> v[i];
cout << td(n, cap, 0);
return 0;
}
|
replace
| 81 | 85 | 81 | 82 |
0
| |
p03163
|
C++
|
Runtime Error
|
// R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
void solve() {
int n, w;
cin >> n >> w;
int wt[n], val[n];
rep(i, n) cin >> wt[i] >> val[i];
int dp[n + 1][w + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 0;
repA(i, 0, n) {
repA(j, 0, w) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (j - wt[i - 1] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[3][8];
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
// R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define trav(x) for (auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vii vector<pii>
#define mii map<int, int>
#define mll map<ll, ll>
using namespace std;
void solve() {
int n, w;
cin >> n >> w;
int wt[n], val[n];
rep(i, n) cin >> wt[i] >> val[i];
int dp[n + 1][w + 1];
memset(dp, 0, sizeof dp);
dp[0][0] = 0;
repA(i, 0, n) {
repA(j, 0, w) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (j - wt[i - 1] >= 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i - 1]] + val[i - 1]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w];
}
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
|
replace
| 56 | 57 | 56 | 57 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long int dp[100][100001];
int v[101], w[101];
int main() {
int n, W;
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> w[i + 1] >> v[i + 1];
for (int i = 0; i <= W; i++)
for (int j = 0; j <= n; j++) {
dp[j][i] = -1;
if (i == 0 || j == 0)
dp[j][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int w1 = 1; w1 <= W; w1++) {
dp[i][w1] = dp[i - 1][w1];
if (w[i] <= w1)
dp[i][w1] = max(dp[i][w1], dp[i - 1][w1 - w[i]] + v[i]);
}
}
cout << dp[n][W] << '\n';
}
|
#include <bits/stdc++.h>
using namespace std;
long long int dp[101][100001];
int v[101], w[101];
int main() {
int n, W;
cin >> n >> W;
for (int i = 0; i < n; i++)
cin >> w[i + 1] >> v[i + 1];
for (int i = 0; i <= W; i++)
for (int j = 0; j <= n; j++) {
dp[j][i] = -1;
if (i == 0 || j == 0)
dp[j][i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int w1 = 1; w1 <= W; w1++) {
dp[i][w1] = dp[i - 1][w1];
if (w[i] <= w1)
dp[i][w1] = max(dp[i][w1], dp[i - 1][w1 - w[i]] + v[i]);
}
}
cout << dp[n][W] << '\n';
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e2 + 5;
const int MAXW = 1e5 + 5;
int n, capacidade;
int p[MAXW], v[MAXW];
int memo[MAXN][MAXW];
int solve(int i, int peso) {
if (memo[peso][i] != -1)
return memo[peso][i];
if (i > n || peso == 0)
return 0;
int pegar = 0, nao_pegar = 0;
if (p[i] <= peso) {
pegar = v[i] + solve(i + 1, peso - p[i]);
}
nao_pegar = solve(i + 1, peso);
return memo[peso][i] = max(pegar, nao_pegar);
}
int32_t main() {
cin >> n >> capacidade;
for (int i = 1; i <= n; i++) {
cin >> p[i] >> v[i];
}
memset(memo, -1, sizeof(memo));
cout << solve(1, capacidade);
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e2 + 5;
const int MAXW = 1e5 + 5;
int n, capacidade;
int p[MAXW], v[MAXW];
int memo[MAXW][MAXN];
int solve(int i, int peso) {
if (memo[peso][i] != -1)
return memo[peso][i];
if (i > n || peso == 0)
return 0;
int pegar = 0, nao_pegar = 0;
if (p[i] <= peso) {
pegar = v[i] + solve(i + 1, peso - p[i]);
}
nao_pegar = solve(i + 1, peso);
return memo[peso][i] = max(pegar, nao_pegar);
}
int32_t main() {
cin >> n >> capacidade;
for (int i = 1; i <= n; i++) {
cin >> p[i] >> v[i];
}
memset(memo, -1, sizeof(memo));
cout << solve(1, capacidade);
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int dp[105][10010];
int main() {
int n, W;
int v[105];
int w[105];
cin >> n >> W;
rep(i, n) cin >> w[i] >> v[i];
rep(i, n) {
for (int sum_w = 0; sum_w <= W; ++sum_w) {
if (sum_w >= w[i])
dp[i + 1][sum_w] = max(dp[i][sum_w - w[i]] + v[i], dp[i][sum_w]);
else
dp[i + 1][sum_w] = dp[i][sum_w];
}
}
cout << dp[n][W] << endl;
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll dp[105][100100];
int main() {
int n, W;
int v[105];
int w[105];
cin >> n >> W;
rep(i, n) cin >> w[i] >> v[i];
rep(i, n) {
for (int sum_w = 0; sum_w <= W; ++sum_w) {
if (sum_w >= w[i])
dp[i + 1][sum_w] = max(dp[i][sum_w - w[i]] + v[i], dp[i][sum_w]);
else
dp[i + 1][sum_w] = dp[i][sum_w];
}
}
cout << dp[n][W] << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long tab[1008];
pair<long long, long long> p[101];
#define f first
#define s second
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b, n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> p[i].f >> p[i].s;
}
for (int i = 0; i < n; i++) {
for (int j = w + 3; j >= 0; j--) {
if (j + p[i].f <= w && tab[j] != 0) {
tab[j + p[i].f] = max(tab[j + p[i].f], tab[j] + p[i].s);
}
}
tab[p[i].f] = max(tab[p[i].f], p[i].s);
}
long long wynik = 0;
for (int i = 0; i <= w; i++) {
wynik = max(wynik, tab[i]);
}
cout << wynik;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long tab[100008];
pair<long long, long long> p[101];
#define f first
#define s second
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b, n, w;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> p[i].f >> p[i].s;
}
for (int i = 0; i < n; i++) {
for (int j = w + 3; j >= 0; j--) {
if (j + p[i].f <= w && tab[j] != 0) {
tab[j + p[i].f] = max(tab[j + p[i].f], tab[j] + p[i].s);
}
}
tab[p[i].f] = max(tab[p[i].f], p[i].s);
}
long long wynik = 0;
for (int i = 0; i <= w; i++) {
wynik = max(wynik, tab[i]);
}
cout << wynik;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<long long> f(w + 1);
for (int i = 0; i < n; i++) {
int wi, vi;
cin >> wi >> vi;
for (int i = w - wi; i >= 0; i--)
f[i + w] = max(f[i + w], f[i] + vi);
}
cout << f[w] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, w;
cin >> n >> w;
vector<long long> f(w + 1);
for (int i = 0; i < n; i++) {
int wi, vi;
cin >> wi >> vi;
for (int j = w - wi; j >= 0; j--)
f[j + wi] = max(f[j + wi], f[j] + vi);
}
cout << f[w] << endl;
return 0;
}
|
replace
| 9 | 11 | 9 | 11 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr \
if (true) \
cerr
void print() { cout << endl; }
template <typename T, typename... Args> void print(T a, Args... args) {
cout << a << " ";
print(args...);
}
lli llipowerp(lli x, lli y, lli p = LLONG_MAX) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x) {
if (r >= l) {
lli mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
return -1;
}
template <typename T> inline void printvec(vector<T> inp) {
for (auto it : inp)
cout << it << " ";
cout << endl;
}
//---------------------------------------------------------------------------------
vector<lli> w, v;
lli n, W;
lli dp[(lli)1e5 + 5][101];
lli fill(lli Wr, lli Nr) {
if (dp[Wr][Nr] != -1)
return dp[Wr][Nr];
if (Nr <= 0)
return 0;
lli maxv = 0;
for (lli i = 1; i <= Nr; i++) {
if (w[i] <= Wr)
maxv = max(fill(Wr - w[i], i - 1) + v[i], maxv);
}
dp[Wr][Nr] = maxv;
return dp[Wr][Nr];
}
int main() {
cin >> n >> W;
w.resize(n + 1);
v.resize(n + 1);
fori(n) { cin >> w[i + 1] >> v[i + 1]; }
memset(dp, -1, sizeof(dp));
cout << fill(W, n) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr \
if (true) \
cerr
void print() { cout << endl; }
template <typename T, typename... Args> void print(T a, Args... args) {
cout << a << " ";
print(args...);
}
lli llipowerp(lli x, lli y, lli p = LLONG_MAX) {
lli res = 1;
x = x % p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x) {
if (r >= l) {
lli mid = l + (r - l) / 2;
if (arr[mid] == x)
return mid;
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
return -1;
}
template <typename T> inline void printvec(vector<T> inp) {
for (auto it : inp)
cout << it << " ";
cout << endl;
}
//---------------------------------------------------------------------------------
vector<lli> w, v;
lli n, W;
lli dp[(lli)1e5 + 5][101];
lli fill(lli Wr, lli Nr) {
if (dp[Wr][Nr] != -1)
return dp[Wr][Nr];
if (Nr <= 0)
return 0;
lli maxv = fill(Wr, Nr - 1);
if (w[Nr] <= Wr) {
maxv = max(fill(Wr - w[Nr], Nr - 1) + v[Nr], maxv);
}
dp[Wr][Nr] = maxv;
return dp[Wr][Nr];
}
int main() {
cin >> n >> W;
w.resize(n + 1);
v.resize(n + 1);
fori(n) { cin >> w[i + 1] >> v[i + 1]; }
memset(dp, -1, sizeof(dp));
cout << fill(W, n) << endl;
}
|
replace
| 61 | 65 | 61 | 64 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long int
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 50;
using namespace std;
int main()
// int found; found=chaine.find(cara); if (found!=std::string::npos) how to
// verify if a caracter exists in a chaine
// toupper(caractere) ==> return the majuscule of a caractere
// floor(x) Returns the largest integer smaller than x
// ceil(x) returns Returns the smallest integer greater
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, w;
cin >> n >> w;
int weight[n + 1];
ll value[n + 1];
for (int i = 0; i < n; i++) {
cin >> weight[i + 1] >> value[i + 1];
}
ll mat[n + 1][w + 1];
for (int av = 0; av <= w; av++) {
if (av < weight[1]) {
mat[1][av] = 0;
} else {
mat[1][av] = value[1];
}
}
for (int i = 2; i <= n; i++) {
for (int av = 0; av <= w; av++) {
if (weight[i] > av) {
mat[i][av] = mat[i - 1][av];
} else {
mat[i][av] = max(mat[i - 1][av - weight[i]] + value[i], mat[i - 1][av]);
}
}
}
cout << mat[n][w];
}
|
#include <bits/stdc++.h>
#define ll long long int
const ll mod = 1e9 + 7;
const int maxn = 2e5 + 50;
using namespace std;
int main()
// int found; found=chaine.find(cara); if (found!=std::string::npos) how to
// verify if a caracter exists in a chaine
// toupper(caractere) ==> return the majuscule of a caractere
// floor(x) Returns the largest integer smaller than x
// ceil(x) returns Returns the smallest integer greater
{
int n, w;
cin >> n >> w;
int weight[n + 1];
ll value[n + 1];
for (int i = 0; i < n; i++) {
cin >> weight[i + 1] >> value[i + 1];
}
ll mat[n + 1][w + 1];
for (int av = 0; av <= w; av++) {
if (av < weight[1]) {
mat[1][av] = 0;
} else {
mat[1][av] = value[1];
}
}
for (int i = 2; i <= n; i++) {
for (int av = 0; av <= w; av++) {
if (weight[i] > av) {
mat[i][av] = mat[i - 1][av];
} else {
mat[i][av] = max(mat[i - 1][av - weight[i]] + value[i], mat[i - 1][av]);
}
}
}
cout << mat[n][w];
}
|
delete
| 12 | 16 | 12 | 12 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = 0; i > (int)(n); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
typedef long long ll;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int w[101], v[101];
ll dp[101][101010];
int main(void) {
int N, W;
cin >> N >> W;
REP(i, N) { cin >> w[i] >> v[i]; }
REP(i, W + 1) {
if (i < w[i]) {
dp[0][i] = 0;
} else {
dp[0][i] = v[0];
}
}
REP(i, N - 1) {
REP(k, W + 1) { dp[i + 1][k] = dp[i][k]; }
REP(k, W) {
if (k + w[i + 1] > W) {
break;
}
chmax(dp[i + 1][k + w[i + 1]], dp[i][k] + v[i + 1]);
}
}
cout << dp[N - 1][W] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = 0; i > (int)(n); i--)
#define ALL(v) v.begin(), v.end()
#define INF 2e9
typedef long long ll;
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 (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int w[101], v[101];
ll dp[101][101010];
int main(void) {
int N, W;
cin >> N >> W;
REP(i, N) { cin >> w[i] >> v[i]; }
REP(i, W + 1) {
if (i < w[0]) {
dp[0][i] = 0;
} else {
dp[0][i] = v[0];
}
}
REP(i, N - 1) {
REP(k, W + 1) { dp[i + 1][k] = dp[i][k]; }
REP(k, W) {
if (k + w[i + 1] > W) {
break;
}
chmax(dp[i + 1][k + w[i + 1]], dp[i][k] + v[i + 1]);
}
}
cout << dp[N - 1][W] << "\n";
return 0;
}
|
replace
| 32 | 33 | 32 | 33 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, W;
cin >> N >> W;
vector<int> weight(N);
vector<int> value(N);
for (int i = 0; i < N; ++i) {
cin >> weight[i] >> value[i];
}
vector<int64_t> dp(W + 1, 0);
for (int i = 0; i <= W; ++i) {
for (int j = W; j >= weight[i]; --j) {
dp[j] = max(dp[j], value[i] + dp[j - weight[i]]);
}
}
cout << dp[W] << "\n";
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N, W;
cin >> N >> W;
vector<int> weight(N);
vector<int> value(N);
for (int i = 0; i < N; ++i) {
cin >> weight[i] >> value[i];
}
vector<int64_t> dp(W + 1, 0);
for (int i = 0; i <= N; ++i) {
for (int j = W; j >= weight[i]; --j) {
dp[j] = max(dp[j], value[i] + dp[j - weight[i]]);
}
}
cout << dp[W] << "\n";
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e3 + 5;
void wynik(ll &a, ll b) { a = max(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, w;
cin >> n >> w;
ll dp[MAXN];
for (int i = 0; i < n; i++) {
int waga, koszt;
cin >> waga >> koszt;
for (int j = w - waga; j >= 0; j--)
wynik(dp[j + waga], dp[j] + koszt);
}
ll R = 0;
for (int i = 0; i <= w; i++)
wynik(R, dp[i]);
cout << R;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 200005;
void wynik(ll &a, ll b) { a = max(a, b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, w;
cin >> n >> w;
ll dp[MAXN];
for (int i = 0; i < n; i++) {
int waga, koszt;
cin >> waga >> koszt;
for (int j = w - waga; j >= 0; j--)
wynik(dp[j + waga], dp[j] + koszt);
}
ll R = 0;
for (int i = 0; i <= w; i++)
wynik(R, dp[i]);
cout << R;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll INF = (ll)(1e18);
ll wei[105];
ll val[105];
ll dp[105][105] = {0};
ll knapsack1(ll w, ll i) {
if (i < 0)
return 0;
if (w - wei[i] < 0)
return knapsack1(w, i - 1);
if (dp[w][i] != 0)
return dp[w][i];
dp[w][i] = max(knapsack1(w, i - 1), knapsack1(w - wei[i], i - 1) + val[i]);
return dp[w][i];
}
int main() {
ll a, b, c, k, d, e, f, n, mx, t;
cin >> n >> mx;
for (int i = 0; i < n; i++) {
cin >> wei[i] >> val[i];
}
a = knapsack1(mx, n - 1);
cout << a;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const ll INF = (ll)(1e18);
ll wei[105];
ll val[105];
ll dp[100005][105] = {0};
ll knapsack1(ll w, ll i) {
if (i < 0)
return 0;
if (w - wei[i] < 0)
return knapsack1(w, i - 1);
if (dp[w][i] != 0)
return dp[w][i];
dp[w][i] = max(knapsack1(w, i - 1), knapsack1(w - wei[i], i - 1) + val[i]);
return dp[w][i];
}
int main() {
ll a, b, c, k, d, e, f, n, mx, t;
cin >> n >> mx;
for (int i = 0; i < n; i++) {
cin >> wei[i] >> val[i];
}
a = knapsack1(mx, n - 1);
cout << a;
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i > b; i--)
#define loopll(i, a, b) for (long long int i = a; i < b; i++)
#define rloopll(i, a, b) for (long long int i = a; i > b; i--)
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mk make_pair
#define intmin INT_MIN
#define intmax INT_MAX
#define cout(x) cout << x << " ";
using namespace std;
void vec(vector<int> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
void vec_ll(vector<long long int> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
int parsestring(string temp) {
int num = 0;
int digs = temp.size() - 1;
for (int i = 0; i <= digs; i++) {
num += pow(10, digs - i) * (temp[i] - '0');
}
return num;
}
int mindig(string &s) {
int temp = INT_MAX;
// int index = -1;
for (int i = 0; i < s.size(); i++) {
if (temp > s[i] - '0') {
temp = s[i] - '0';
// index = i;
}
}
return temp;
}
//}
ll power(ll base, ll exp) {
ll ans = 1;
for (ll i = 1; i <= exp; i++) {
ans *= base;
}
return ans;
}
//}
//
void factor(ll n, set<ll> &s) {
ll x = 2;
while (n != 1) {
if (n % x == 0) {
s.insert(x);
n /= x;
} else {
x++;
}
}
}
bool prime(int n) {
bool ok = true;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
ok = false;
break;
}
}
return ok;
}
pair<ll, ll> ass(pair<ll, ll> &a, pair<ll, ll> &b) {
pair<ll, ll> x;
x.first = -1e10;
x.second = -1e10;
if (a.second < b.first) {
return x;
}
if (b.second < a.first) {
return x;
}
if (a.first <= b.first) {
x.first = b.first;
x.second = min(a.second, b.second);
} else {
x.first = a.first;
x.second = min(a.second, b.second);
}
return x;
}
int MX = 100005;
vector<vector<int>> adj(MX, vector<int>());
vector<int> subt(MX, 1);
vector<bool> vis(MX, false);
vector<bool> vis2(MX, false);
vector<int> neigh(MX, 0);
int ans = 0;
int dfs(int x) {
if (vis[x]) {
return 0;
}
vis[x] = true;
for (int i = 0; i < adj[x].size(); i++) {
subt[x] += dfs(adj[x][i]);
}
return subt[x];
}
void dfs2(int x) {
if (vis2[x]) {
return;
}
vis2[x] = true;
for (int i = 0; i < adj[x].size(); i++) {
if (neigh[x] > 1 && subt[adj[x][i]] % 2 == 0 && !vis2[adj[x][i]]) {
cout << x << " " << adj[x][i] << " " << neigh[x] << " " << subt[adj[x][i]]
<< endl;
ans++;
neigh[x]--;
neigh[adj[x][i]]--;
// cout<<"a "<< x<< " " <<adj[x][i]<<endl;
}
dfs(adj[x][i]);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, w;
cin >> n >> w;
vector<pair<bool, ll>> poss(1e5 + 10, mk(false, 0));
poss[0].first = true;
for (int i = 0; i < n; i++) {
ll u, v;
cin >> u >> v;
for (int j = w; j >= 0; j--) {
if (poss[j].first) {
poss[j + u].first = true;
poss[j + u].second = max(poss[j + u].second, poss[j].second + v);
}
}
}
ll ans = 0;
for (int j = w; j >= 0; j--) {
if (poss[j].first) {
ans = max(ans, poss[j].second);
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rloop(i, a, b) for (int i = a; i > b; i--)
#define loopll(i, a, b) for (long long int i = a; i < b; i++)
#define rloopll(i, a, b) for (long long int i = a; i > b; i--)
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mk make_pair
#define intmin INT_MIN
#define intmax INT_MAX
#define cout(x) cout << x << " ";
using namespace std;
void vec(vector<int> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
void vec_ll(vector<long long int> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
cout << endl;
}
int parsestring(string temp) {
int num = 0;
int digs = temp.size() - 1;
for (int i = 0; i <= digs; i++) {
num += pow(10, digs - i) * (temp[i] - '0');
}
return num;
}
int mindig(string &s) {
int temp = INT_MAX;
// int index = -1;
for (int i = 0; i < s.size(); i++) {
if (temp > s[i] - '0') {
temp = s[i] - '0';
// index = i;
}
}
return temp;
}
//}
ll power(ll base, ll exp) {
ll ans = 1;
for (ll i = 1; i <= exp; i++) {
ans *= base;
}
return ans;
}
//}
//
void factor(ll n, set<ll> &s) {
ll x = 2;
while (n != 1) {
if (n % x == 0) {
s.insert(x);
n /= x;
} else {
x++;
}
}
}
bool prime(int n) {
bool ok = true;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
ok = false;
break;
}
}
return ok;
}
pair<ll, ll> ass(pair<ll, ll> &a, pair<ll, ll> &b) {
pair<ll, ll> x;
x.first = -1e10;
x.second = -1e10;
if (a.second < b.first) {
return x;
}
if (b.second < a.first) {
return x;
}
if (a.first <= b.first) {
x.first = b.first;
x.second = min(a.second, b.second);
} else {
x.first = a.first;
x.second = min(a.second, b.second);
}
return x;
}
int MX = 100005;
vector<vector<int>> adj(MX, vector<int>());
vector<int> subt(MX, 1);
vector<bool> vis(MX, false);
vector<bool> vis2(MX, false);
vector<int> neigh(MX, 0);
int ans = 0;
int dfs(int x) {
if (vis[x]) {
return 0;
}
vis[x] = true;
for (int i = 0; i < adj[x].size(); i++) {
subt[x] += dfs(adj[x][i]);
}
return subt[x];
}
void dfs2(int x) {
if (vis2[x]) {
return;
}
vis2[x] = true;
for (int i = 0; i < adj[x].size(); i++) {
if (neigh[x] > 1 && subt[adj[x][i]] % 2 == 0 && !vis2[adj[x][i]]) {
cout << x << " " << adj[x][i] << " " << neigh[x] << " " << subt[adj[x][i]]
<< endl;
ans++;
neigh[x]--;
neigh[adj[x][i]]--;
// cout<<"a "<< x<< " " <<adj[x][i]<<endl;
}
dfs(adj[x][i]);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, w;
cin >> n >> w;
vector<pair<bool, ll>> poss(1e5 + 10, mk(false, 0));
poss[0].first = true;
for (int i = 0; i < n; i++) {
ll u, v;
cin >> u >> v;
for (int j = w; j >= 0; j--) {
if (poss[j].first) {
if (j + u < poss.size()) {
poss[j + u].first = true;
poss[j + u].second = max(poss[j + u].second, poss[j].second + v);
}
}
}
}
ll ans = 0;
for (int j = w; j >= 0; j--) {
if (poss[j].first) {
ans = max(ans, poss[j].second);
}
}
cout << ans << endl;
}
|
replace
| 151 | 153 | 151 | 155 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>
using namespace std;
using ll = long long;
ll const MM = 1000000007;
#define pv(val) cerr << #val << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, b, e) for (ll i = (b); i < (e); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
template <class T> ostream &operator<<(ostream &os, vector<T> const &vec);
template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr);
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p);
template <class... Args>
ostream &operator<<(ostream &os, tuple<Args...> const &t);
template <class T> ostream &operator<<(ostream &os, vector<T> const &vec) {
if (vec.empty()) {
os << "{}";
} else {
os << '{';
for (size_t i = 0; i < vec.size() - 1; i++)
os << vec[i] << ", ";
os << vec.back() << '}';
}
return os;
}
template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
if (arr.empty()) {
os << "{}";
} else {
os << '{';
for (size_t i = 0; i < arr.size() - 1; i++)
os << arr[i] << ", ";
os << arr.back() << '}';
}
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template <size_t I, class... Args>
typename enable_if<sizeof...(Args) == (I + 1)>::type
print_tuple(ostream &os, tuple<Args...> const &t) {
os << get<I>(t);
}
template <size_t I, class... Args>
typename enable_if<sizeof...(Args) != (I + 1)>::type
print_tuple(ostream &os, tuple<Args...> const &t) {
os << get<I>(t) << ", ";
print_tuple<I + 1, Args...>(os, t);
}
template <class... Args>
ostream &operator<<(ostream &os, tuple<Args...> const &t) {
os << '(';
print_tuple<0, Args...>(os, t);
os << ')';
return os;
}
struct Timer {
using Clock = std::chrono::system_clock;
Clock::time_point startTime;
Timer() { start(); }
void start() { startTime = Clock::now(); }
long long milli() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() -
startTime)
.count();
}
long long micro() const {
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() -
startTime)
.count();
}
};
namespace math {
ll gcd(ll u, ll v) {
while (v != 0) {
ll r = u % v;
u = v;
v = r;
}
return u;
}
ll lcm(ll m, ll n) {
if ((0 == m) || (0 == n))
return 0;
return ((m / math::gcd(m, n)) * n);
}
vector<ll> divisors(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return ret;
}
set<ll> divisors_set(ll n) {
set<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.insert(i);
if (i * i != n)
ret.insert(n / i);
}
}
return ret;
}
// https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
struct Combination {
vector<ll> fac;
vector<ll> ifac;
Combination() : fac(1000000 + 100), ifac(1000000 + 100) {
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < 1000000 + 100; i++) {
fac[i + 1] = fac[i] * (i + 1) % MM;
ifac[i + 1] = ifac[i] * this->mpow(i + 1, MM - 2) % MM;
}
}
static ll mpow(ll x, ll n) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % MM;
x = x * x % MM;
n = n >> 1;
}
return ans;
}
ll operator()(ll a, ll b) const { return this->comb(a, b); }
ll comb(ll a, ll b) const {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0 || b < 0)
return 0;
ll const tmp = ifac[a - b] * ifac[b] % MM;
return tmp * fac[a] % MM;
}
}; // comb;
ll digit(ll n, ll b = 10) {
if (n == 0)
return 1;
ll d = 0;
while (n > 0) {
d++;
n /= b;
}
return d;
}
} // namespace math
struct UnionFind {
vector<ll> data;
UnionFind(ll size) : data(size, -1) {}
bool unionSet(ll x, ll y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool findSet(ll x, ll y) { return root(x) == root(y); }
ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
ll size(ll x) { return -data[root(x)]; }
};
ll bound(function<bool(ll)> f, ll ng, ll ok) {
while (abs(ng - ok) > 1) {
ll mid = (ng + ok) / 2;
if (f(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
ll order(vector<ll> const &r) {
vector<ll> a(r.size());
iota(all(a), 1);
ll ord = 0;
while (a != r) {
next_permutation(all(a));
ord++;
}
return ord;
}
ll ab(ll a, ll b) {
ll const c = math::gcd(a, b);
ll const a0 = a / c;
ll const b0 = b / c;
if (a0 % 2 == 0 || b0 % 2 == 0)
return 10000000000;
return a * b0;
}
ll div(ll n) {
ll ans = 0;
while (n > 0) {
ans++;
n /= 2;
}
return ans;
}
// value, weight
ll knapsack(vector<pair<ll, ll>> const &a, ll max_w) {
ll max_n = a.size();
vector<ll> table(max_w + 1, 0);
for (int i = 1; i <= max_n; ++i) {
ll v = a[i].first;
ll w = a[i].second;
if (w <= max_w && table[w] < v)
table[w] = v;
for (int j = 1; j <= max_w - w; j++) {
if (table[j] != 0 && table[w + j] < table[j] + v)
table[w + j] = table[j] + v;
}
}
return *max_element(all(table));
}
ll llpow(ll n, ll m) {
ll ans = 1;
rep(i, m) ans *= n;
return ans;
}
int main(void) {
ll N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
vector<vector<ll>> dp(N + 1, vector<ll>(2 * W + 1, -1));
dp[0][0] = 0;
rep(i, N) {
rep(j, W) {
if (dp[i][j] >= 0) {
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]);
}
}
}
pv(dp);
cout << *max_element(dp.back().begin(), dp.back().begin() + W + 1) << endl;
return 0;
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>
using namespace std;
using ll = long long;
ll const MM = 1000000007;
#define pv(val) cerr << #val << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, b, e) for (ll i = (b); i < (e); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
template <class T> ostream &operator<<(ostream &os, vector<T> const &vec);
template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr);
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p);
template <class... Args>
ostream &operator<<(ostream &os, tuple<Args...> const &t);
template <class T> ostream &operator<<(ostream &os, vector<T> const &vec) {
if (vec.empty()) {
os << "{}";
} else {
os << '{';
for (size_t i = 0; i < vec.size() - 1; i++)
os << vec[i] << ", ";
os << vec.back() << '}';
}
return os;
}
template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
if (arr.empty()) {
os << "{}";
} else {
os << '{';
for (size_t i = 0; i < arr.size() - 1; i++)
os << arr[i] << ", ";
os << arr.back() << '}';
}
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
os << '(' << p.first << ", " << p.second << ')';
return os;
}
template <size_t I, class... Args>
typename enable_if<sizeof...(Args) == (I + 1)>::type
print_tuple(ostream &os, tuple<Args...> const &t) {
os << get<I>(t);
}
template <size_t I, class... Args>
typename enable_if<sizeof...(Args) != (I + 1)>::type
print_tuple(ostream &os, tuple<Args...> const &t) {
os << get<I>(t) << ", ";
print_tuple<I + 1, Args...>(os, t);
}
template <class... Args>
ostream &operator<<(ostream &os, tuple<Args...> const &t) {
os << '(';
print_tuple<0, Args...>(os, t);
os << ')';
return os;
}
struct Timer {
using Clock = std::chrono::system_clock;
Clock::time_point startTime;
Timer() { start(); }
void start() { startTime = Clock::now(); }
long long milli() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() -
startTime)
.count();
}
long long micro() const {
return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now() -
startTime)
.count();
}
};
namespace math {
ll gcd(ll u, ll v) {
while (v != 0) {
ll r = u % v;
u = v;
v = r;
}
return u;
}
ll lcm(ll m, ll n) {
if ((0 == m) || (0 == n))
return 0;
return ((m / math::gcd(m, n)) * n);
}
vector<ll> divisors(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return ret;
}
set<ll> divisors_set(ll n) {
set<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.insert(i);
if (i * i != n)
ret.insert(n / i);
}
}
return ret;
}
// https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
struct Combination {
vector<ll> fac;
vector<ll> ifac;
Combination() : fac(1000000 + 100), ifac(1000000 + 100) {
fac[0] = 1;
ifac[0] = 1;
for (ll i = 0; i < 1000000 + 100; i++) {
fac[i + 1] = fac[i] * (i + 1) % MM;
ifac[i + 1] = ifac[i] * this->mpow(i + 1, MM - 2) % MM;
}
}
static ll mpow(ll x, ll n) {
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % MM;
x = x * x % MM;
n = n >> 1;
}
return ans;
}
ll operator()(ll a, ll b) const { return this->comb(a, b); }
ll comb(ll a, ll b) const {
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0 || b < 0)
return 0;
ll const tmp = ifac[a - b] * ifac[b] % MM;
return tmp * fac[a] % MM;
}
}; // comb;
ll digit(ll n, ll b = 10) {
if (n == 0)
return 1;
ll d = 0;
while (n > 0) {
d++;
n /= b;
}
return d;
}
} // namespace math
struct UnionFind {
vector<ll> data;
UnionFind(ll size) : data(size, -1) {}
bool unionSet(ll x, ll y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool findSet(ll x, ll y) { return root(x) == root(y); }
ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
ll size(ll x) { return -data[root(x)]; }
};
ll bound(function<bool(ll)> f, ll ng, ll ok) {
while (abs(ng - ok) > 1) {
ll mid = (ng + ok) / 2;
if (f(mid))
ok = mid;
else
ng = mid;
}
return ok;
}
ll order(vector<ll> const &r) {
vector<ll> a(r.size());
iota(all(a), 1);
ll ord = 0;
while (a != r) {
next_permutation(all(a));
ord++;
}
return ord;
}
ll ab(ll a, ll b) {
ll const c = math::gcd(a, b);
ll const a0 = a / c;
ll const b0 = b / c;
if (a0 % 2 == 0 || b0 % 2 == 0)
return 10000000000;
return a * b0;
}
ll div(ll n) {
ll ans = 0;
while (n > 0) {
ans++;
n /= 2;
}
return ans;
}
// value, weight
ll knapsack(vector<pair<ll, ll>> const &a, ll max_w) {
ll max_n = a.size();
vector<ll> table(max_w + 1, 0);
for (int i = 1; i <= max_n; ++i) {
ll v = a[i].first;
ll w = a[i].second;
if (w <= max_w && table[w] < v)
table[w] = v;
for (int j = 1; j <= max_w - w; j++) {
if (table[j] != 0 && table[w + j] < table[j] + v)
table[w + j] = table[j] + v;
}
}
return *max_element(all(table));
}
ll llpow(ll n, ll m) {
ll ans = 1;
rep(i, m) ans *= n;
return ans;
}
int main(void) {
ll N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
vector<vector<ll>> dp(N + 1, vector<ll>(2 * W + 1, -1));
dp[0][0] = 0;
rep(i, N) {
rep(j, W) {
if (dp[i][j] >= 0) {
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 << *max_element(dp.back().begin(), dp.back().begin() + W + 1) << endl;
return 0;
}
|
delete
| 315 | 316 | 315 | 315 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <stdio.h>
const int W = 1e5 + 10;
long long int max(long long int a, long long int b) { return a > b ? a : b; }
int main() {
int n, w, p, v;
long long int a[W], ans = 0;
scanf("%d%d", &n, &w);
for (int i = 0; i <= w; i++)
a[i] = 0;
for (int i = 0; i < n; i++) {
scanf("%d%d", &p, &v);
for (int j = w; j >= p; j--)
a[i] = max(a[i], a[i - p] + v);
}
for (int j = w; j >= 0; j--)
ans = max(ans, a[j]);
printf("%lld\n", ans);
}
|
#include <stdio.h>
const int W = 1e5 + 10;
long long int max(long long int a, long long int b) { return a > b ? a : b; }
int main() {
int n, w, p, v;
long long int a[W], ans = 0;
scanf("%d%d", &n, &w);
for (int i = 0; i <= w; i++)
a[i] = 0;
for (int i = 0; i < n; i++) {
scanf("%d%d", &p, &v);
for (int j = w; j >= p; j--)
a[j] = max(a[j], a[j - p] + v);
}
for (int j = w; j >= 0; j--)
ans = max(ans, a[j]);
printf("%lld\n", ans);
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03163
|
C++
|
Runtime Error
|
// srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;
#define all(c) (c).begin(), (c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(), (c).rend()
#define fr(x, in, n, r) for (x = in; x < n; x += r)
#define ifr(x, n) for (x = 0; x < n; x++)
#define dfr(x, n) for (x = n - 1; x >= 0; x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
freopen("input.txt", "r", stdin);
ll n, w, i, j;
cin >> n >> w;
ll a[n], b[n];
ifr(i, n) cin >> a[i] >> b[i];
ll dp[n][w + 1];
ifr(i, n) ifr(j, w + 1) dp[i][j] = 0;
fr(i, a[0], w + 1, 1) dp[0][i] = b[0];
fr(i, 1, n, 1) {
ifr(j, w + 1) {
if (j < a[i])
dp[i][j] = dp[i - 1][j];
else {
if (j - a[i] >= 0)
dp[i][j] = max(dp[i - 1][j - a[i]] + b[i], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
// ifr(i,n){
// ifr(j,w+1){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[n - 1][w] << endl;
return 0;
}
|
// srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using namespace __gnu_pbds;
using namespace std;
#define all(c) (c).begin(), (c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(), (c).rend()
#define fr(x, in, n, r) for (x = in; x < n; x += r)
#define ifr(x, n) for (x = 0; x < n; x++)
#define dfr(x, n) for (x = n - 1; x >= 0; x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll, ll> mll;
typedef map<string, ll> msll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen("input.txt","r",stdin);
ll n, w, i, j;
cin >> n >> w;
ll a[n], b[n];
ifr(i, n) cin >> a[i] >> b[i];
ll dp[n][w + 1];
ifr(i, n) ifr(j, w + 1) dp[i][j] = 0;
fr(i, a[0], w + 1, 1) dp[0][i] = b[0];
fr(i, 1, n, 1) {
ifr(j, w + 1) {
if (j < a[i])
dp[i][j] = dp[i - 1][j];
else {
if (j - a[i] >= 0)
dp[i][j] = max(dp[i - 1][j - a[i]] + b[i], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
// ifr(i,n){
// ifr(j,w+1){
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
cout << dp[n - 1][w] << endl;
return 0;
}
|
replace
| 36 | 37 | 36 | 37 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
const int mod = 1000000007;
int main() {
int n, W;
cin >> n >> W;
vector<ll> w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
vector<vector<ll>> dp(100010, vector<ll>(101));
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= W; ++j) {
if (j - w[i] >= 0) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
}
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
}
}
cout << dp[n][W] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++)
const int mod = 1000000007;
int main() {
int n, W;
cin >> n >> W;
vector<ll> w(n), v(n);
rep(i, n) cin >> w[i] >> v[i];
vector<vector<ll>> dp(110, vector<ll>(100100));
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= W; ++j) {
if (j - w[i] >= 0) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
}
dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
}
}
cout << dp[n][W] << endl;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
long long w[N], v[N];
int n, W;
long long f[N];
int main() {
scanf("%d%d", &n, &W);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &w[i], &v[i]);
f[i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = W; j >= w[i]; j--) {
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
}
printf("%lld\n", f[W]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
long long w[N], v[N];
int n, W;
long long f[100010];
int main() {
scanf("%d%d", &n, &W);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &w[i], &v[i]);
f[i] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = W; j >= w[i]; j--) {
f[j] = max(f[j], f[j - w[i]] + v[i]);
}
}
printf("%lld\n", f[W]);
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long N;
long long W;
std::vector<long long> w;
std::vector<long long> v;
long long SUM_W;
long long dfs(long long n, long long used_w) {
if (n == N) {
return 0;
}
long long no_used = dfs(n + 1, used_w);
if (used_w + w[n] <= W) {
long long used = dfs(n + 1, used_w + w[n]) + v[n];
return max(used, no_used);
} else {
return no_used;
}
}
long long dp() {
auto table = vector<vector<long long>>(N + 1, vector<long long>(SUM_W + 1));
int i, i1;
for (int i_ = N - 1; i_ >= 0; i_--) {
i = i_ % 2;
i1 = (i + 1) % 2;
for (int j = 0; j <= W + 1; j++) {
if (j + w[i_] <= W) {
table[i][j] = max(table[i1][j + w[i_]] + v[i_], table[i1][j]);
} else {
table[i][j] = (table[i1][j]);
}
}
}
return *max_element(table[i].begin(), table[i].end());
}
void solve(long long N_, long long W_, std::vector<long long> w_,
std::vector<long long> v_) {
N = N_;
W = W_;
w = w_;
v = v_;
SUM_W = accumulate(w.begin(), w.end(), 0);
// long long res = dfs(0, 0);
long long res = dp();
cout << res << endl;
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
long long N;
scanf("%lld", &N);
long long W;
scanf("%lld", &W);
std::vector<long long> w(N);
std::vector<long long> v(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &w[i]);
scanf("%lld", &v[i]);
}
solve(N, W, std::move(w), std::move(v));
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long N;
long long W;
std::vector<long long> w;
std::vector<long long> v;
long long SUM_W;
long long dfs(long long n, long long used_w) {
if (n == N) {
return 0;
}
long long no_used = dfs(n + 1, used_w);
if (used_w + w[n] <= W) {
long long used = dfs(n + 1, used_w + w[n]) + v[n];
return max(used, no_used);
} else {
return no_used;
}
}
long long dp() {
auto table = vector<vector<long long>>(N + 1, vector<long long>(W + 1));
int i, i1;
for (int i_ = N - 1; i_ >= 0; i_--) {
i = i_ % 2;
i1 = (i + 1) % 2;
for (int j = 0; j <= W + 1; j++) {
if (j + w[i_] <= W) {
table[i][j] = max(table[i1][j + w[i_]] + v[i_], table[i1][j]);
} else {
table[i][j] = (table[i1][j]);
}
}
}
return *max_element(table[i].begin(), table[i].end());
}
void solve(long long N_, long long W_, std::vector<long long> w_,
std::vector<long long> v_) {
N = N_;
W = W_;
w = w_;
v = v_;
SUM_W = accumulate(w.begin(), w.end(), 0);
// long long res = dfs(0, 0);
long long res = dp();
cout << res << endl;
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
long long N;
scanf("%lld", &N);
long long W;
scanf("%lld", &W);
std::vector<long long> w(N);
std::vector<long long> v(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &w[i]);
scanf("%lld", &v[i]);
}
solve(N, W, std::move(w), std::move(v));
return 0;
}
|
replace
| 23 | 24 | 23 | 24 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
long long f[10010];
int main() {
int n, w;
scanf("%d%d", &n, &w);
// f[i][j]= f[i-1][j] / f[i-1][j-w[i]]+v[i];
for (int i = 0; i < n; ++i) {
int ww, vv;
scanf("%d%d", &ww, &vv);
for (int j = w; j >= ww; --j)
if (f[j - ww] + vv > f[j])
f[j] = f[j - ww] + vv;
}
printf("%lld\n", f[w]);
}
|
#include <algorithm>
#include <map>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <vector>
using namespace std;
long long f[100010];
int main() {
int n, w;
scanf("%d%d", &n, &w);
// f[i][j]= f[i-1][j] / f[i-1][j-w[i]]+v[i];
for (int i = 0; i < n; ++i) {
int ww, vv;
scanf("%d%d", &ww, &vv);
for (int j = w; j >= ww; --j)
if (f[j - ww] + vv > f[j])
f[j] = f[j - ww] + vv;
}
printf("%lld\n", f[w]);
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long N, W;
cin >> N >> W;
vector<long> v(N);
vector<long> w(N);
// dp[i][j] : 商品iまで、重さjまでの価値最大値
vector<vector<long>> dp(N, vector<long>(W + 1, 0));
for (int i = 0; i < N; i++) {
cin >> w.at(i) >> v.at(i);
}
for (int j = 0; j < W + 1; j++) {
dp[0][j] = (j < w[0]) ? 0 : v[0];
}
for (int i = 1; i < N; i++) {
for (int j = 0; j < W + 1; j++) {
if (j - w[i] >= 0) {
dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
cerr << "i, j, dp.i.j: " << i << ", " << j << ", " << dp[i][j] << endl;
}
}
cout << dp[N - 1][W] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long N, W;
cin >> N >> W;
vector<long> v(N);
vector<long> w(N);
// dp[i][j] : 商品iまで、重さjまでの価値最大値
vector<vector<long>> dp(N, vector<long>(W + 1, 0));
for (int i = 0; i < N; i++) {
cin >> w.at(i) >> v.at(i);
}
for (int j = 0; j < W + 1; j++) {
dp[0][j] = (j < w[0]) ? 0 : v[0];
}
for (int i = 1; i < N; i++) {
for (int j = 0; j < W + 1; j++) {
if (j - w[i] >= 0) {
dp[i][j] = max(dp[i - 1][j - w[i]] + v[i], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[N - 1][W] << endl;
}
|
delete
| 28 | 30 | 28 | 28 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); // cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
/* BIEN CUC BO BEGIN*/
ll t, n, A[3][102], w;
ll DD[100002], ans;
/* BIEN CUC BO END*/
int main() {
FIO;
cin >> n >> w;
for (int i = 1; i <= n; ++i) {
cin >> A[1][i] >> A[2][i];
for (int j = w; j >= 0; --j) {
DD[j + A[1][i]] = max(DD[j + A[1][i]], DD[j] + A[2][i]);
}
}
for (int i = 0; i <= w; ++i) {
ans = max(ans, DD[i]);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); // cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
/* BIEN CUC BO BEGIN*/
ll t, n, A[3][102], w;
ll DD[200012], ans;
/* BIEN CUC BO END*/
int main() {
FIO;
cin >> n >> w;
for (int i = 1; i <= n; ++i) {
cin >> A[1][i] >> A[2][i];
for (int j = w; j >= 0; --j) {
DD[j + A[1][i]] = max(DD[j + A[1][i]], DD[j] + A[2][i]);
}
}
for (int i = 0; i <= w; ++i) {
ans = max(ans, DD[i]);
}
cout << ans;
return 0;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define MOD (long long int)1e9 + 7
using namespace std;
typedef long long int ll;
// bool cmp(const pair<int, set<int>> a, const pair<int, set<int>> b) {
// return a.second.size() > b.second.size();
// }
bool cmp(int a, int b) { return a > b; }
// void printV(vector<int> nums) {
// for (int i: nums) {
// printf("%d ", i);// << " ";
// }
// printf("\n");
// }
void printV(vector<ll> nums) {
for (ll i : nums) {
printf("%lld ", i); // << " ";
}
printf("\n");
}
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool valid(int i, int j, int n, int m) {
if (i >= 0 && i < n && j >= 0 && j < m)
return true;
else
return false;
}
ll dp[110][100010];
ll solve(int index, ll currweight, ll weight, vector<vector<int>> nums, int n) {
if (index == n)
return 0;
if (dp[index][currweight] != -1)
return dp[index][currweight];
ll res = solve(index + 1, currweight, weight, nums, n);
if (currweight + nums[index][0] <= weight) {
res =
max(res, nums[index][1] + solve(index + 1, currweight + nums[index][0],
weight, nums, n));
}
dp[index][currweight] = res;
return res;
}
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
// ios_base::sync_with_stdio(false);
// cin.tie(0);cout.tie(0);
// time_t start, end;
// time(&start);
int n, k;
cin >> n >> k;
vector<vector<int>> nums(n, vector<int>(2));
for (int i = 0; i < n; i++)
cin >> nums[i][0] >> nums[i][1];
memset(dp, -1, sizeof(dp));
ll res = solve(0, 0, k, nums, n);
cout << res << endl;
// l time(&end);
// double time_taken = double(end - start);
// cout << "Time Taken: " << fixed << time_taken << setprecision(5);
// cout << " sec" << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define MOD (long long int)1e9 + 7
using namespace std;
typedef long long int ll;
// bool cmp(const pair<int, set<int>> a, const pair<int, set<int>> b) {
// return a.second.size() > b.second.size();
// }
bool cmp(int a, int b) { return a > b; }
// void printV(vector<int> nums) {
// for (int i: nums) {
// printf("%d ", i);// << " ";
// }
// printf("\n");
// }
void printV(vector<ll> nums) {
for (ll i : nums) {
printf("%lld ", i); // << " ";
}
printf("\n");
}
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool valid(int i, int j, int n, int m) {
if (i >= 0 && i < n && j >= 0 && j < m)
return true;
else
return false;
}
ll dp[110][100010];
ll solve(int index, ll currweight, ll weight, vector<vector<int>> &nums,
int n) {
if (index == n)
return 0;
if (dp[index][currweight] != -1)
return dp[index][currweight];
ll res = solve(index + 1, currweight, weight, nums, n);
if (currweight + nums[index][0] <= weight) {
res =
max(res, nums[index][1] + solve(index + 1, currweight + nums[index][0],
weight, nums, n));
}
dp[index][currweight] = res;
return res;
}
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
// ios_base::sync_with_stdio(false);
// cin.tie(0);cout.tie(0);
// time_t start, end;
// time(&start);
int n, k;
cin >> n >> k;
vector<vector<int>> nums(n, vector<int>(2));
for (int i = 0; i < n; i++)
cin >> nums[i][0] >> nums[i][1];
memset(dp, -1, sizeof(dp));
ll res = solve(0, 0, k, nums, n);
cout << res << endl;
// l time(&end);
// double time_taken = double(end - start);
// cout << "Time Taken: " << fixed << time_taken << setprecision(5);
// cout << " sec" << endl;
return 0;
}
|
replace
| 38 | 39 | 38 | 40 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX / 2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
int pow(int x, int n) {
int res = 1;
while (n) {
if (n & 1)
res *= x;
x *= x;
n >>= 1;
}
return res;
}
int get_gcd(int a, int b) {
while (1) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
a %= b;
}
}
int get_lcm(int a, int b) { return a * b / get_gcd(a, b); }
bool chmin(int &a, int b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
bool chmax(int &a, int b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
//-------------------------テンプレここまで-------------------------//
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, W;
cin >> N >> W;
static int w[100], v[100];
REP(i, N) cin >> w[i] >> v[i];
// dp[n][w] ... n番目(1-index)までの品物の中で、合計w以下としたときの最大価値
static int dp[100][100000];
// 貰うdp
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
// i番目を選ばない場合
chmax(dp[i][j], dp[i - 1][j]);
// i番目を選ぶ場合
if (j - w[i - 1] >= 0)
chmax(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
cout << dp[N][W] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX / 2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
int pow(int x, int n) {
int res = 1;
while (n) {
if (n & 1)
res *= x;
x *= x;
n >>= 1;
}
return res;
}
int get_gcd(int a, int b) {
while (1) {
if (a < b)
swap(a, b);
if (b == 0)
return a;
a %= b;
}
}
int get_lcm(int a, int b) { return a * b / get_gcd(a, b); }
bool chmin(int &a, int b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
bool chmax(int &a, int b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
//-------------------------テンプレここまで-------------------------//
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, W;
cin >> N >> W;
static int w[100], v[100];
REP(i, N) cin >> w[i] >> v[i];
// dp[n][w] ... n番目(1-index)までの品物の中で、合計w以下としたときの最大価値
static int dp[101][100001];
// 貰うdp
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= W; j++) {
// i番目を選ばない場合
chmax(dp[i][j], dp[i - 1][j]);
// i番目を選ぶ場合
if (j - w[i - 1] >= 0)
chmax(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
}
}
cout << dp[N][W] << endl;
return 0;
}
|
replace
| 69 | 70 | 69 | 70 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 1e3 + 5;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i, l, m) for (int i = l; i < m; i++)
#define vii vector<int>
#define vpr vector<pair<ll, ll>>
ll pwr(ll x, ll y);
bool isprime(int n);
int a[2][N];
ll dp[N][105];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w;
cin >> n >> w;
fr(i, 1, n + 1) { cin >> a[0][i] >> a[1][i]; }
fr(i, 0, w + 1) {
fr(j, 0, n + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else {
if (a[0][j] <= i) {
dp[i][j] = max((ll)a[1][j] + dp[i - a[0][j]][j - 1], dp[i][j - 1]);
} else {
dp[i][j] = dp[i][j - 1];
}
}
}
}
cout << dp[w][n] << endl;
return 0;
}
ll pwr(ll x, ll y) {
ll ans = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
ans = (x * (ans % mod)) % mod;
x = (x * x) % mod;
y = y / 2;
}
return ans % mod;
}
bool isprime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 1e5 + 5;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i, l, m) for (int i = l; i < m; i++)
#define vii vector<int>
#define vpr vector<pair<ll, ll>>
ll pwr(ll x, ll y);
bool isprime(int n);
int a[2][N];
ll dp[N][105];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w;
cin >> n >> w;
fr(i, 1, n + 1) { cin >> a[0][i] >> a[1][i]; }
fr(i, 0, w + 1) {
fr(j, 0, n + 1) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
} else {
if (a[0][j] <= i) {
dp[i][j] = max((ll)a[1][j] + dp[i - a[0][j]][j - 1], dp[i][j - 1]);
} else {
dp[i][j] = dp[i][j - 1];
}
}
}
}
cout << dp[w][n] << endl;
return 0;
}
ll pwr(ll x, ll y) {
ll ans = 1;
x = x % mod;
while (y > 0) {
if (y & 1)
ans = (x * (ans % mod)) % mod;
x = (x * x) % mod;
y = y / 2;
}
return ans % mod;
}
bool isprime(int n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long int
int n, w;
cin >> n >> w;
vector<pair<int, int>> v;
int dp[10000][10000];
v.push_back({0, 0});
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
v.push_back(make_pair(a, b));
}
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int i = 0; i <= w; i++)
dp[0][i] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (v[i].first > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], v[i].second + dp[i - 1][j - v[i].first]);
}
}
cout << dp[n][w] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long int
int n, w;
cin >> n >> w;
vector<pair<int, int>> v;
int dp[103][100003];
v.push_back({0, 0});
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
v.push_back(make_pair(a, b));
}
for (int i = 0; i <= n; i++)
dp[i][0] = 0;
for (int i = 0; i <= w; i++)
dp[0][i] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (v[i].first > j)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = max(dp[i - 1][j], v[i].second + dp[i - 1][j - v[i].first]);
}
}
cout << dp[n][w] << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
-11
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define N 100005
#define s second
#define f first
#define ll long long
using namespace std;
pair<int, ll> a[101];
ll dp[101][N];
int main() {
int n, w, j, i;
cin >> n >> w;
for (i = 1; i <= n; ++i)
cin >> a[i].f >> a[i].s;
for (i = 1; i <= n + 1; ++i) {
for (j = 1; j <= w + 1; ++j) {
if (a[i - 1].f <= j)
dp[i][j] = max(dp[i - 1][j - a[i - 1].f] + a[i - 1].s, dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n + 1][w];
return 0;
}
|
#include <bits/stdc++.h>
#define N 100005
#define s second
#define f first
#define ll long long
using namespace std;
pair<int, ll> a[105];
ll dp[105][N];
int main() {
int n, w, j, i;
cin >> n >> w;
for (i = 1; i <= n; ++i)
cin >> a[i].f >> a[i].s;
for (i = 1; i <= n + 1; ++i) {
for (j = 1; j <= w + 1; ++j) {
if (a[i - 1].f <= j)
dp[i][j] = max(dp[i - 1][j - a[i - 1].f] + a[i - 1].s, dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n + 1][w];
return 0;
}
|
replace
| 6 | 8 | 6 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
int dp[101][100001];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, capacity;
cin >> n >> capacity;
vector<int> wt(n);
vector<int> val(n);
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
for (int i = 0; i <= capacity; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 or j == 0)
dp[i][j] = 0;
else if (i >= wt[j - 1])
dp[i][j] = max(val[j - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1]);
else
dp[i][j] = dp[i][j - 1];
}
}
cout << dp[capacity][n];
}
|
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
int dp[100001][101];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, capacity;
cin >> n >> capacity;
vector<int> wt(n);
vector<int> val(n);
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
}
for (int i = 0; i <= capacity; i++) {
for (int j = 0; j <= n; j++) {
if (i == 0 or j == 0)
dp[i][j] = 0;
else if (i >= wt[j - 1])
dp[i][j] = max(val[j - 1] + dp[i - wt[j - 1]][j - 1], dp[i][j - 1]);
else
dp[i][j] = dp[i][j - 1];
}
}
cout << dp[capacity][n];
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD = 1e9 + 7;
#ifndef HOME
#define cerr \
if (0) \
cerr
#endif
const int MaxW = 1e5 + 5;
int n, weight;
int dp[105][MaxW];
int w[105];
int v[105];
int solve(int i, int can) {
if (can > weight) {
return -1e18;
}
if (i == n) {
return 0;
}
int &ans = dp[i][can];
if (ans != -1) {
return ans;
}
// don't take current item or take current item
return max(solve(i + 1, can), v[i] + solve(i + 1, can + w[i]));
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> weight;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, -1, sizeof(dp));
cout << solve(0, 0) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD = 1e9 + 7;
#ifndef HOME
#define cerr \
if (0) \
cerr
#endif
const int MaxW = 1e5 + 5;
int n, weight;
int dp[105][MaxW];
int w[105];
int v[105];
int solve(int i, int can) {
if (can > weight) {
return -1e18;
}
if (i == n) {
return 0;
}
int &ans = dp[i][can];
if (ans != -1) {
return ans;
}
// don't take current item or take current item
return ans = max(solve(i + 1, can), v[i] + solve(i + 1, can + w[i]));
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> weight;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
memset(dp, -1, sizeof(dp));
cout << solve(0, 0) << endl;
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define maxx 100100
long long dp[100][maxx], peso[maxx], valor[maxx];
int main() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> peso[i] >> valor[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (peso[i] <= j) {
dp[i][j] = max(valor[i] + dp[i - 1][j - peso[i]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define maxx 100100
long long dp[200][maxx], peso[200], valor[200];
int main() {
int n, w;
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> peso[i] >> valor[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= w; j++) {
if (peso[i] <= j) {
dp[i][j] = max(valor[i] + dp[i - 1][j - peso[i]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
cout << dp[n][w] << endl;
return 0;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long N, W;
vector<long long> w(101), v(101);
vector<vector<long long>> dp(101, vector<long long>(10001, 0));
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> w[i];
cin >> v[i];
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= W; j++) {
if (j < w[i]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
}
}
}
cout << dp[N][W] << "\n";
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
int main() {
long long N, W;
vector<long long> w(101), v(101);
vector<vector<long long>> dp(101, vector<long long>(100001, 0));
cin >> N >> W;
for (int i = 1; i <= N; i++) {
cin >> w[i];
cin >> v[i];
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= W; j++) {
if (j < w[i]) {
dp[i][j] = dp[i - 1][j];
} else {
dp[i][j] = max(dp[i - 1][j], v[i] + dp[i - 1][j - w[i]]);
}
}
}
cout << dp[N][W] << "\n";
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define sanyes \
ios_base::sync_with_stdio(0), cout.tie(0); \
cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount
const llong mxn = 1e5 + 7;
const llong mod = 998244353;
const llong inf = 1e18 + 9;
using namespace std;
llong n, k, dp[101][10001], w[mxn], v[mxn], c[mxn], mx = -inf;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; 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][k];
return 0;
}
|
#include <bits/stdc++.h>
#define sanyes \
ios_base::sync_with_stdio(0), cout.tie(0); \
cin.tie(0);
#define llong long long
#define pb push_back
#define bpc __builtin_popcount
const llong mxn = 1e5 + 7;
const llong mod = 998244353;
const llong inf = 1e18 + 9;
using namespace std;
llong n, k, dp[101][mxn], w[mxn], v[mxn], mx = -inf;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; 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][k];
return 0;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
int wt[n], val[n];
for (int i = 0; i < n; ++i) {
cin >> wt[i] >> val[i];
}
long long dp[1009][100009];
for (int i = 0; i < n + 1; ++i) {
for (int j = 0; j < W + 1; ++j) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (wt[i - 1] <= j) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][W];
}
|
#include <iostream>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
int wt[n], val[n];
for (int i = 0; i < n; ++i) {
cin >> wt[i] >> val[i];
}
long long dp[109][100009];
for (int i = 0; i < n + 1; ++i) {
for (int j = 0; j < W + 1; ++j) {
if (i == 0 || j == 0) {
dp[i][j] = 0;
continue;
}
if (wt[i - 1] <= j) {
dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
cout << dp[n][W];
}
|
replace
| 12 | 13 | 12 | 13 |
-11
| |
p03163
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> v;
vector<ll> w;
ll knapsack(ll x, ll n, vector<vector<ll>> dp) {
if (x == 0 || n < 0)
return 0;
if (dp[n][x] > 0) {
return dp[n][x];
}
if (w[n] > x) {
dp[n][x] = knapsack(x, n - 1, dp);
} else {
dp[n][x] =
max(knapsack(x - w[n], n - 1, dp) + v[n], knapsack(x, n - 1, dp));
}
return dp[n][x];
}
int main() {
ll n, x;
cin >> n >> x;
v.assign(n, 0);
w.assign(n, 0);
vector<vector<ll>> dp;
for (int i = 0; i < n; i++) {
vector<ll> row(x + 1);
dp.push_back(row);
}
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(x, n - 1, dp) << "\n";
}
|
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> v;
vector<ll> w;
ll knapsack(ll x, ll n, vector<vector<ll>> &dp) {
if (x == 0 || n < 0)
return 0;
if (dp[n][x] > 0) {
return dp[n][x];
}
if (w[n] > x) {
dp[n][x] = knapsack(x, n - 1, dp);
} else {
dp[n][x] =
max(knapsack(x - w[n], n - 1, dp) + v[n], knapsack(x, n - 1, dp));
}
return dp[n][x];
}
int main() {
ll n, x;
cin >> n >> x;
v.assign(n, 0);
w.assign(n, 0);
vector<vector<ll>> dp;
for (int i = 0; i < n; i++) {
vector<ll> row(x + 1);
dp.push_back(row);
}
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
cout << knapsack(x, n - 1, dp) << "\n";
}
|
replace
| 9 | 10 | 9 | 10 |
TLE
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 200;
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
ll n, cap, item, maxis = 0, dp[N], i, j, weight;
cin >> n >> cap;
for (i = 0; i <= cap; ++i)
dp[i] = 0;
for (i = 0; i < n; ++i) {
cin >> weight >> item;
for (j = cap; j >= weight; --j)
dp[j] = max(dp[j - weight] + item, dp[j]);
}
for (i = 0; i <= cap; ++i)
maxis = max(maxis, dp[i]);
cout << maxis;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 150000;
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
ll n, cap, item, maxis = 0, dp[N], i, j, weight;
cin >> n >> cap;
for (i = 0; i <= cap; ++i)
dp[i] = 0;
for (i = 0; i < n; ++i) {
cin >> weight >> item;
for (j = cap; j >= weight; --j)
dp[j] = max(dp[j - weight] + item, dp[j]);
}
for (i = 0; i <= cap; ++i)
maxis = max(maxis, dp[i]);
cout << maxis;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03163
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long int dp[101][12345];
long int A[101][2];
int main() {
int n, w;
scanf("%d %d", &n, &w);
for (int i = 0; i < n; i++)
scanf("%ld %ld", &A[i][0], &A[i][1]);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j < A[i - 1][0])
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] = max(A[i - 1][1] + dp[i - 1][j - A[i - 1][0]], dp[i - 1][j]);
}
}
}
printf("%ld\n", dp[n][w]);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long int dp[1000][123456];
long int A[1000][2];
int main() {
int n, w;
scanf("%d %d", &n, &w);
for (int i = 0; i < n; i++)
scanf("%ld %ld", &A[i][0], &A[i][1]);
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= w; j++) {
if (i == 0 || j == 0)
dp[i][j] = 0;
else if (j < A[i - 1][0])
dp[i][j] = dp[i - 1][j];
else {
dp[i][j] = max(A[i - 1][1] + dp[i - 1][j - A[i - 1][0]], dp[i - 1][j]);
}
}
}
printf("%ld\n", dp[n][w]);
return 0;
}
|
replace
| 4 | 6 | 4 | 6 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.