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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int const inf = 1e9 + 7;
int n, W, v[101], w[101], dp[101][1100000];
// dp[i][j] = max(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1])
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < 101; i++)
for (int j = 0; j < 1100000; j++)
dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
// for(int j = 0; j < 1100000; j++)dp[i][j] = inf;
for (int j = 0; j < 1100000; j++) {
dp[i][j] = dp[i - 1][j];
if (j - v[i - 1] >= 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
}
}
}
int mmax = 0;
for (int i = 0; i < 11000000; i++) {
if (dp[n][i] <= W)
mmax = i;
// cout << dp[n][i] << ' ';
}
cout << mmax << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int const inf = 1e9 + 7;
int n, W, v[101], w[101], dp[101][1100000];
// dp[i][j] = max(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1])
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < 101; i++)
for (int j = 0; j < 1100000; j++)
dp[i][j] = inf;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
// for(int j = 0; j < 1100000; j++)dp[i][j] = inf;
for (int j = 0; j < 1100000; j++) {
dp[i][j] = dp[i - 1][j];
if (j - v[i - 1] >= 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
}
}
}
int mmax = 0;
for (int i = 0; i < 1100000; i++) {
if (dp[n][i] <= W)
mmax = i;
// cout << dp[n][i] << ' ';
}
cout << mmax << endl;
return 0;
}
|
replace
| 28 | 29 | 28 | 29 |
-11
| |
p03164
|
Python
|
Time Limit Exceeded
|
N, W = [int(_) for _ in input().split()]
WV = [[int(_) for _ in input().split()] for _ in range(N)]
dp = {}
dp[0] = 0
for w, v in WV:
dp_o = dp.copy()
for k in dp_o:
if k + w <= W:
dp[k + w] = max(dp_o.get(k + w, 0), dp_o[k] + v)
print(max([v for k, v in dp.items()]))
|
N, W = [int(_) for _ in input().split()]
WV = [[int(_) for _ in input().split()] for _ in range(N)]
dp = {}
dp[0] = 0
for w, v in WV:
dp_o = dp.copy()
for k in dp_o:
dp[k + v] = min(dp_o.get(k + v, float("inf")), dp_o[k] + w)
print(max([k for k, v in dp.items() if v <= W]))
|
replace
| 7 | 10 | 7 | 9 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define maxn 10000000000000
#define endl '\n'
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) \
cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl;
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl;
int mod(int x, int y) {
int s;
s = abs(x) / y;
if (x < 0)
s--;
return x - y * s;
}
int dir8[2][8] = {{1, -1, 0, 0, 1, -1, 1, -1}, {0, 0, 1, -1, 1, -1, -1, 1}};
int dir4[2][4] = {{1, -1, 0, 0}, {0, 0, 1, -1}};
ll m, n, row, col, k;
ll memo[105][1005];
ll cost[105], weight[105];
ll maxVal = 0;
void solve() {
scanf("%lld%lld", &n, &m);
for (int w = 0; w < n; w++) {
scanf("%lld%lld", &weight[w], &cost[w]);
maxVal += cost[w];
}
for (int w = 0; w <= maxVal; w++)
memo[n - 1][w] = (cost[n - 1] >= w) ? weight[n - 1] : maxn;
for (int i = n - 2; i >= 0; i--) {
for (ll j = 0; j <= maxVal; j++) {
if (cost[i] >= j) {
memo[i][j] = min(memo[i + 1][j], weight[i]);
} else {
memo[i][j] = min(weight[i] + memo[i + 1][j - cost[i]], memo[i + 1][j]);
}
}
}
ll ans = 0;
for (int i = 0; i <= maxVal; i++) {
// cout << memo[0][i] << " " << i << endl;
ans = (memo[0][i] <= m) ? i : ans;
}
printf("%lld\n", ans);
}
void test() {
int t;
// scanf("%d",&t);
t = 1;
for (int test = 1; test <= t; test++) {
// memset(memo,-1,sizeof memo);
solve();
}
}
int main() {
test();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ll long long
#define lcm(a, b) (a) / __gcd((a), (b)) * (b)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define maxn 10000000000000
#define endl '\n'
#define trace(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) \
cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl;
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl;
int mod(int x, int y) {
int s;
s = abs(x) / y;
if (x < 0)
s--;
return x - y * s;
}
int dir8[2][8] = {{1, -1, 0, 0, 1, -1, 1, -1}, {0, 0, 1, -1, 1, -1, -1, 1}};
int dir4[2][4] = {{1, -1, 0, 0}, {0, 0, 1, -1}};
ll m, n, row, col, k;
ll memo[105][100005];
ll cost[105], weight[105];
ll maxVal = 0;
void solve() {
scanf("%lld%lld", &n, &m);
for (int w = 0; w < n; w++) {
scanf("%lld%lld", &weight[w], &cost[w]);
maxVal += cost[w];
}
for (int w = 0; w <= maxVal; w++)
memo[n - 1][w] = (cost[n - 1] >= w) ? weight[n - 1] : maxn;
for (int i = n - 2; i >= 0; i--) {
for (ll j = 0; j <= maxVal; j++) {
if (cost[i] >= j) {
memo[i][j] = min(memo[i + 1][j], weight[i]);
} else {
memo[i][j] = min(weight[i] + memo[i + 1][j - cost[i]], memo[i + 1][j]);
}
}
}
ll ans = 0;
for (int i = 0; i <= maxVal; i++) {
// cout << memo[0][i] << " " << i << endl;
ans = (memo[0][i] <= m) ? i : ans;
}
printf("%lld\n", ans);
}
void test() {
int t;
// scanf("%d",&t);
t = 1;
for (int test = 1; test <= t; test++) {
// memset(memo,-1,sizeof memo);
solve();
}
}
int main() {
test();
return 0;
}
|
replace
| 31 | 32 | 31 | 32 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
typedef pair<int, int> pii;
vector<int> v;
map<int, int> op;
#define MAX 200005
bool visited[MAX];
vector<int> adj[MAX];
const int M = 1e9 + 7;
int n, m;
const ll INF = 1LL << 60;
ll solve(int n, int w, int wt[], int val[]) {
vector<ll> dp(100001, LLONG_MAX);
dp[0] = 0;
for (int i = 0; i <= n; i++) {
int w = wt[i], v = val[i];
for (int j = 100000; j >= v; j--) {
if (dp[j - v] == LLONG_MAX)
continue;
dp[j] = min(dp[j], dp[j - v] + w);
}
}
for (int i = 100000; i >= 0; i--)
if (dp[i] <= w)
return i;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << solve(n, w, wt, val) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long int
typedef pair<int, int> pii;
vector<int> v;
map<int, int> op;
#define MAX 200005
bool visited[MAX];
vector<int> adj[MAX];
const int M = 1e9 + 7;
int n, m;
const ll INF = 1LL << 60;
ll solve(int n, int w, int wt[], int val[]) {
vector<ll> dp(100001, LLONG_MAX);
dp[0] = 0;
for (int i = 0; i < n; i++) {
int w = wt[i], v = val[i];
for (int j = 100000; j >= v; j--) {
if (dp[j - v] == LLONG_MAX)
continue;
dp[j] = min(dp[j], dp[j - v] + w);
}
}
for (int i = 100000; i >= 0; i--)
if (dp[i] <= w)
return i;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int w;
cin >> n >> w;
int wt[n], val[n];
for (int i = 0; i < n; i++)
cin >> wt[i] >> val[i];
cout << solve(n, w, wt, val) << endl;
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000001
#define N 101
#define VALUE 10001
int n, weight;
ll w[N], v[N], dp[VALUE], mx;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> weight;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
mx += v[i];
}
for (int i = 1; i <= mx; i++)
dp[i] = INF;
for (int j = 1; j <= n; j++)
for (int i = mx; i >= v[j]; i--)
dp[i] = min(dp[i], dp[i - v[j]] + w[j]);
for (int i = mx; i >= 0; i--)
if (dp[i] <= weight) {
cout << i << '\n';
return 0;
}
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000001
#define N 101
#define VALUE 100001
int n, weight;
ll w[N], v[N], dp[VALUE], mx;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> weight;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
mx += v[i];
}
for (int i = 1; i <= mx; i++)
dp[i] = INF;
for (int j = 1; j <= n; j++)
for (int i = mx; i >= v[j]; i--)
dp[i] = min(dp[i], dp[i - v[j]] + w[j]);
for (int i = mx; i >= 0; i--)
if (dp[i] <= weight) {
cout << i << '\n';
return 0;
}
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18L + 5;
const int MAX_W_V_SIZE = 105, M = 2e3 + 5;
int64_t W[105], V[105], dp[M];
int main() {
int n, w, max_val;
cin >> n >> w;
max_val = 0;
for (int i = 0; i < n; i++)
cin >> W[i] >> V[i], max_val += V[i];
for (int i = 0; i <= M; i++)
dp[i] = INF;
dp[0] = 0;
for (int k = 0; k < n; k++) {
for (int x = max_val - V[k]; x >= 0; x--) {
if (dp[x] || !dp[0]) {
dp[x + V[k]] = min(dp[x + V[k]], W[k] + dp[x]);
}
}
}
int64_t m = 0;
for (int i = 0; i <= max_val; i++) {
// cout << dp[i] << " ";
if (dp[i] <= w) {
m = max(m, (int64_t)i);
}
}
cout << m;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18L + 5;
const int MAX_W_V_SIZE = 105, M = 2e5 + 5;
int64_t W[105], V[105], dp[M];
int main() {
int n, w, max_val;
cin >> n >> w;
max_val = 0;
for (int i = 0; i < n; i++)
cin >> W[i] >> V[i], max_val += V[i];
for (int i = 0; i <= M; i++)
dp[i] = INF;
dp[0] = 0;
for (int k = 0; k < n; k++) {
for (int x = max_val - V[k]; x >= 0; x--) {
if (dp[x] || !dp[0]) {
dp[x + V[k]] = min(dp[x + V[k]], W[k] + dp[x]);
}
}
}
int64_t m = 0;
for (int i = 0; i <= max_val; i++) {
// cout << dp[i] << " ";
if (dp[i] <= w) {
m = max(m, (int64_t)i);
}
}
cout << m;
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
int main() {
ll n, W;
cin >> n >> W;
vector<ll> w(n);
vector<ll> v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(100001, LINF));
dp[0][0] = 0LL;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 100000; j++) {
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
}
}
for (int i = 100000; i >= 0; i--) {
if (dp[n][i] <= W) {
cout << i << endl;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
int main() {
ll n, W;
cin >> n >> W;
vector<ll> w(n);
vector<ll> v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(100001, LINF));
dp[0][0] = 0LL;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 100000; j++) {
if (j - v[i - 1] >= 0) {
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
for (int i = 100000; i >= 0; i--) {
if (dp[n][i] <= W) {
cout << i << endl;
break;
}
}
return 0;
}
|
replace
| 27 | 28 | 27 | 32 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
/*### FAST-IO ###*/
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
/*### DEBUGGGGGGG ###*/
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define testcases \
int testcases; \
cin >> testcases; \
while (testcases--)
#define queries \
int queries; \
cin >> queries; \
while (queries--)
/*### TO PRINT ###*/
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define pp5(a, b, c, d, e) \
cout << a << " " << b << " " << c << " " << d << " " << e << endl;
/*### SSSSSSS ###*/
#define INF INT_MAX
#define endl "\n"
#define ll long long
#define int long long
ll mod = 1e18L + 5;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define ff first
#define ss second
#define sz size()
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define REP1(i, a, b) for (int i = a; i < b; i++)
#define f0(n) for (ll i = 0; i < n; i++)
#define f(n) for (ll i = 1; i <= n; i++)
#define fn(a, n) for (ll a = 0; a < n; a++)
#define flr(a, l, r) for (ll a = l; a <= r; a++)
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define stop return 0
/*### COMPARATOR ###*/
bool rev(int x, int y) { return x > y; }
/*### PAIR_SORT_IN_DESCENDING_ORDER ###*/
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
/*### MODULO ###*/
int modulo(int x, int N) { return (x % N + N) % N; }
/*### MAX & MIN ###*/
int max(int a, int b) {
if (a >= b)
return a;
else
return b;
}
int min(int a, int b) {
if (a <= b)
return a;
else
return b;
}
/*### MOD-DIFFERENCE ###*/
ll diff(ll a, ll b) {
if (a >= b)
return a - b;
else
return b - a;
}
/*### PAIR-SORTING ###*/
void pairsort(int a[], int b[], ll n) {
pair<int, int> pairt[n];
for (int i = 0; i < n; i++) {
pairt[i].first = a[i];
pairt[i].second = b[i];
}
sort(pairt, pairt + n);
for (int i = 0; i < n; i++) {
a[i] = pairt[i].first;
b[i] = pairt[i].second;
}
}
/*### GCD && LCM ###*/
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
/*### PRIME OR NOT ###*/
int isPrime(int n) {
if (n < 2)
return 0;
if (n < 4)
return 1;
if (n % 2 == 0 or n % 3 == 0)
return 0;
for (int i = 5; i * i <= n; i += 6)
if (n % i == 0 or n % (i + 2) == 0)
return 0;
return 1;
}
/*### nCr ###*/
long long C(int n, int r) {
if (r > n - r)
r = n - r;
long long ans = 1;
int i;
for (i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
/*### MODULAR-EXPONENTIATION ###*/
ll modexpo(ll x, ll p) {
ll res = 1;
x = x % mod;
while (p) {
if (p % 2)
res = res * x;
p >>= 1;
x = x * x % mod;
res %= mod;
}
return res;
}
uint64_t mul_mod(uint64_t a, uint64_t b, uint64_t m) {
long double x;
uint64_t c;
int64_t r;
if (a >= m)
a %= m;
if (b >= m)
b %= m;
x = a;
c = x * b / m;
r = (int64_t)(a * b - c * m) % (int64_t)m;
return r < 0 ? r + m : r;
}
/*### STRING TO INT ###*/
int sti(string s) {
int ans = 0;
int p = 1;
for (int i = s.size() - 1; i >= 0; i--) {
ans = (ans + ((ll)(s[i] - '0') * p) % mod) % mod;
p = (p * 10) % mod;
}
return ans;
}
/*### TIMER ###*/
void time() {
#ifndef ONLINE_JUDGE
cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}
/*************************** END OF TEMPLATE ****************************/
const int N = 1e6 + 5;
void minself(int &a, int b) { a = min(a, b); }
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
IOS
// 1st solution
int n,
W;
cin >> n >> W;
vi weight(n), value(n);
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
int sum_value = 0;
for (int x : value) {
sum_value += x;
}
vi dp(sum_value + 1, INF);
dp[0] = 0;
// dp[i]-the minn total value of items with total value exatly i
for (int i = 0; i < n; ++i) {
for (int j = sum_value - value[i]; j >= 0; --j) {
// for(int j=0; j<=W-weight ; j++){
minself(dp[j + value[i]], dp[j] + weight[i]);
}
}
int ans = 0;
flr(i, 0, sum_value) {
if (dp[i] <= W) {
ans = max(ans, i);
}
// minself(ans,dp[i]);
}
cout << ans << endl;
// time();
stop;
}
|
#include <bits/stdc++.h>
using namespace std;
/*### FAST-IO ###*/
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
/*### DEBUGGGGGGG ###*/
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define testcases \
int testcases; \
cin >> testcases; \
while (testcases--)
#define queries \
int queries; \
cin >> queries; \
while (queries--)
/*### TO PRINT ###*/
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define pp5(a, b, c, d, e) \
cout << a << " " << b << " " << c << " " << d << " " << e << endl;
/*### SSSSSSS ###*/
#define INF INT_MAX
#define endl "\n"
#define ll long long
#define int long long
ll mod = 1e18L + 5;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vpii vector<pair<int, int>>
#define ff first
#define ss second
#define sz size()
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define REP1(i, a, b) for (int i = a; i < b; i++)
#define f0(n) for (ll i = 0; i < n; i++)
#define f(n) for (ll i = 1; i <= n; i++)
#define fn(a, n) for (ll a = 0; a < n; a++)
#define flr(a, l, r) for (ll a = l; a <= r; a++)
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define stop return 0
/*### COMPARATOR ###*/
bool rev(int x, int y) { return x > y; }
/*### PAIR_SORT_IN_DESCENDING_ORDER ###*/
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
/*### MODULO ###*/
int modulo(int x, int N) { return (x % N + N) % N; }
/*### MAX & MIN ###*/
int max(int a, int b) {
if (a >= b)
return a;
else
return b;
}
int min(int a, int b) {
if (a <= b)
return a;
else
return b;
}
/*### MOD-DIFFERENCE ###*/
ll diff(ll a, ll b) {
if (a >= b)
return a - b;
else
return b - a;
}
/*### PAIR-SORTING ###*/
void pairsort(int a[], int b[], ll n) {
pair<int, int> pairt[n];
for (int i = 0; i < n; i++) {
pairt[i].first = a[i];
pairt[i].second = b[i];
}
sort(pairt, pairt + n);
for (int i = 0; i < n; i++) {
a[i] = pairt[i].first;
b[i] = pairt[i].second;
}
}
/*### GCD && LCM ###*/
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
/*### PRIME OR NOT ###*/
int isPrime(int n) {
if (n < 2)
return 0;
if (n < 4)
return 1;
if (n % 2 == 0 or n % 3 == 0)
return 0;
for (int i = 5; i * i <= n; i += 6)
if (n % i == 0 or n % (i + 2) == 0)
return 0;
return 1;
}
/*### nCr ###*/
long long C(int n, int r) {
if (r > n - r)
r = n - r;
long long ans = 1;
int i;
for (i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
/*### MODULAR-EXPONENTIATION ###*/
ll modexpo(ll x, ll p) {
ll res = 1;
x = x % mod;
while (p) {
if (p % 2)
res = res * x;
p >>= 1;
x = x * x % mod;
res %= mod;
}
return res;
}
uint64_t mul_mod(uint64_t a, uint64_t b, uint64_t m) {
long double x;
uint64_t c;
int64_t r;
if (a >= m)
a %= m;
if (b >= m)
b %= m;
x = a;
c = x * b / m;
r = (int64_t)(a * b - c * m) % (int64_t)m;
return r < 0 ? r + m : r;
}
/*### STRING TO INT ###*/
int sti(string s) {
int ans = 0;
int p = 1;
for (int i = s.size() - 1; i >= 0; i--) {
ans = (ans + ((ll)(s[i] - '0') * p) % mod) % mod;
p = (p * 10) % mod;
}
return ans;
}
/*### TIMER ###*/
void time() {
#ifndef ONLINE_JUDGE
cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}
/*************************** END OF TEMPLATE ****************************/
const int N = 1e6 + 5;
void minself(int &a, int b) { a = min(a, b); }
int32_t main() {
IOS
// 1st solution
int n,
W;
cin >> n >> W;
vi weight(n), value(n);
for (int i = 0; i < n; i++) {
cin >> weight[i] >> value[i];
}
int sum_value = 0;
for (int x : value) {
sum_value += x;
}
vi dp(sum_value + 1, INF);
dp[0] = 0;
// dp[i]-the minn total value of items with total value exatly i
for (int i = 0; i < n; ++i) {
for (int j = sum_value - value[i]; j >= 0; --j) {
// for(int j=0; j<=W-weight ; j++){
minself(dp[j + value[i]], dp[j] + weight[i]);
}
}
int ans = 0;
flr(i, 0, sum_value) {
if (dp[i] <= W) {
ans = max(ans, i);
}
// minself(ans,dp[i]);
}
cout << ans << endl;
// time();
stop;
}
|
delete
| 237 | 241 | 237 | 237 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long c[105], v[105];
long long dp[105][1005];
#define inf 1e9 + 5
int main() {
long long n, w;
cin >> n >> w;
long long v_sum = 0;
for (int i = 1; i <= n; i++) {
cin >> c[i] >> v[i];
v_sum += v[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= v_sum; j++) {
dp[i][j] = inf;
}
}
// for(int i = 0; i<=1004s
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= v_sum; j++) {
if (i - 1 >= 0 && j - v[i] >= 0)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + c[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
long long ans = 0;
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j <= v_sum; j++) {
// cout << dp[i][j] << " ";
if (dp[i][j] <= w) {
ans = max(j, ans);
}
}
// cout << endl;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
long long c[105], v[105];
long long dp[105][100005];
#define inf 1e9 + 5
int main() {
long long n, w;
cin >> n >> w;
long long v_sum = 0;
for (int i = 1; i <= n; i++) {
cin >> c[i] >> v[i];
v_sum += v[i];
}
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= v_sum; j++) {
dp[i][j] = inf;
}
}
// for(int i = 0; i<=1004s
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= v_sum; j++) {
if (i - 1 >= 0 && j - v[i] >= 0)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + c[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
long long ans = 0;
for (long long i = 1; i <= n; i++) {
for (long long j = 0; j <= v_sum; j++) {
// cout << dp[i][j] << " ";
if (dp[i][j] <= w) {
ans = max(j, ans);
}
}
// cout << endl;
}
cout << ans << endl;
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03164
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
using namespace std;
const int w_max = 1e9 + 1;
const int v_max = 1e5 + 10;
const int size = 1e2 + 1;
int memo[v_max][size];
bool vis[v_max][size];
int v[size];
int w[size];
int n, w_tot;
int dp(int vtmp, int i) {
if (vtmp <= 0)
return 0;
if (i == n)
return w_max;
if (vis[vtmp][i])
return memo[vtmp][i];
return memo[vtmp][i] = min(dp(vtmp, i + 1), w[i] + dp(vtmp - v[i], i + 1));
}
int answer(int v_tot) {
int ans = 0;
for (int i = v_tot; i >= 0; i--) {
if (dp(i, 0) <= w_tot)
return i;
}
return 0;
}
int main() {
scanf("%d %d", &n, &w_tot);
int v_tot = 0;
for (int i = 0; i < n; i++) {
scanf("%d %d", &w[i], &v[i]);
v_tot += v[i];
}
printf("%d\n", answer(v_tot));
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
using namespace std;
const int w_max = 1e9 + 1;
const int v_max = 1e5 + 10;
const int size = 1e2 + 1;
int memo[v_max][size];
bool vis[v_max][size];
int v[size];
int w[size];
int n, w_tot;
int dp(int vtmp, int i) {
if (vtmp <= 0)
return 0;
if (i == n)
return w_max;
if (vis[vtmp][i])
return memo[vtmp][i];
vis[vtmp][i] = 1;
return memo[vtmp][i] = min(dp(vtmp, i + 1), w[i] + dp(vtmp - v[i], i + 1));
}
int answer(int v_tot) {
int ans = 0;
for (int i = v_tot; i >= 0; i--) {
if (dp(i, 0) <= w_tot)
return i;
}
return 0;
}
int main() {
scanf("%d %d", &n, &w_tot);
int v_tot = 0;
for (int i = 0; i < n; i++) {
scanf("%d %d", &w[i], &v[i]);
v_tot += v[i];
}
printf("%d\n", answer(v_tot));
return 0;
}
|
insert
| 26 | 26 | 26 | 28 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 1e+12;
int main() {
int N, W, sval = 0, ans = 0;
static ll dp[110][1010];
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
sval += v[i];
}
for (int i = 0; i <= N; ++i)
for (int j = 1; j <= sval; ++j)
dp[i][j] = INF;
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= sval; ++j) {
if (j >= v[i - 1]) {
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
} else
dp[i][j] = min(dp[i - 1][j], dp[i][j]);
}
}
for (int i = 1; i <= sval; ++i)
if (dp[N][i] <= W)
ans = i;
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll INF = 1e+12;
int main() {
int N, W, sval = 0, ans = 0;
static ll dp[110][100010];
cin >> N >> W;
vector<int> w(N), v(N);
for (int i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
sval += v[i];
}
for (int i = 0; i <= N; ++i)
for (int j = 1; j <= sval; ++j)
dp[i][j] = INF;
for (int i = 1; i <= N; ++i) {
for (int j = 1; j <= sval; ++j) {
if (j >= v[i - 1]) {
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i - 1]] + w[i - 1]);
} else
dp[i][j] = min(dp[i - 1][j], dp[i][j]);
}
}
for (int i = 1; i <= sval; ++i)
if (dp[N][i] <= W)
ans = i;
cout << ans << endl;
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03164
|
C++
|
Runtime Error
|
///*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*///
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ln '\n'
#define inp(x) scanf("%lld", &x)
#define inp2(a, b) scanf("%lld %lld", &a, &b)
#define f0(i, b) for (int i = 0; i < (b); i++)
#define f1(i, b) for (int i = 1; i <= (b); i++)
#define MOD 1000000007
#define PI acos(-1)
#define ll long long int
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define F first
#define S second
#define sz size()
#define LCM(a, b) (a * (b / __gcd(a, b)))
// #define harmonic(n) 0.57721566490153286060651209+log(n)+1.0/(2*n)
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define all(v) v.begin(), v.end()
#define MEM(a, b) memset(a, b, sizeof(a))
#define fastio ios_base::sync_with_stdio(false)
/*
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including */
// using namespace __gnu_pbds;
/*
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; template<typename F, typename S> using
ordered_map = tree<F, S, less<F>, rb_tree_tag,
tree_order_statistics_node_update>;
// find_by_order(k) – ফাংশনটি kth ordered element এর একটা পয়েন্টার রিটার্ন করে।
অর্থাৎ তুমি চাইলেই kth ইন্ডেক্সে কি আছে, সেটা জেনে ফেলতে পারছো!
// order_of_key(x) – ফƂশনটি x এলিমਠƨ্টটޠকোন পজিশনে আছে সেটা বলে
দেয়।
*/
/// Inline functions
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(ll year) {
return (year % 400 == 0) | (year % 4 == 0 && year % 100 != 0);
}
inline void normal(ll &a) {
a %= MOD;
(a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline bool isInside(pii p, ll n, ll m) {
return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m);
}
inline bool isInside(pii p, ll n) {
return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n);
}
inline bool isSquare(ll x) {
ll s = sqrt(x);
return (s * s == x);
}
inline bool isFib(ll x) {
return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4);
}
inline bool isPowerOfTwo(ll x) { return ((1LL << (ll)log2(x)) == x); }
/// DEBUG
/// --------------------------------------------------------------------------------->>>>>>
///**
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define dbg(args...) \
do { \
cerr << #args << " : "; \
faltu(args); \
} while (0)
clock_t tStart = clock();
#define timeStamp \
dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC)
void faltu() { cerr << endl; }
template <typename T> void faltu(T a[], int n) {
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
cerr << arg << ' ';
faltu(rest...);
}
/// TEMPLATE
/// ----------------------------------------------------------------------->>>>>>
struct func {
// this is a sample overloading function for sorting stl
bool operator()(pii const &a, pii const &b) {
if (a.F == b.F)
return (a.S < b.S);
return (a.F < b.F);
}
};
/*------------------------------Graph Moves----------------------------*/
// Rotation: S -> E -> N -> W
// const int fx[] = {0, +1, 0, -1};
// const int fy[] = {-1, 0, +1, 0};
// const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
// const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
// const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
// const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
/*---------------------------------------------------------------------*/
/// Bit Operations
/// count set bit C = (num * 0x200040008001ULL & 0x111111111111111ULL) % 0xf;
/// /// 32 bit integer inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
/// inline ll setBit(ll n, int i) { return n|(1LL<<i); }
/// inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }
/// ************************************** Code starts here
/// ****************************************** */
const ll INF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-9;
const int inf = 0x3f3f3f3f;
const int mx = (int)1e5 + 9;
ll n, m, a, b, t, i, W, j, d, cs = 0, counT = 0, k, ans = 0, l = 0, sum1 = 0,
sum = 0, Max, Min, num;
vector<ll> vc;
ll dp[10000 + 9][100];
ll wt[mx + 9], val[mx + 9];
ll W_MAX = (ll)1e9;
ll knapSack(int r, int i = 0) {
if (r <= 0)
return 0;
if (i == n)
return W_MAX;
if (dp[r][i] != -1)
return dp[r][i];
dp[r][i] = min(knapSack(r, i + 1), wt[i] + knapSack(r - val[i], i + 1));
return dp[r][i];
}
ll maxWeight() {
for (i = sum; i >= 0; i--)
if (knapSack(i) <= W)
return i;
return 0;
}
int main() {
cin >> n >> W;
MEM(dp, -1);
f0(i, n) {
cin >> wt[i] >> val[i];
sum += val[i];
}
cout << maxWeight() << ln;
}
|
///*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*///
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define ln '\n'
#define inp(x) scanf("%lld", &x)
#define inp2(a, b) scanf("%lld %lld", &a, &b)
#define f0(i, b) for (int i = 0; i < (b); i++)
#define f1(i, b) for (int i = 1; i <= (b); i++)
#define MOD 1000000007
#define PI acos(-1)
#define ll long long int
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define F first
#define S second
#define sz size()
#define LCM(a, b) (a * (b / __gcd(a, b)))
// #define harmonic(n) 0.57721566490153286060651209+log(n)+1.0/(2*n)
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define all(v) v.begin(), v.end()
#define MEM(a, b) memset(a, b, sizeof(a))
#define fastio ios_base::sync_with_stdio(false)
/*
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including */
// using namespace __gnu_pbds;
/*
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; template<typename F, typename S> using
ordered_map = tree<F, S, less<F>, rb_tree_tag,
tree_order_statistics_node_update>;
// find_by_order(k) – ফাংশনটি kth ordered element এর একটা পয়েন্টার রিটার্ন করে।
অর্থাৎ তুমি চাইলেই kth ইন্ডেক্সে কি আছে, সেটা জেনে ফেলতে পারছো!
// order_of_key(x) – ফƂশনটি x এলিমਠƨ্টটޠকোন পজিশনে আছে সেটা বলে
দেয়।
*/
/// Inline functions
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool isLeapYear(ll year) {
return (year % 400 == 0) | (year % 4 == 0 && year % 100 != 0);
}
inline void normal(ll &a) {
a %= MOD;
(a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline bool isInside(pii p, ll n, ll m) {
return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m);
}
inline bool isInside(pii p, ll n) {
return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n);
}
inline bool isSquare(ll x) {
ll s = sqrt(x);
return (s * s == x);
}
inline bool isFib(ll x) {
return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4);
}
inline bool isPowerOfTwo(ll x) { return ((1LL << (ll)log2(x)) == x); }
/// DEBUG
/// --------------------------------------------------------------------------------->>>>>>
///**
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "}";
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
for (auto it = v.begin(); it != v.end(); ++it) {
if (it != v.begin())
os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
#define dbg(args...) \
do { \
cerr << #args << " : "; \
faltu(args); \
} while (0)
clock_t tStart = clock();
#define timeStamp \
dbg("Execution Time: ", (double)(clock() - tStart) / CLOCKS_PER_SEC)
void faltu() { cerr << endl; }
template <typename T> void faltu(T a[], int n) {
for (int i = 0; i < n; ++i)
cerr << a[i] << ' ';
cerr << endl;
}
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
cerr << arg << ' ';
faltu(rest...);
}
/// TEMPLATE
/// ----------------------------------------------------------------------->>>>>>
struct func {
// this is a sample overloading function for sorting stl
bool operator()(pii const &a, pii const &b) {
if (a.F == b.F)
return (a.S < b.S);
return (a.F < b.F);
}
};
/*------------------------------Graph Moves----------------------------*/
// Rotation: S -> E -> N -> W
// const int fx[] = {0, +1, 0, -1};
// const int fy[] = {-1, 0, +1, 0};
// const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
// const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
// const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
// const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
/*---------------------------------------------------------------------*/
/// Bit Operations
/// count set bit C = (num * 0x200040008001ULL & 0x111111111111111ULL) % 0xf;
/// /// 32 bit integer inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
/// inline ll setBit(ll n, int i) { return n|(1LL<<i); }
/// inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }
/// ************************************** Code starts here
/// ****************************************** */
const ll INF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-9;
const int inf = 0x3f3f3f3f;
const int mx = (int)1e5 + 9;
ll n, m, a, b, t, i, W, j, d, cs = 0, counT = 0, k, ans = 0, l = 0, sum1 = 0,
sum = 0, Max, Min, num;
vector<ll> vc;
ll dp[100000 + 9][100];
ll wt[mx + 9], val[mx + 9];
ll W_MAX = (ll)1e9;
ll knapSack(int r, int i = 0) {
if (r <= 0)
return 0;
if (i == n)
return W_MAX;
if (dp[r][i] != -1)
return dp[r][i];
dp[r][i] = min(knapSack(r, i + 1), wt[i] + knapSack(r - val[i], i + 1));
return dp[r][i];
}
ll maxWeight() {
for (i = sum; i >= 0; i--)
if (knapSack(i) <= W)
return i;
return 0;
}
int main() {
cin >> n >> W;
MEM(dp, -1);
f0(i, n) {
cin >> wt[i] >> val[i];
sum += val[i];
}
cout << maxWeight() << ln;
}
|
replace
| 210 | 211 | 210 | 211 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
typedef long long int ll;
ll N, K;
ll DP[100005][102];
ll W[102], V[102];
ll INF = 1e18;
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> W[i + 1] >> V[i + 1];
for (int i = 1; i < 1003 * N; i++)
DP[i][0] = INF;
for (int i = 0; i < N * 1003; i++)
for (int j = 1; j < N + 1; j++)
DP[i][j] = min(DP[i][j - 1],
((i - V[j] >= 0) ? (DP[i - V[j]][j - 1] + W[j]) : INF));
for (int i = N * 1003 - 1; i >= 0; i--)
if (DP[i][N] <= K) {
cout << i;
return 0;
}
}
|
#include <iostream>
using namespace std;
typedef long long int ll;
ll N, K;
ll DP[110005][102];
ll W[102], V[102];
ll INF = 1e18;
int main() {
cin >> N >> K;
for (int i = 0; i < N; i++)
cin >> W[i + 1] >> V[i + 1];
for (int i = 1; i < 1003 * N; i++)
DP[i][0] = INF;
for (int i = 0; i < N * 1003; i++)
for (int j = 1; j < N + 1; j++)
DP[i][j] = min(DP[i][j - 1],
((i - V[j] >= 0) ? (DP[i - V[j]][j - 1] + W[j]) : INF));
for (int i = N * 1003 - 1; i >= 0; i--)
if (DP[i][N] <= K) {
cout << i;
return 0;
}
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define MX 100000
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
x = 0;
int c = getchar(), f = 1;
for (; !isdigit(c); c = getchar())
if (c == 45)
f = -1;
for (; isdigit(c); c = getchar())
(x *= 10) += f * (c - '0');
}
int n, w[105], v[105];
lnt m, f[MX + 5];
int main() {
read(n), read(m);
for (int i = 1; i <= n; i++)
read(w[i]), read(v[i]);
memset(f, 0x3f, sizeof f), f[0] = 0;
for (int i = 1; i <= n; i++)
for (int j = MX; ~j; j--)
f[j] = min(f[j], f[j - v[i]] + w[i]);
for (int i = MX; ~i; i--)
if (f[i] <= m)
return printf("%d\n", i), 0;
return 0;
}
|
#include <bits/stdc++.h>
#define MX 100000
using namespace std;
typedef long long lnt;
template <class T> inline void read(T &x) {
x = 0;
int c = getchar(), f = 1;
for (; !isdigit(c); c = getchar())
if (c == 45)
f = -1;
for (; isdigit(c); c = getchar())
(x *= 10) += f * (c - '0');
}
int n, w[105], v[105];
lnt m, f[MX + 5];
int main() {
read(n), read(m);
for (int i = 1; i <= n; i++)
read(w[i]), read(v[i]);
memset(f, 0x3f, sizeof f), f[0] = 0;
for (int i = 1; i <= n; i++)
for (int j = MX; j >= v[i]; j--)
f[j] = min(f[j], f[j - v[i]] + w[i]);
for (int i = MX; ~i; i--)
if (f[i] <= m)
return printf("%d\n", i), 0;
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03164
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 110
#define W 100010
using namespace std;
ll dp[N][W], A[N], B[N], n;
ll fun(int a, int b) {
if (b < 0)
return 2 * 1e9;
if (a == n) {
if (b == 0)
return 0;
return 2 * 1e9;
}
return dp[a][b] = min(fun(a + 1, b), B[a] + fun(a + 1, b - A[a]));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int w;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> B[i] >> A[i];
memset(dp, -1, sizeof(dp));
for (int i = 100000; i >= 0; i--) {
if (fun(0, i) <= w) {
cout << i << '\n';
return 0;
}
}
}
|
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 110
#define W 100010
using namespace std;
ll dp[N][W], A[N], B[N], n;
ll fun(int a, int b) {
if (b < 0)
return 2 * 1e9;
if (a == n) {
if (b == 0)
return 0;
return 2 * 1e9;
}
if (dp[a][b] != -1)
return dp[a][b];
return dp[a][b] = min(fun(a + 1, b), B[a] + fun(a + 1, b - A[a]));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int w;
cin >> n >> w;
for (int i = 0; i < n; i++)
cin >> B[i] >> A[i];
memset(dp, -1, sizeof(dp));
for (int i = 100000; i >= 0; i--) {
if (fun(0, i) <= w) {
cout << i << '\n';
return 0;
}
}
}
|
insert
| 17 | 17 | 17 | 19 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
void Main() {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
long total_val = 0;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
total_val += v[i];
}
long max_value = 0;
vector<vector<long>> nap(N, vector<long>(total_val + 1, 1e18));
for (int i = 0; i < N; i++)
nap[i][0] = 0;
for (long j = 1; j <= total_val; j++) {
if (j <= v[0])
nap[0][j] = w[0];
if (nap[0][j] <= W)
max_value = max(max_value, j);
}
for (int i = 1; i < N; i++) {
for (int j = 1; j <= total_val; j++) {
if (j <= v[0]) {
nap[i][j] = min((long)w[i], nap[i - 1][j]);
} else {
nap[i][j] = min(nap[i - 1][j - v[i]] + w[i], nap[i - 1][j]);
}
if (nap[i][j] <= W)
max_value = max(max_value, (long)j);
}
}
cout << max_value << endl;
}
int main(int argc, char **argv) {
Main();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void Main() {
int N, W;
cin >> N >> W;
vector<int> w(N), v(N);
long total_val = 0;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
total_val += v[i];
}
long max_value = 0;
vector<vector<long>> nap(N, vector<long>(total_val + 1, 1e18));
for (int i = 0; i < N; i++)
nap[i][0] = 0;
for (long j = 1; j <= total_val; j++) {
if (j <= v[0])
nap[0][j] = w[0];
if (nap[0][j] <= W)
max_value = max(max_value, j);
}
for (int i = 1; i < N; i++) {
for (int j = 1; j <= total_val; j++) {
if (j <= v[i]) {
nap[i][j] = min((long)w[i], nap[i - 1][j]);
} else {
nap[i][j] = min(nap[i - 1][j - v[i]] + w[i], nap[i - 1][j]);
}
if (nap[i][j] <= W)
max_value = max(max_value, (long)j);
}
}
cout << max_value << endl;
}
int main(int argc, char **argv) {
Main();
return 0;
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int N, W;
cin >> N >> W;
vector<int> w(N);
vector<int> v(N);
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
vector<vector<int>> dp(100, vector<int>(100000 + 100, 1e16));
int V = *max_element(v.begin(), v.end());
int ans = 0;
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= V * N; j++) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
}
}
for (int j = 0; j <= V * N; j++) {
if (dp[N][j] <= W)
ans = j;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int N, W;
cin >> N >> W;
vector<int> w(N);
vector<int> v(N);
for (int i = 0; i < N; i++)
cin >> w[i] >> v[i];
vector<vector<int>> dp(110, vector<int>(1000000 + 100, 1e16));
int V = *max_element(v.begin(), v.end());
int ans = 0;
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= V * N; j++) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
}
}
for (int j = 0; j <= V * N; j++) {
if (dp[N][j] <= W)
ans = j;
}
cout << ans << endl;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define prior priority_queue
#define MOD 1000000007
#define INF64 (long long int)1e18
#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define ll long long int
#define ld long double
#define ret return
#define NUM 1000001
const int SIZE = 2e5 + 4;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int p[20000];
ll dp[200005];
int main() {
fastio();
input();
ll N;
ll W;
cin >> N >> W;
ll w[N + 1];
ll v[N + 1];
ll total_val = 0;
for (ll i = 1; i <= N; i++) {
cin >> w[i] >> v[i];
total_val += v[i];
}
ll dp[N + 1][total_val + 1];
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= total_val; j++) {
if (j == 0) {
dp[i][j] = (ll)0;
} else {
dp[i][j] = INF64;
}
}
}
/* for(int i=0;i<=N;i++){
for(int j=0;j<=total_val;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
for (ll i = 1; i <= N; i++) {
for (ll j = 1; j <= total_val; j++) {
if (v[i] <= j)
dp[i][j] = min(w[i] + dp[i - 1][j - v[i]], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
ll ans = 0;
for (ll i = 1; i <= total_val; i++) {
if (dp[N][i] <= W) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define prior priority_queue
#define MOD 1000000007
#define INF64 (long long int)1e18
#define INF (int)1e9
#define PI 3.1415926535897932384626433832795
#define ll long long int
#define ld long double
#define ret return
#define NUM 1000001
const int SIZE = 2e5 + 4;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void input() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int p[20000];
ll dp[200005];
int main() {
fastio();
// input();
ll N;
ll W;
cin >> N >> W;
ll w[N + 1];
ll v[N + 1];
ll total_val = 0;
for (ll i = 1; i <= N; i++) {
cin >> w[i] >> v[i];
total_val += v[i];
}
ll dp[N + 1][total_val + 1];
for (ll i = 0; i <= N; i++) {
for (ll j = 0; j <= total_val; j++) {
if (j == 0) {
dp[i][j] = (ll)0;
} else {
dp[i][j] = INF64;
}
}
}
/* for(int i=0;i<=N;i++){
for(int j=0;j<=total_val;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
for (ll i = 1; i <= N; i++) {
for (ll j = 1; j <= total_val; j++) {
if (v[i] <= j)
dp[i][j] = min(w[i] + dp[i - 1][j - v[i]], dp[i - 1][j]);
else
dp[i][j] = dp[i - 1][j];
}
}
ll ans = 0;
for (ll i = 1; i <= total_val; i++) {
if (dp[N][i] <= W) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 33 | 34 | 33 | 34 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
ll tot = 0;
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
tot += v[i];
}
ll ans = 0;
vector<ll> min(tot, -1);
tot = 0;
min[0] = 0;
for (ll i = 0; i < n; i++) {
tot += v[i];
for (ll j = tot; j >= v[i]; j--) {
if (min[j - v[i]] != -1) {
ll req = min[j - v[i]] + wt[i];
if (req <= w)
ans = max(ans, j);
if (min[j] == -1 || min[j] > req)
min[j] = req;
}
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a) * (a)
#define debug(x) cerr << #x << '=' << (x) << endl;
#define debugv(v) \
cerr << #v << " : "; \
for (auto x : v) \
cerr << x << ' '; \
cerr << endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
ll exp(ll x, ll n, ll mod) {
ll result = 1;
while (n > 0) {
if (n & 1 == 1)
result = (result * x) % mod;
x = (x * x) % mod;
n = n >> 1;
}
return result;
}
int32_t main() {
IOS
ll n,
w;
cin >> n >> w;
ll v[n], wt[n];
ll tot = 0;
for (ll i = 0; i < n; i++) {
cin >> wt[i] >> v[i];
tot += v[i];
}
ll ans = 0;
vector<ll> min(tot, -1);
tot = 0;
min[0] = 0;
for (ll i = 0; i < n; i++) {
tot += v[i];
for (ll j = tot; j >= v[i]; j--) {
if (min[j - v[i]] != -1) {
ll req = min[j - v[i]] + wt[i];
if (req <= w)
ans = max(ans, j);
if (min[j] == -1 || min[j] > req)
min[j] = req;
}
}
}
cout << ans << endl;
return 0;
}
|
delete
| 38 | 42 | 38 | 38 |
-11
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const ll dx[9] = {0, -1, 0, 1, 1, -1, 1, -1, 0};
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;
}
vvl dp(101, vl(100010, INF));
int main() {
ll n, w;
cin >> n >> w;
vpl it(n);
rep(i, n) cin >> it[i].fi >> it[i].se;
dp[0][0] = 0;
rep(i, n) {
rep(j, 100005) {
chmin(dp[i + 1][j + it[i].se], dp[i][j] + it[i].fi);
chmin(dp[i + 1][j], dp[i][j]);
}
}
per(i, 100005) if (dp[n][i] <= w) cout << i << endl, exit(0);
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define per(i, n) for (ll i = n - 1; i >= 0; i--)
#define perl(i, r, l) for (ll i = r - 1; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x, vector<x>, greater<x>>
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
#define rev(x) reverse(x);
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const ll dx[9] = {0, -1, 0, 1, 1, -1, 1, -1, 0};
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;
}
vvl dp(101, vl(100010, INF));
int main() {
ll n, w;
cin >> n >> w;
vpl it(n);
rep(i, n) cin >> it[i].fi >> it[i].se;
dp[0][0] = 0;
rep(i, n) {
rep(j, 100005) {
if (j + it[i].se <= 100001)
chmin(dp[i + 1][j + it[i].se], dp[i][j] + it[i].fi);
chmin(dp[i + 1][j], dp[i][j]);
}
}
per(i, 100005) if (dp[n][i] <= w) cout << i << endl, exit(0);
}
|
replace
| 49 | 50 | 49 | 51 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
long long dp[105][1005];
// ミョ(-ω- ?)
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n, 0);
vector<ll> value(n, 0);
ll max_value = 0;
rep(i, n) {
cin >> weight[i] >> value[i];
max_value = max(max_value, value[i]);
}
rep(i, n * max_value + 1) dp[0][i] = (1LL << 60);
// dp[i][j] = i番目の荷物 価値jまで詰めたときの重さの最小値
dp[0][0] = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j <= n * max_value; j++) {
if (j < value[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]);
}
}
ll res = 0;
rep(i, n * max_value + 1) {
if (dp[n][i] <= w)
res = i;
}
cout << res << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define repp(i, l, r) for (long long i = (l); i < (r); i++)
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define per(i, n) for (long long i = (n); i >= 0; --i)
const int INF = 1 << 30; // int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
long long dp[105][1000005];
// ミョ(-ω- ?)
int main() {
ll n, w;
cin >> n >> w;
vector<ll> weight(n, 0);
vector<ll> value(n, 0);
ll max_value = 0;
rep(i, n) {
cin >> weight[i] >> value[i];
max_value = max(max_value, value[i]);
}
rep(i, n * max_value + 1) dp[0][i] = (1LL << 60);
// dp[i][j] = i番目の荷物 価値jまで詰めたときの重さの最小値
dp[0][0] = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 0; j <= n * max_value; j++) {
if (j < value[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]);
}
}
ll res = 0;
rep(i, n * max_value + 1) {
if (dp[n][i] <= w)
res = i;
}
cout << res << "\n";
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[10005][1005];
int solve(int r, int i, int wt[], int val[], int n) {
if (r <= 0)
return 0;
if (i == n)
return INT_MAX;
if (dp[r][i] != -1)
return dp[r][i];
return dp[r][i] = min(solve(r, i + 1, wt, val, n),
wt[i] + solve(r - val[i], i + 1, wt, val, n));
}
int32_t main() {
int n, w;
cin >> n >> w;
int wt[n + 1];
int val[n + 1];
int V = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
V += val[i];
}
memset(dp, -1, sizeof(dp));
for (int i = V; i >= 0; i--) {
if (solve(i, 0, wt, val, n) <= w) {
cout << i << endl;
break;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[100005][105];
int solve(int r, int i, int wt[], int val[], int n) {
if (r <= 0)
return 0;
if (i == n)
return INT_MAX;
if (dp[r][i] != -1)
return dp[r][i];
return dp[r][i] = min(solve(r, i + 1, wt, val, n),
wt[i] + solve(r - val[i], i + 1, wt, val, n));
}
int32_t main() {
int n, w;
cin >> n >> w;
int wt[n + 1];
int val[n + 1];
int V = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
V += val[i];
}
memset(dp, -1, sizeof(dp));
for (int i = V; i >= 0; i--) {
if (solve(i, 0, wt, val, n) <= w) {
cout << i << endl;
break;
}
}
}
|
replace
| 3 | 4 | 3 | 4 |
0
| |
p03164
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <iostream>
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
const int MAXN = 100;
const int MAXV = 1e5;
const int INF = 0x3f3f3f3f;
template <typename T> inline T read() {
T res = 0, flag = 1;
char in = getchar();
while (!isdigit(in)) {
if (in == '-')
flag = -1;
in = getchar();
}
while (isdigit(in)) {
res = (res << 1) + (res << 3) + in - '0';
in = getchar();
}
return res * flag;
}
template <typename T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
int dp[MAXV + 10];
int w[MAXN], val[MAXN], n, W;
inline void solve() {
n = read<int>();
W = read<int>();
for (int i = 1; i <= n; ++i)
w[i] = read<int>(), val[i] = read<int>();
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = MAXV; j >= val[i]; --j)
chkmin(dp[j], dp[j - val[i]] + w[i]);
for (int i = MAXV;; --i)
if (dp[i] <= W) {
printf("%d\n", i);
return;
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("E.in", "r", stdin);
freopen("E.out", "w", stdout);
#endif
solve();
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <iostream>
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
const int MAXN = 100;
const int MAXV = 1e5;
const int INF = 0x3f3f3f3f;
template <typename T> inline T read() {
T res = 0, flag = 1;
char in = getchar();
while (!isdigit(in)) {
if (in == '-')
flag = -1;
in = getchar();
}
while (isdigit(in)) {
res = (res << 1) + (res << 3) + in - '0';
in = getchar();
}
return res * flag;
}
template <typename T> inline void chkmax(T &a, T b) {
if (a < b)
a = b;
}
template <typename T> inline void chkmin(T &a, T b) {
if (a > b)
a = b;
}
int dp[MAXV + 10];
int w[MAXN], val[MAXN], n, W;
inline void solve() {
n = read<int>();
W = read<int>();
for (int i = 1; i <= n; ++i)
w[i] = read<int>(), val[i] = read<int>();
memset(dp, 0x3f, sizeof dp);
dp[0] = 0;
for (int i = 1; i <= n; ++i)
for (int j = MAXV; j >= val[i]; --j)
chkmin(dp[j], dp[j - val[i]] + w[i]);
for (int i = MAXV;; --i)
if (dp[i] <= W) {
printf("%d\n", i);
return;
}
}
int main() {
solve();
return 0;
}
|
delete
| 64 | 68 | 64 | 64 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;
int main() {
int N, W;
cin >> N >> W;
vec<ll> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
ll MAX_VAL = 1000 * 100;
vec<vec<ll>> dp(N + 1, vec<ll>(MAX_VAL + 100, 1e14 + 5));
for (int i = 1; i <= N; ++i) {
dp[i][v[i - 1]] = min(dp[i][v[i - 1]], w[i - 1]);
for (int j = 0; j <= MAX_VAL; ++j) {
dp[i][j] = min({dp[i][j], dp[i - 1][j]});
dp[i][j + v[i - 1]] = min(dp[i][j + v[i - 1]], dp[i - 1][j] + w[i - 1]);
}
}
ll ans = 0;
rep(i, MAX_VAL + 50) if (dp[N][i] <= W) ans = max(ans, i);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;
int main() {
int N, W;
cin >> N >> W;
vec<ll> w(N), v(N);
rep(i, N) cin >> w[i] >> v[i];
ll MAX_VAL = 10000 * N;
vec<vec<ll>> dp(N + 1, vec<ll>(MAX_VAL + 100, 1e14 + 5));
for (int i = 1; i <= N; ++i) {
dp[i][v[i - 1]] = min(dp[i][v[i - 1]], w[i - 1]);
for (int j = 0; j <= MAX_VAL; ++j) {
dp[i][j] = min({dp[i][j], dp[i - 1][j]});
dp[i][j + v[i - 1]] = min(dp[i][j + v[i - 1]], dp[i - 1][j] + w[i - 1]);
}
}
ll ans = 0;
rep(i, MAX_VAL + 50) if (dp[N][i] <= W) ans = max(ans, i);
cout << ans << endl;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define nl '\n'
#define repd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define F first
#define S second
const ll N = 1e6 + 9;
const ll mod = 1e9 + 7;
ll a[100][N];
vector<pair<ll, ll>> v;
void solve() {
ll n, w, w1, v1;
cin >> n >> w;
v.pb({0, 0});
rep(i, 1, n) {
cin >> w1 >> v1;
v.pb({v1, w1});
}
// sort(all(v));
rep(i, 0, n) { rep(j, 1, 100000) a[i][j] = 1e9 + 7; }
rep(i, 1, n) a[i][0] = 0;
rep(i, 1, n) {
rep(j, 1, 100000) {
a[i][j] = a[i - 1][j];
if (j - v[i].F >= 0)
a[i][j] = min(a[i - 1][j], a[i - 1][j - v[i].F] + v[i].S);
// cout<<j<<"<<"<<a[i][j]<<" ";}
}
// cout<<nl;
}
repd(i, 100000, 1) {
if (a[n][i] <= w) {
cout << i;
break;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// pre();
// cin>>t;
// if(t^1)exit(0);
while (t--)
solve();
}
|
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define nl '\n'
#define repd(i, a, b) for (int i = a; i >= b; --i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define F first
#define S second
const ll N = 1e6 + 9;
const ll mod = 1e9 + 7;
ll a[105][N];
vector<pair<ll, ll>> v;
void solve() {
ll n, w, w1, v1;
cin >> n >> w;
v.pb({0, 0});
rep(i, 1, n) {
cin >> w1 >> v1;
v.pb({v1, w1});
}
// sort(all(v));
rep(i, 0, n) { rep(j, 1, 100000) a[i][j] = 1e9 + 7; }
rep(i, 1, n) a[i][0] = 0;
rep(i, 1, n) {
rep(j, 1, 100000) {
a[i][j] = a[i - 1][j];
if (j - v[i].F >= 0)
a[i][j] = min(a[i - 1][j], a[i - 1][j - v[i].F] + v[i].S);
// cout<<j<<"<<"<<a[i][j]<<" ";}
}
// cout<<nl;
}
repd(i, 100000, 1) {
if (a[n][i] <= w) {
cout << i;
break;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll t = 1;
// pre();
// cin>>t;
// if(t^1)exit(0);
while (t--)
solve();
}
|
replace
| 14 | 15 | 14 | 15 |
-11
| |
p03164
|
C++
|
Runtime Error
|
// recurive code hai 0/1 knapsack ka
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define int long long
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ip(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define op(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " ";
#define MAX 100001
void start() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
int dp[101][MAX];
int *wt, *val;
int solve(int capacity, int n, int profit) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= profit; j++) {
if (i == 0 && j == 0)
dp[i][j] = 0;
else if (i == 0)
dp[i][j] = 1e11;
else if (j >= val[i - 1]) {
dp[i][j] = min(wt[i - 1] + dp[i - 1][j - val[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
int ans = 0;
for (int i = 0; i <= profit; i++) {
if (dp[n][i] <= capacity)
ans = i;
}
return ans;
}
int32_t main() {
start();
fastIO
int n,
capacity;
cin >> n >> capacity;
wt = new int[n];
val = new int[n];
int profit = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
profit += val[i];
}
// memset(dp,-1,sizeof(dp));
// cout<<knapsack(wt,val,capacity,n)<<endl;
// cout<<memoization(wt,val,capacity,n)<<endl;
memset(dp, 0, sizeof(dp));
cout << solve(capacity, n, profit) << endl;
}
|
// recurive code hai 0/1 knapsack ka
#include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
#define int long long
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ip(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define op(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << " ";
#define MAX 100001
void start() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
}
int dp[101][MAX];
int *wt, *val;
int solve(int capacity, int n, int profit) {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= profit; j++) {
if (i == 0 && j == 0)
dp[i][j] = 0;
else if (i == 0)
dp[i][j] = 1e11;
else if (j >= val[i - 1]) {
dp[i][j] = min(wt[i - 1] + dp[i - 1][j - val[i - 1]], dp[i - 1][j]);
} else
dp[i][j] = dp[i - 1][j];
}
}
int ans = 0;
for (int i = 0; i <= profit; i++) {
if (dp[n][i] <= capacity)
ans = i;
}
return ans;
}
int32_t main() {
// start();
fastIO
int n,
capacity;
cin >> n >> capacity;
wt = new int[n];
val = new int[n];
int profit = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i];
cin >> val[i];
profit += val[i];
}
// memset(dp,-1,sizeof(dp));
// cout<<knapsack(wt,val,capacity,n)<<endl;
// cout<<memoization(wt,val,capacity,n)<<endl;
memset(dp, 0, sizeof(dp));
cout << solve(capacity, n, profit) << endl;
}
|
replace
| 56 | 57 | 56 | 57 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[110][100100];
void chmin(ll &a, ll b) {
if (a > b) {
a = b;
}
return;
}
const ll inf = 1LL << 60;
int main() {
ll max_v = 0;
for (ll i = 0; i < 110; i++) {
for (ll j = 0; j < 100100; j++) {
dp[i][j] = inf;
}
}
ll N, W;
cin >> N >> W;
vector<ll> w(N);
vector<ll> v(N);
for (ll i = 0; i < N; i++) {
cin >> w[i] >> v[i];
max_v += v[i];
}
dp[0][v[0]] = w[0];
dp[0][0] = 0;
for (ll i = 0; i < N - 1; i++) {
for (ll j = 0; j < 100100; j++) {
chmin(dp[i + 1][j], dp[i][j]);
if (j - v[j + 1] >= 0) {
chmin(dp[i + 1][j], dp[i][j - v[i + 1]] + w[i + 1]);
}
}
}
ll res = 0;
for (ll i = 0; i <= max_v; i++) {
if (dp[N - 1][i] <= W) {
res = i;
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[110][100100];
void chmin(ll &a, ll b) {
if (a > b) {
a = b;
}
return;
}
const ll inf = 1LL << 60;
int main() {
ll max_v = 0;
for (ll i = 0; i < 110; i++) {
for (ll j = 0; j < 100100; j++) {
dp[i][j] = inf;
}
}
ll N, W;
cin >> N >> W;
vector<ll> w(N);
vector<ll> v(N);
for (ll i = 0; i < N; i++) {
cin >> w[i] >> v[i];
max_v += v[i];
}
dp[0][v[0]] = w[0];
dp[0][0] = 0;
for (ll i = 0; i < N - 1; i++) {
for (ll j = 0; j < 100100; j++) {
chmin(dp[i + 1][j], dp[i][j]);
if (j - v[i + 1] >= 0) {
chmin(dp[i + 1][j], dp[i][j - v[i + 1]] + w[i + 1]);
}
}
}
ll res = 0;
for (ll i = 0; i <= max_v; i++) {
if (dp[N - 1][i] <= W) {
res = i;
}
}
cout << res << endl;
return 0;
}
|
replace
| 38 | 39 | 38 | 39 |
-11
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
long long w[105], v[105];
long long dp[105][100005];
int main() {
int N;
long long W;
cin >> N >> W;
for (int i = 1; i <= N; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= N; i++)
for (int j = 1; j <= 100000; j++)
dp[i][j] = 1e18;
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= 100000; j++) {
if (j < v[i])
dp[i][j] = dp[i - 1][j];
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
}
}
for (int i = 100000; i >= 0; i--)
if (dp[N][i] <= W) {
cout << i;
break;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long w[105], v[105];
long long dp[105][100005];
int main() {
int N;
long long W;
cin >> N >> W;
for (int i = 1; i <= N; i++)
cin >> w[i] >> v[i];
for (int i = 0; i <= N; i++)
for (int j = 1; j <= 100000; j++)
dp[i][j] = 1e18;
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= 100000; j++) {
if (j < v[i])
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
}
}
for (int i = 100000; i >= 0; i--)
if (dp[N][i] <= W) {
cout << i;
break;
}
}
|
replace
| 18 | 19 | 18 | 20 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][100020];
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int N, W;
cin >> N >> W;
int w[110], v[110];
rep(i, N) cin >> w[i] >> v[i];
rep(i, 110) rep(j, 100010) dp[i][j] = INF;
dp[0][0] = 0;
rep(i, N) {
RREP(j, 100000, 0) {
dp[i + 1][j] = dp[i][j];
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
}
int ans = 0;
rep(i, N + 1) {
rep(j, 100010) {
if (dp[i][j] <= W)
ans = max(ans, j);
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int dp[110][100020];
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int N, W;
cin >> N >> W;
int w[110], v[110];
rep(i, N) cin >> w[i] >> v[i];
rep(i, 110) rep(j, 100010) dp[i][j] = INF;
dp[0][0] = 0;
rep(i, N) {
RREP(j, 100000, 0) {
dp[i + 1][j] = dp[i][j];
if (j - v[i] >= 0)
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
}
int ans = 0;
rep(i, N + 1) {
rep(j, 100010) {
if (dp[i][j] <= W)
ans = max(ans, j);
}
}
cout << ans << endl;
return 0;
}
|
replace
| 38 | 39 | 38 | 40 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
// Type alias
using ll = long long;
using ld = double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpi = vector<pi>;
using vpll = vector<ll>;
using vpld = vector<ld>;
using vti3 = vector<ti3>;
// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll llinf = numeric_limits<ll>::max() / 2;
const ll mod = 1e9 + 7;
// Macro
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = int(n - 1); i >= 0; --i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RREP(i, a, b) for (int i = int(b - 1); i >= int(a); --i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a, n) \
for (int i = 0; i < int(n); ++i) \
cout << #a << "[" << i << "]" \
<< " = " << a[i] << endl
#define ALL(a) a.begin(), a.end()
// Funtcions
ll pow(ll base, ll i, ll mod) {
ll a = 1;
while (i) {
if (i & 1) {
a *= base;
a %= mod;
}
base *= base;
base %= mod;
i >>= 1;
}
return a;
}
ll gcd(ll a, ll b) {
while (b) {
ll c = a % b;
a = b;
b = c;
}
return a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T> bool chmin(T &a, const T &b) {
if (a > b)
return a = b, true;
else
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b)
return a = b, true;
else
return false;
}
ll dp[105][1005];
void solve() {
ll N, W;
cin >> N >> W;
ll w[105], v[105];
rep(i, N) cin >> w[i] >> v[i];
dp[0][0] = 0;
REP(j, 1, 100000 + 1) dp[0][j] = llinf;
rep(i, N) {
rep(j, 100000 + 1) {
if (j - v[i] >= 0) {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
rrep(i, 100000 + 1) {
if (dp[N][i] <= W) {
cout << i << endl;
break;
}
}
}
int main() {
// FastIO
// ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
// Type alias
using ll = long long;
using ld = double;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
using ti3 = tuple<int, int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;
using vpi = vector<pi>;
using vpll = vector<ll>;
using vpld = vector<ld>;
using vti3 = vector<ti3>;
// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll llinf = numeric_limits<ll>::max() / 2;
const ll mod = 1e9 + 7;
// Macro
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = int(n - 1); i >= 0; --i)
#define REP(i, a, b) for (int i = int(a); i < int(b); ++i)
#define RREP(i, a, b) for (int i = int(b - 1); i >= int(a); --i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a, n) \
for (int i = 0; i < int(n); ++i) \
cout << #a << "[" << i << "]" \
<< " = " << a[i] << endl
#define ALL(a) a.begin(), a.end()
// Funtcions
ll pow(ll base, ll i, ll mod) {
ll a = 1;
while (i) {
if (i & 1) {
a *= base;
a %= mod;
}
base *= base;
base %= mod;
i >>= 1;
}
return a;
}
ll gcd(ll a, ll b) {
while (b) {
ll c = a % b;
a = b;
b = c;
}
return a;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T> bool chmin(T &a, const T &b) {
if (a > b)
return a = b, true;
else
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b)
return a = b, true;
else
return false;
}
ll dp[105][100005];
void solve() {
ll N, W;
cin >> N >> W;
ll w[105], v[105];
rep(i, N) cin >> w[i] >> v[i];
dp[0][0] = 0;
REP(j, 1, 100000 + 1) dp[0][j] = llinf;
rep(i, N) {
rep(j, 100000 + 1) {
if (j - v[i] >= 0) {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
rrep(i, 100000 + 1) {
if (dp[N][i] <= W) {
cout << i << endl;
break;
}
}
}
int main() {
// FastIO
// ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
return 0;
}
|
replace
| 76 | 77 | 76 | 77 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define pb push_back
#define rep(a, b, c) for (int a = (int)b; a < (int)c; a++)
#define repk(a, b, c, k) for (int a = (int)b; a < (int)c; a += (int)k)
#define comeback \
std::ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int, int>
#define ful(a) a.begin(), a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x, int n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return em((x % mod * x % mod) % mod, n / 2);
else
return (x % mod * em((x % mod * x % mod) % mod, (n - 1) / 2)) % mod;
}
int dp[102][100009];
signed main() {
comeback
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output1.txt", "w", stdout);
#endif
int n, W, i, j, k, l;
cin >> n >> W;
int w[n + 1], va[n + 1];
for (i = 1; i <= n; i++) {
cin >> w[i] >> va[i];
}
for (i = 0; i <= n; i++)
for (j = 0; j <= 100000; j++)
dp[i][j] = 1e15;
dp[0][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= 100000; j++) {
if (va[i] <= j)
dp[i][j] = min(dp[i - 1][j], w[i] + dp[i - 1][j - va[i]]);
else
dp[i][j] = dp[i - 1][j];
}
}
for (i = 100000; i >= 0; i--)
if (dp[n][i] <= W) {
cout << i;
return 0;
}
cout << 0;
}
|
#include <bits/stdc++.h>
#define pb push_back
#define rep(a, b, c) for (int a = (int)b; a < (int)c; a++)
#define repk(a, b, c, k) for (int a = (int)b; a < (int)c; a += (int)k)
#define comeback \
std::ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int, int>
#define ful(a) a.begin(), a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x, int n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return em((x % mod * x % mod) % mod, n / 2);
else
return (x % mod * em((x % mod * x % mod) % mod, (n - 1) / 2)) % mod;
}
int dp[102][100009];
signed main() {
comeback
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output1.txt","w",stdout);
#endif*/
int n,
W, i, j, k, l;
cin >> n >> W;
int w[n + 1], va[n + 1];
for (i = 1; i <= n; i++) {
cin >> w[i] >> va[i];
}
for (i = 0; i <= n; i++)
for (j = 0; j <= 100000; j++)
dp[i][j] = 1e15;
dp[0][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 0; j <= 100000; j++) {
if (va[i] <= j)
dp[i][j] = min(dp[i - 1][j], w[i] + dp[i - 1][j - va[i]]);
else
dp[i][j] = dp[i - 1][j];
}
}
for (i = 100000; i >= 0; i--)
if (dp[n][i] <= W) {
cout << i;
return 0;
}
cout << 0;
}
|
replace
| 28 | 33 | 28 | 34 |
-11
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
/*
||||||||||||||||||||||||||||||||||||||||||||||||
| ||| | |||| |||| | |
| | | | | | | | | | |
| | | | | | | | | | |
||||||| | | ||||||| ||| ||| |||||
| | | | | | | | | | |
| | ||| | | | || |||| | |
||||||||||||||||||||||||||||||||||||||||||||||||
*/
using namespace std;
// #include "testlib.h"
#define ff first
#define ss second
#define mp make_pair
#define all(v) v.begin(), v.end()
#define int long long
#define ll long long
#define M 1000000007
#define inputarr(a, n) \
for (int i = 0; i < n; ++i) \
cin >> a[i]
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll int, string>
#define rep(a, b) for (ll i = a; i < b; i++)
#define rep0(n) for (ll i = 0; i < n; i++)
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define vi vector<ll>
#define mp make_pair
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define FORE(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define inputoutput \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define input freopen("input.txt", "r", stdin);
#define Set(a, s) 4(a, s, sizeof(a))
#define FOR repi
#define pii pair<int, int>
#define REVERSE(v) reverse(ALL(v))
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl
#define debug cerr << "bhau" << endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
// #define float long double
ll max(ll a, ll b) { return (a > b) ? a : b; }
int min(int a, int b) { return (a < b) ? a : b; }
#define INF 1e11L
int solve() {
int n, W;
cin >> n >> W;
vi w(n), v(n);
rep0(n) cin >> w[i] >> v[i];
int sum_value = 0;
for (int i = 0; i < n; i++)
sum_value += v[i];
vi dp(sum_value + 100, INF);
// dp[i] contain minimum weight contained with total value i
dp[0] = 0;
for (int item = 0; item < n; item++) {
for (int value = sum_value - v[item]; value >= 0; value--) {
dp[value + v[item]] = min(dp[value + v[item]], dp[value] + w[item]);
}
}
int ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= W)
ans = max(ans, i);
}
cout << ans;
r0
}
signed main() {
asdf inputoutput int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
/*
||||||||||||||||||||||||||||||||||||||||||||||||
| ||| | |||| |||| | |
| | | | | | | | | | |
| | | | | | | | | | |
||||||| | | ||||||| ||| ||| |||||
| | | | | | | | | | |
| | ||| | | | || |||| | |
||||||||||||||||||||||||||||||||||||||||||||||||
*/
using namespace std;
// #include "testlib.h"
#define ff first
#define ss second
#define mp make_pair
#define all(v) v.begin(), v.end()
#define int long long
#define ll long long
#define M 1000000007
#define inputarr(a, n) \
for (int i = 0; i < n; ++i) \
cin >> a[i]
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll int, string>
#define rep(a, b) for (ll i = a; i < b; i++)
#define rep0(n) for (ll i = 0; i < n; i++)
#define repi(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define vi vector<ll>
#define mp make_pair
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define FORE(it, c) \
for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define inputoutput \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define input freopen("input.txt", "r", stdin);
#define Set(a, s) 4(a, s, sizeof(a))
#define FOR repi
#define pii pair<int, int>
#define REVERSE(v) reverse(ALL(v))
#define display(x) \
trav(a, x) cout << a << " "; \
cout << endl
#define debug cerr << "bhau" << endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
std::cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
// #define float long double
ll max(ll a, ll b) { return (a > b) ? a : b; }
int min(int a, int b) { return (a < b) ? a : b; }
#define INF 1e11L
int solve() {
int n, W;
cin >> n >> W;
vi w(n), v(n);
rep0(n) cin >> w[i] >> v[i];
int sum_value = 0;
for (int i = 0; i < n; i++)
sum_value += v[i];
vi dp(sum_value + 100, INF);
// dp[i] contain minimum weight contained with total value i
dp[0] = 0;
for (int item = 0; item < n; item++) {
for (int value = sum_value - v[item]; value >= 0; value--) {
dp[value + v[item]] = min(dp[value + v[item]], dp[value] + w[item]);
}
}
int ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= W)
ans = max(ans, i);
}
cout << ans;
r0
}
signed main() {
asdf
// inputoutput
int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
|
replace
| 105 | 106 | 105 | 108 |
-6
|
terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;
int main(void) {
ll N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
REP(i, 0, N) cin >> w[i] >> v[i];
const ll INF = 1LL << 60;
vector<vector<ll>> dp(N + 1, vector<ll>(100001, INF));
dp[0][0] = 0;
REP(i, 0, N) {
REP(j, 0, 100001) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
}
}
ll ans = 0;
REP(i, 0, 100001) {
if (dp[N][i] <= W) {
ans = i;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;
int main(void) {
ll N, W;
cin >> N >> W;
vector<ll> w(N), v(N);
REP(i, 0, N) cin >> w[i] >> v[i];
const ll INF = 1LL << 60;
vector<vector<ll>> dp(N + 1, vector<ll>(100001, INF));
dp[0][0] = 0;
REP(i, 0, N) {
REP(j, 0, 100001) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
if (j + v[i] <= 100000) {
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
}
}
}
ll ans = 0;
REP(i, 0, 100001) {
if (dp[N][i] <= W) {
ans = i;
}
}
cout << ans << endl;
}
|
replace
| 18 | 19 | 18 | 21 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INFint = 2e9 + 1;
const ll INFll = 2e18 + 1;
ll MOD = 1e9 + 7;
int main() {
int N, W;
cin >> N >> W;
vector<int> wi(N + 1), vi(N + 1);
for (int i(1); i <= N; i++) {
cin >> wi[i] >> vi[i];
}
ll dp[101][10001] = {0};
for (int i(0); i <= N; i++) {
for (int v(1); v <= N * 1000; v++) {
dp[i][v] = INFll;
}
}
for (int i(1); i <= N; i++) {
for (int v(0); v <= N * 1000; v++) {
if (v >= vi[i]) {
dp[i][v] = min(dp[i - 1][v], dp[i - 1][v - vi[i]] + wi[i]);
} else {
dp[i][v] = dp[i - 1][v];
}
}
}
for (int i(0); i < N; i++) {
for (int v(0); v <= N * 10; v++) {
// cout << dp[i][v] << " ";
}
// cout << endl;
}
ll ans(0);
for (ll i(0); i <= N * 1000; i++) {
if (dp[N][i] <= W)
ans = i;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INFint = 2e9 + 1;
const ll INFll = 2e18 + 1;
ll MOD = 1e9 + 7;
int main() {
int N, W;
cin >> N >> W;
vector<int> wi(N + 1), vi(N + 1);
for (int i(1); i <= N; i++) {
cin >> wi[i] >> vi[i];
}
ll dp[101][100001] = {0};
for (int i(0); i <= N; i++) {
for (int v(1); v <= N * 1000; v++) {
dp[i][v] = INFll;
}
}
for (int i(1); i <= N; i++) {
for (int v(0); v <= N * 1000; v++) {
if (v >= vi[i]) {
dp[i][v] = min(dp[i - 1][v], dp[i - 1][v - vi[i]] + wi[i]);
} else {
dp[i][v] = dp[i - 1][v];
}
}
}
for (int i(0); i < N; i++) {
for (int v(0); v <= N * 10; v++) {
// cout << dp[i][v] << " ";
}
// cout << endl;
}
ll ans(0);
for (ll i(0); i <= N * 1000; i++) {
if (dp[N][i] <= W)
ans = i;
}
cout << ans << endl;
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define var auto
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1LL << 60;
const int MAX_ITEM = 100;
const int MAX_VALUE = 100000;
ll dp[MAX_ITEM][MAX_VALUE]; // 重さ
int main() {
int n;
ll w;
cin >> n >> w;
ll weight[n];
ll value[n];
rep(i, n) { cin >> weight[i] >> value[i]; }
// 最小化問題なのでINF埋め
rep(i, MAX_ITEM) { rep(j, MAX_VALUE) dp[i][j] = INF; }
// 初期値00だけ0にする
dp[0][0] = 0;
// N個の品物の数ループ
rep(i, n) {
// 価値が 0->10^3*100 になるまで 1+v 回ループ
rep(limit, 1 + MAX_VALUE) {
// 選ばない場合
chmin(dp[i + 1][limit], dp[i][limit]);
// 選びたい
if (limit - value[i] >= 0) {
// 選んだ
chmin(dp[i + 1][limit], weight[i] + dp[i][limit - value[i]]);
}
}
}
// 10^3*100 の1次配列中から dp[i][sum_v]<w を満たす sum_v を見つける
ll res;
rep(i, MAX_VALUE) {
if (dp[n][i] <= w)
res = i;
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define var auto
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1LL << 60;
const int MAX_ITEM = 110;
const int MAX_VALUE = 100100;
ll dp[MAX_ITEM][MAX_VALUE]; // 重さ
int main() {
int n;
ll w;
cin >> n >> w;
ll weight[n];
ll value[n];
rep(i, n) { cin >> weight[i] >> value[i]; }
// 最小化問題なのでINF埋め
rep(i, MAX_ITEM) { rep(j, MAX_VALUE) dp[i][j] = INF; }
// 初期値00だけ0にする
dp[0][0] = 0;
// N個の品物の数ループ
rep(i, n) {
// 価値が 0->10^3*100 になるまで 1+v 回ループ
rep(limit, 1 + MAX_VALUE) {
// 選ばない場合
chmin(dp[i + 1][limit], dp[i][limit]);
// 選びたい
if (limit - value[i] >= 0) {
// 選んだ
chmin(dp[i + 1][limit], weight[i] + dp[i][limit - value[i]]);
}
}
}
// 10^3*100 の1次配列中から dp[i][sum_v]<w を満たす sum_v を見つける
ll res;
rep(i, MAX_VALUE) {
if (dp[n][i] <= w)
res = i;
}
cout << res << endl;
}
|
replace
| 21 | 23 | 21 | 23 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i, a, b) for (int i = a; i <= b; i++)
#define g(i, a, b) for (int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout << "Case #" << x << ": "
using namespace std;
ll mod = 1000000007;
ll INF = 1000000000000000000;
ll n, k;
ll a[101];
ll v[101];
ll w[101];
ll dp[101][100001];
ll lim;
ll foo(ll idx, ll val) {
if (idx == n) {
if (val >= lim)
return 0;
return INF;
}
if (dp[idx][val] != -1)
return dp[idx][val];
ll res = 0;
ll v1 = w[idx] + foo(idx + 1, val + v[idx]);
ll v2 = foo(idx + 1, val);
res = min(v1, v2);
return dp[idx][val] = res;
}
void solve(int t) {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
ll s = 0;
for (int i = 0; i < n; i++)
s += v[i];
ll lo = 0;
ll hi = s;
ll ans;
ll mid;
// lim = 140;
// cout << foo(0, 0) << endl;
while (lo <= hi) {
mid = (lo + hi) / 2;
lim = mid;
memset(dp, -1, sizeof(dp));
if (foo(0, 0) <= k) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}
|
#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i, a, b) for (int i = a; i <= b; i++)
#define g(i, a, b) for (int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout << "Case #" << x << ": "
using namespace std;
ll mod = 1000000007;
ll INF = 1000000000000000000;
ll n, k;
ll a[101];
ll v[101];
ll w[101];
ll dp[101][100001];
ll lim;
ll foo(ll idx, ll val) {
if (idx == n) {
if (val >= lim)
return 0;
return INF;
}
if (dp[idx][val] != -1)
return dp[idx][val];
ll res = 0;
ll v1 = w[idx] + foo(idx + 1, val + v[idx]);
ll v2 = foo(idx + 1, val);
res = min(v1, v2);
return dp[idx][val] = res;
}
void solve(int t) {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
ll s = 0;
for (int i = 0; i < n; i++)
s += v[i];
ll lo = 0;
ll hi = s;
ll ans;
ll mid;
// lim = 140;
// cout << foo(0, 0) << endl;
while (lo <= hi) {
mid = (lo + hi) / 2;
lim = mid;
memset(dp, -1, sizeof(dp));
if (foo(0, 0) <= k) {
ans = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}
|
delete
| 79 | 83 | 79 | 79 |
0
| |
p03164
|
Python
|
Runtime Error
|
n, w = map(int, input().split())
item = [list(map(int, input().split())) for i in range(n)]
max_v = 100005
dp = [[float("inf") * max_v] for j in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for sum_v in range(max_v):
if sum_v - item[i][1] >= 0:
dp[i + 1][sum_v] = min(
dp[i + 1][sum_v], dp[i][sum_v - item[i][1]] + item[i][0]
)
dp[i + 1][sum_v] = min((dp[i + 1][sum_v], dp[i][sum_v]))
for sum_v in reversed(range(max_v)):
if dp[-1][sum_v] <= w:
print(sum_v)
break
|
n, w = map(int, input().split())
item = [list(map(int, input().split())) for i in range(n)]
max_v = 100005
dp = [[float("inf")] * max_v for j in range(n + 1)]
dp[0][0] = 0
for i in range(n):
for sum_v in range(max_v):
if sum_v - item[i][1] >= 0:
dp[i + 1][sum_v] = min(
dp[i + 1][sum_v], dp[i][sum_v - item[i][1]] + item[i][0]
)
dp[i + 1][sum_v] = min((dp[i + 1][sum_v], dp[i][sum_v]))
for sum_v in reversed(range(max_v)):
if dp[-1][sum_v] <= w:
print(sum_v)
break
|
replace
| 5 | 6 | 5 | 6 |
IndexError: list index out of range
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03164/Python/s800712672.py", line 13, in <module>
dp[i + 1][sum_v] = min((dp[i + 1][sum_v], dp[i][sum_v]))
IndexError: list index out of range
|
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
// DEEP
using namespace std;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define fwd(i, a, n) for (int i = a; i < n; i++)
#define bak(i, a, n) for (int i = a; i >= n; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll modl = 998244353;
const double pie = 3.1415926535;
// power
ull power(ull x, ull y) {
if (y == 0)
return 1;
else {
if (y % 2 == 0)
return power(x * x, y / 2);
else
return x * power(x * x, (y - 1) / 2);
}
}
// Modular Exponentiation
ll mod_power(ll x, ll y, ll m) {
ll r = 1; // Initialize result
x = x % m; // Update x if it is more than or equal to m
if (x == 0)
return 0; // In case x is divisible by m;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
r = (r * x) % m;
// y must be even now
y = y / 2;
x = (x * x) % m;
}
return r;
}
// GCD
ll gcd(ll x, ll y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
// EXTENDED_EUCLID
vector<ll> extended_Euclid(ll a, ll b) {
vector<ll> v(3);
if (b == 0) {
v[0] = a;
v[1] = 1;
v[2] = 0;
return v;
} else {
vector<ll> v1 = extended_Euclid(b, a % b); // recursive call
v[0] = v1[0];
v[1] = v1[2];
v[2] = v1[1] - (a / b) * v1[2];
return v;
}
}
// DFS ( number of connected components )
// vector<vector<ll> >adj(200001);
// bool visited[200001];
/*ll dfs(int x,int c){ // x - > node c - > number
of edges in the component if(visited[x])return c; else{ visited[x]=true; int
y=c; for(int i=0;i<adj[x].size();i++){ if(!visited[adj[x][i]]){ c+=1; int
d=dfs(adj[x][i],y); c+=d;
}
}
return c;
}
}
*/
// SIEVE
/*
bool isPrime[100001];
void sieve(int N) {
for(int i = 0; i <= N;++i) {
isPrime[i]=true;
}
isPrime[0]=false;
isPrime[1]=false;
for(int i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) {
for(int j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
}
*/
// Binary Search
/*
ll bin_search(ll y){
while(lo<hi){
x=lo+(hi-lo)/2;
if(condition){
.....
}
else{
// increase lo or decrease hi suitably
}
}
}
*/
void max_self(ll &a, ll b) { a = max(a, b); }
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
boost;
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, w;
cin >> n >> w;
ll weight[n];
ll value[n];
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
ll sum_value = 0;
for (int x : value)
sum_value += x;
vector<ll> dp(sum_value + 1, 1e9 + 5);
dp[0] = 0;
for (int i = 0; i <= n; i++) {
for (int value_already = sum_value - value[i]; value_already >= 0;
--value_already) {
min_self(dp[value_already + value[i]], dp[value_already] + weight[i]);
}
}
ll ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
ans = max(ans, ll(i));
}
}
cout << ans << endl;
}
}
|
#include <bits/stdc++.h>
// DEEP
using namespace std;
#define boost \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define fwd(i, a, n) for (int i = a; i < n; i++)
#define bak(i, a, n) for (int i = a; i >= n; i--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define endl '\n'
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll modl = 998244353;
const double pie = 3.1415926535;
// power
ull power(ull x, ull y) {
if (y == 0)
return 1;
else {
if (y % 2 == 0)
return power(x * x, y / 2);
else
return x * power(x * x, (y - 1) / 2);
}
}
// Modular Exponentiation
ll mod_power(ll x, ll y, ll m) {
ll r = 1; // Initialize result
x = x % m; // Update x if it is more than or equal to m
if (x == 0)
return 0; // In case x is divisible by m;
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
r = (r * x) % m;
// y must be even now
y = y / 2;
x = (x * x) % m;
}
return r;
}
// GCD
ll gcd(ll x, ll y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
// EXTENDED_EUCLID
vector<ll> extended_Euclid(ll a, ll b) {
vector<ll> v(3);
if (b == 0) {
v[0] = a;
v[1] = 1;
v[2] = 0;
return v;
} else {
vector<ll> v1 = extended_Euclid(b, a % b); // recursive call
v[0] = v1[0];
v[1] = v1[2];
v[2] = v1[1] - (a / b) * v1[2];
return v;
}
}
// DFS ( number of connected components )
// vector<vector<ll> >adj(200001);
// bool visited[200001];
/*ll dfs(int x,int c){ // x - > node c - > number
of edges in the component if(visited[x])return c; else{ visited[x]=true; int
y=c; for(int i=0;i<adj[x].size();i++){ if(!visited[adj[x][i]]){ c+=1; int
d=dfs(adj[x][i],y); c+=d;
}
}
return c;
}
}
*/
// SIEVE
/*
bool isPrime[100001];
void sieve(int N) {
for(int i = 0; i <= N;++i) {
isPrime[i]=true;
}
isPrime[0]=false;
isPrime[1]=false;
for(int i = 2; i * i <= N; ++i) {
if(isPrime[i] == true) {
for(int j = i * i; j <= N ;j += i)
isPrime[j] = false;
}
}
}
*/
// Binary Search
/*
ll bin_search(ll y){
while(lo<hi){
x=lo+(hi-lo)/2;
if(condition){
.....
}
else{
// increase lo or decrease hi suitably
}
}
}
*/
void max_self(ll &a, ll b) { a = max(a, b); }
void min_self(ll &a, ll b) { a = min(a, b); }
int main() {
boost;
int TESTS = 1;
// cin>>TESTS;
while (TESTS--) {
int n, w;
cin >> n >> w;
ll weight[n];
ll value[n];
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
ll sum_value = 0;
for (int x : value)
sum_value += x;
vector<ll> dp(sum_value + 1, 1e9 + 5);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int value_already = sum_value - value[i]; value_already >= 0;
--value_already) {
min_self(dp[value_already + value[i]], dp[value_already] + weight[i]);
}
}
ll ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= w) {
ans = max(ans, ll(i));
}
}
cout << ans << endl;
}
}
|
replace
| 148 | 149 | 148 | 149 |
-11
| |
p03164
|
Python
|
Runtime Error
|
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
v_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [inf for _ in range(v_sum + 1)]
dp[0] = 0
for i in range(N):
for j in range(v_sum, -1, -1):
if dp[j] >= dp[j - items[i][1] + items[i][0]]:
dp[j] = dp[j - items[i][1]] + items[i][0]
for i in range(v_sum, -1, -1):
if dp[i] <= W:
print(i)
exit()
|
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]
v_sum = sum([item[1] for item in items])
inf = float("inf")
dp = [inf for _ in range(v_sum + 1)]
dp[0] = 0
for i in range(N):
for j in range(v_sum, -1, -1):
if dp[j] > dp[j - items[i][1]] + items[i][0]:
dp[j] = dp[j - items[i][1]] + items[i][0]
for i in range(v_sum, -1, -1):
if dp[i] <= W:
print(i)
exit()
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long int
#define F(i, j, k, in) for (int i = j; i < k; i += in)
#define DF(i, j, k, in) for (int i = j; i >= k; i -= in)
#define feach(it, l) for (auto it = l.begin(); it != l.end(); ++it)
#define fitr(it, it1, itr2) for (auto it = itr1; it != itr2; ++it)
#define fall(a) a.begin(), a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int, int>> vvin;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<int, int>> vpin;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef queue<int> qin;
typedef priority_queue<int> pqin;
typedef map<ll, ll> mpll;
typedef map<int, int> mpin;
typedef pair<ll, ll> pll;
typedef pair<int, int> pin;
const ll MOD = 1000000007;
const long double PI = 3.1415926535897932384626433832795;
ll pwr(ll b, ll p) {
ll res = 1;
while (p) {
if (p & 1) {
res *= b;
p--;
} else {
b *= b;
p >>= 1;
}
}
return res;
}
const int maxn = 1e3 + 1, maxn1 = 101;
ll dp[maxn][maxn1];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
ll n, w;
cin >> n >> w;
vpll A(n + 1);
F(i, 1, n + 1, 1) {
ll a, b;
cin >> a >> b;
A[i] = mkp(a, b);
}
ll sum = 0;
F(i, 1, n + 1, 1) sum += A[i].ss;
F(i, 0, n + 1, 1) dp[0][i] = 0;
F(i, 1, sum + 1, 1) dp[i][0] = INT_MAX;
F(i, 1, n + 1, 1) {
F(j, 1, sum + 1, 1) {
dp[j][i] = dp[j][i - 1];
if (j >= A[i].ss) {
if (dp[j - A[i].ss][i - 1] <= w)
dp[j][i] = min(dp[j][i], dp[j - A[i].ss][i - 1] + A[i].fs);
}
}
}
ll ans;
F(i, 1, sum + 1, 1) {
if (dp[i][n] <= w)
ans = i;
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long int
#define F(i, j, k, in) for (int i = j; i < k; i += in)
#define DF(i, j, k, in) for (int i = j; i >= k; i -= in)
#define feach(it, l) for (auto it = l.begin(); it != l.end(); ++it)
#define fitr(it, it1, itr2) for (auto it = itr1; it != itr2; ++it)
#define fall(a) a.begin(), a.end()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int, int>> vvin;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<int, int>> vpin;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef queue<int> qin;
typedef priority_queue<int> pqin;
typedef map<ll, ll> mpll;
typedef map<int, int> mpin;
typedef pair<ll, ll> pll;
typedef pair<int, int> pin;
const ll MOD = 1000000007;
const long double PI = 3.1415926535897932384626433832795;
ll pwr(ll b, ll p) {
ll res = 1;
while (p) {
if (p & 1) {
res *= b;
p--;
} else {
b *= b;
p >>= 1;
}
}
return res;
}
const int maxn = 1e5 + 1, maxn1 = 101;
ll dp[maxn][maxn1];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
ll n, w;
cin >> n >> w;
vpll A(n + 1);
F(i, 1, n + 1, 1) {
ll a, b;
cin >> a >> b;
A[i] = mkp(a, b);
}
ll sum = 0;
F(i, 1, n + 1, 1) sum += A[i].ss;
F(i, 0, n + 1, 1) dp[0][i] = 0;
F(i, 1, sum + 1, 1) dp[i][0] = INT_MAX;
F(i, 1, n + 1, 1) {
F(j, 1, sum + 1, 1) {
dp[j][i] = dp[j][i - 1];
if (j >= A[i].ss) {
if (dp[j - A[i].ss][i - 1] <= w)
dp[j][i] = min(dp[j][i], dp[j - A[i].ss][i - 1] + A[i].fs);
}
}
}
ll ans;
F(i, 1, sum + 1, 1) {
if (dp[i][n] <= w)
ans = i;
}
cout << ans;
return 0;
}
|
replace
| 52 | 53 | 52 | 53 |
0
| |
p03164
|
Python
|
Time Limit Exceeded
|
N, W = map(int, input().split())
items = [None] * N
for n in range(N):
w, v = map(int, input().split())
items[n] = (w, v)
V = 10**6 + 1
dp = [[10**9 + 1] * V for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(V):
w, v = items[i]
if j >= v:
dp[i + 1][j] = min(dp[i][j - v] + w, dp[i][j])
else:
dp[i + 1][j] = dp[i][j]
ans = 0
for v in range(V):
if dp[N][v] <= W:
ans = v
print(ans)
|
N, W = map(int, input().split())
items = [None] * N
for n in range(N):
w, v = map(int, input().split())
items[n] = (w, v)
V = 10**5 + 1
dp = [[10**9 + 1] * V for _ in range(N + 1)]
dp[0][0] = 0
for i in range(N):
for j in range(V):
w, v = items[i]
if j >= v:
dp[i + 1][j] = min(dp[i][j - v] + w, dp[i][j])
else:
dp[i + 1][j] = dp[i][j]
ans = 0
for v in range(V):
if dp[N][v] <= W:
ans = v
print(ans)
|
replace
| 5 | 6 | 5 | 6 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define in(x) cin >> x
#define out(x) cout << x << endl
#define out2(x, y) cout << x << " " << y << endl;
#define MOD 1000000007
#define PI acos(-1)
#define pb push_back
#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define pllll pair<ll, ll>
#define plls pair<ll, string>
#define psll pair<string, ll>
#define For(i, n) for (int i = 0; i < n; i++)
#define phoge out("hoge")
#define phugo out("hugo")
#define vll vector<ll>
#define v2ll vec2<ll>
#define v3ll vec3<ll>
template <typename T> using vec = vector<T>;
template <typename T> using vec2 = vector<vector<T>>;
template <typename T> using vec3 = vector<vector<vector<ll>>>;
template <typename T> using uset = unordered_set<T>;
template <typename T, typename S> using umap = unordered_map<T, S>;
bool inRange(ll a, ll x, ll b) {
if (a > b) {
swap(a, b);
}
return (a <= x && x <= b);
}
bool between(ll a, ll x, ll b) {
if (a > b) {
swap(a, b);
}
return (a < x && x < b);
}
template <typename T> void sort(T &a, T &b) {
if (a > b) {
swap(a, b);
}
}
template <typename T> void input(T *data, int n) {
For(i, n) { cin >> data[i]; }
}
template <typename T, typename S> void input(T *data1, S *data2, int n) {
For(i, n) { cin >> data1[i] >> data2[i]; }
}
template <typename T> void input(vector<T> &vec, int n) {
T temp;
For(i, n) {
cin >> temp;
vec.push_back(temp);
}
}
template <typename T, typename S>
void input(vector<T> &vec1, vector<S> &vec2, int n) {
T temp1;
S temp2;
For(i, n) {
cin >> temp1 >> temp2;
vec1.push_back(temp1);
vec2.push_back(temp2);
}
}
template <typename T> void sort(vector<T> &ary) {
sort(ary.begin(), ary.end());
}
template <typename T> void rsort(vector<T> &ary) {
sort(ary.rbegin(), ary.rend());
}
void rstring(string &str) {
string temp = str;
For(i, (int)str.size()) { str[i] = temp[(str.size() - 1) - i]; }
}
template <typename T> void print(T *x, int n) {
For(i, n) { cout << x[i] << " "; }
cout << endl;
}
template <typename T> void print(T &x) {
for (auto t : x) {
cout << t << " ";
}
cout << endl;
}
template <typename T, typename S> void print(pair<T, S> &p) {
out2(p.first, p.second);
}
template <typename T> T gcd(T n, T m) {
if (n % m == 0) {
return m;
} else {
return gcd<T>(m, n % m);
}
}
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
UnionFind() {}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size() {
int count = 0;
for (int i = 0; i < (int)par.size(); i++) {
if (par[i] == i) {
count++;
}
}
return count;
}
};
template <typename T, typename S> struct _CountMap {
T data;
void add(S key, int n) {
auto itr = data.find(key);
if (itr == data.end()) {
data.insert(pair<S, int>(key, n));
} else {
itr->second += n;
}
}
auto top() { return data.begin(); }
int val(S key) { return data[key]; }
int size() { return data.size(); }
int sub(S key, int n) {
auto elm = data.find(key);
int ret = min(elm->second, n);
if (ret == elm->second) {
data.erase(elm);
}
elm->second -= ret;
return ret;
}
int &operator[](S key) {
auto itr = data.find(key);
if (itr == data.end()) {
data.insert(pair<S, int>(key, 0));
}
return itr->second;
}
};
struct Area {
vector<ll> data;
Area(ll range) : data(range + 1) {}
void add(pair<ll, ll> newdata) {
data[newdata.first]++;
data[newdata.second]--;
}
ll num() {
ll sum = 0;
ll ret = 0;
For(i, (int)data.size()) {
sum += data[i];
if (sum != 0) {
ret++;
for (i++; i < (int)data.size() && (sum += data[i]) != 0; i++)
;
}
}
return ret;
}
};
struct Interval {
vector<pllll> data;
void add(ll s, ll f) { data.push_back(pllll(f, s)); }
ll num() {
sort(data);
ll ret = 0;
ll lastf = -1;
for (auto t : data) {
if (t.first == lastf) {
continue;
}
if (t.second >= lastf) {
lastf = t.first;
ret++;
}
}
return ret;
}
};
template <typename T> using CountMap = _CountMap<map<T, int>, T>;
template <typename T>
using CountMapr = _CountMap<multimap<T, int, greater<T>>, T>;
void factoring(ll n, CountMap<ll> &p) {
for (ll i = 2; i + i <= n; i++) {
while (n % i == 0) {
p.add(i, 1);
n /= i;
}
}
}
template <typename T, typename S> using rmap = multimap<T, S, greater<T>>;
template <typename T> using rset = multiset<T, greater<T>>;
vector<ll> fac(2001); // n!(mod M)
vector<ll> ifac(2001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分
ll mpow(ll x,
ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため,随時mod計算
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % 1000000007;
x = x * x % 1000000007;
n = n >> 1;
}
return ans;
}
ll comb(ll a, ll b) { // aCbをmod計算
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
ll tmp = ifac[a - b] * ifac[b] % 1000000007;
return tmp * fac[a] % 1000000007;
}
int main() {
ll n, m, k, a, b, c, x, y, z, h, w, sum = 0;
string s;
cin >> n >> w;
vll W(n + 1), V(n + 1);
For(i, n) { cin >> W[i + 1] >> V[i + 1]; }
v2ll dp(n + 1, vll(100001, 1e15));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
For(j, 100001) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j + V[i]] = min(dp[i][j + V[i]], dp[i - 1][j] + W[i]);
}
}
ll ans = 0;
For(i, 100001) {
if (dp[n][i] <= w) {
ans = i;
}
}
out(ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define in(x) cin >> x
#define out(x) cout << x << endl
#define out2(x, y) cout << x << " " << y << endl;
#define MOD 1000000007
#define PI acos(-1)
#define pb push_back
#define Yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define No cout << "No" << endl
#define NO cout << "NO" << endl
#define pllll pair<ll, ll>
#define plls pair<ll, string>
#define psll pair<string, ll>
#define For(i, n) for (int i = 0; i < n; i++)
#define phoge out("hoge")
#define phugo out("hugo")
#define vll vector<ll>
#define v2ll vec2<ll>
#define v3ll vec3<ll>
template <typename T> using vec = vector<T>;
template <typename T> using vec2 = vector<vector<T>>;
template <typename T> using vec3 = vector<vector<vector<ll>>>;
template <typename T> using uset = unordered_set<T>;
template <typename T, typename S> using umap = unordered_map<T, S>;
bool inRange(ll a, ll x, ll b) {
if (a > b) {
swap(a, b);
}
return (a <= x && x <= b);
}
bool between(ll a, ll x, ll b) {
if (a > b) {
swap(a, b);
}
return (a < x && x < b);
}
template <typename T> void sort(T &a, T &b) {
if (a > b) {
swap(a, b);
}
}
template <typename T> void input(T *data, int n) {
For(i, n) { cin >> data[i]; }
}
template <typename T, typename S> void input(T *data1, S *data2, int n) {
For(i, n) { cin >> data1[i] >> data2[i]; }
}
template <typename T> void input(vector<T> &vec, int n) {
T temp;
For(i, n) {
cin >> temp;
vec.push_back(temp);
}
}
template <typename T, typename S>
void input(vector<T> &vec1, vector<S> &vec2, int n) {
T temp1;
S temp2;
For(i, n) {
cin >> temp1 >> temp2;
vec1.push_back(temp1);
vec2.push_back(temp2);
}
}
template <typename T> void sort(vector<T> &ary) {
sort(ary.begin(), ary.end());
}
template <typename T> void rsort(vector<T> &ary) {
sort(ary.rbegin(), ary.rend());
}
void rstring(string &str) {
string temp = str;
For(i, (int)str.size()) { str[i] = temp[(str.size() - 1) - i]; }
}
template <typename T> void print(T *x, int n) {
For(i, n) { cout << x[i] << " "; }
cout << endl;
}
template <typename T> void print(T &x) {
for (auto t : x) {
cout << t << " ";
}
cout << endl;
}
template <typename T, typename S> void print(pair<T, S> &p) {
out2(p.first, p.second);
}
template <typename T> T gcd(T n, T m) {
if (n % m == 0) {
return m;
} else {
return gcd<T>(m, n % m);
}
}
struct UnionFind {
vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(int N) : par(N) { // 最初は全てが根であるとして初期化
for (int i = 0; i < N; i++)
par[i] = i;
}
UnionFind() {}
int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根}
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) { // xとyの木を併合
int rx = root(x); // xの根をrx
int ry = root(y); // yの根をry
if (rx == ry)
return; // xとyの根が同じ(=同じ木にある)時はそのまま
par[rx] =
ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける
}
bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int size() {
int count = 0;
for (int i = 0; i < (int)par.size(); i++) {
if (par[i] == i) {
count++;
}
}
return count;
}
};
template <typename T, typename S> struct _CountMap {
T data;
void add(S key, int n) {
auto itr = data.find(key);
if (itr == data.end()) {
data.insert(pair<S, int>(key, n));
} else {
itr->second += n;
}
}
auto top() { return data.begin(); }
int val(S key) { return data[key]; }
int size() { return data.size(); }
int sub(S key, int n) {
auto elm = data.find(key);
int ret = min(elm->second, n);
if (ret == elm->second) {
data.erase(elm);
}
elm->second -= ret;
return ret;
}
int &operator[](S key) {
auto itr = data.find(key);
if (itr == data.end()) {
data.insert(pair<S, int>(key, 0));
}
return itr->second;
}
};
struct Area {
vector<ll> data;
Area(ll range) : data(range + 1) {}
void add(pair<ll, ll> newdata) {
data[newdata.first]++;
data[newdata.second]--;
}
ll num() {
ll sum = 0;
ll ret = 0;
For(i, (int)data.size()) {
sum += data[i];
if (sum != 0) {
ret++;
for (i++; i < (int)data.size() && (sum += data[i]) != 0; i++)
;
}
}
return ret;
}
};
struct Interval {
vector<pllll> data;
void add(ll s, ll f) { data.push_back(pllll(f, s)); }
ll num() {
sort(data);
ll ret = 0;
ll lastf = -1;
for (auto t : data) {
if (t.first == lastf) {
continue;
}
if (t.second >= lastf) {
lastf = t.first;
ret++;
}
}
return ret;
}
};
template <typename T> using CountMap = _CountMap<map<T, int>, T>;
template <typename T>
using CountMapr = _CountMap<multimap<T, int, greater<T>>, T>;
void factoring(ll n, CountMap<ll> &p) {
for (ll i = 2; i + i <= n; i++) {
while (n % i == 0) {
p.add(i, 1);
n /= i;
}
}
}
template <typename T, typename S> using rmap = multimap<T, S, greater<T>>;
template <typename T> using rset = multiset<T, greater<T>>;
vector<ll> fac(2001); // n!(mod M)
vector<ll> ifac(2001); // k!^{M-2} (mod M)
// a,bの範囲的にこれだけ配列を用意していけば十分
ll mpow(ll x,
ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため,随時mod計算
ll ans = 1;
while (n != 0) {
if (n & 1)
ans = ans * x % 1000000007;
x = x * x % 1000000007;
n = n >> 1;
}
return ans;
}
ll comb(ll a, ll b) { // aCbをmod計算
if (a == 0 && b == 0)
return 1;
if (a < b || a < 0)
return 0;
ll tmp = ifac[a - b] * ifac[b] % 1000000007;
return tmp * fac[a] % 1000000007;
}
int main() {
ll n, m, k, a, b, c, x, y, z, h, w, sum = 0;
string s;
cin >> n >> w;
vll W(n + 1), V(n + 1);
For(i, n) { cin >> W[i + 1] >> V[i + 1]; }
v2ll dp(n + 1, vll(100001, 1e15));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
For(j, 100001) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j + V[i] <= 100001)
dp[i][j + V[i]] = min(dp[i][j + V[i]], dp[i - 1][j] + W[i]);
}
}
ll ans = 0;
For(i, 100001) {
if (dp[n][i] <= w) {
ans = i;
}
}
out(ans);
return 0;
}
|
replace
| 328 | 329 | 328 | 330 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, W;
cin >> N >> W;
vector<ll> v(N);
vector<ll> w(N);
ll sum = 0;
rep(i, N) {
cin >> w[i] >> v[i];
sum += v[i];
}
vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, INF));
dp[0][0] = 0;
rep(i, N) {
rep(j, sum + 1) {
if (dp[i][j - v[i]] >= 0)
dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
ll ans = 0;
rep(j, sum + 1) {
if (dp[N][j] <= W)
ans = max(ans, j);
}
cout << ans << endl;
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
typedef pair<int, int> P;
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9 + 7;
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, W;
cin >> N >> W;
vector<ll> v(N);
vector<ll> w(N);
ll sum = 0;
rep(i, N) {
cin >> w[i] >> v[i];
sum += v[i];
}
vector<vector<ll>> dp(N + 1, vector<ll>(sum + 1, INF));
dp[0][0] = 0;
rep(i, N) {
rep(j, sum + 1) {
if (j - v[i] >= 0)
dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]);
else
dp[i + 1][j] = dp[i][j];
}
}
ll ans = 0;
rep(j, sum + 1) {
if (dp[N][j] <= W)
ans = max(ans, j);
}
cout << ans << endl;
cout << endl;
return 0;
}
|
replace
| 32 | 33 | 32 | 33 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
int32_t main() {
int n, w;
cin >> n >> w;
vector<int> wt(n), val(n);
int sum_val = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
sum_val += val[i];
}
vector<int> dp(sum_val + 1, INT_MAX);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = sum_val; j >= 0; j--) {
if (wt[i] + dp[j - val[i]] <= w)
dp[j] = min(dp[j], wt[i] + dp[j - val[i]]);
}
}
int ans = -1;
for (int i = 1; i <= sum_val; i++) {
if (dp[i] > 0 && dp[i] <= w)
ans = max(ans, i);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
int32_t main() {
int n, w;
cin >> n >> w;
vector<int> wt(n), val(n);
int sum_val = 0;
for (int i = 0; i < n; i++) {
cin >> wt[i] >> val[i];
sum_val += val[i];
}
vector<int> dp(sum_val + 1, INT_MAX);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j = sum_val; j >= val[i]; j--) {
if (wt[i] + dp[j - val[i]] <= w)
dp[j] = min(dp[j], wt[i] + dp[j - val[i]]);
}
}
int ans = -1;
for (int i = 1; i <= sum_val; i++) {
if (dp[i] > 0 && dp[i] <= w)
ans = max(ans, i);
}
cout << ans << endl;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p03164
|
C++
|
Runtime Error
|
/*
Author - linpaws07
*/
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define f first
#define s second
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define memst(a, b) memset(a, (b), sizeof(a))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rp(i, n) for (int i = 0; i < (n); i++)
#define fr(i, a, b) for (int i = (a); i < (b); i++)
#define fre(i, a, b) for (int i = (a); i <= (b); i++)
#define frd(i, a, b) for (int i = (a); i >= (b); i--)
inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
auto start = high_resolution_clock::now();
inline void measure();
int64 w[102], v[102], n;
int64 dp[100][100002];
int64 solve(int i, int va) {
if (va == 0)
return 0;
if (i < 1)
return inf;
if (dp[i][va] != -1)
return dp[i][va];
int64 ans = inf;
if (va >= v[i]) {
ans = w[i] + solve(i - 1, va - v[i]);
}
ans = min(ans, solve(i - 1, va));
dp[i][va] = ans;
return ans;
}
int main() {
FAST
// Do awesome things here
int64 wt,
sum = 0, ans = 0;
cin >> n >> wt;
memst(dp, -1);
fre(i, 1, n) {
cin >> w[i] >> v[i];
sum += v[i];
}
fre(i, 0, sum) {
int64 awt = solve(n, i);
if (awt <= wt)
ans = i;
}
cout << ans << endl;
return 0;
}
inline void measure() {
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
cout << duration.count() << endl;
}
|
/*
Author - linpaws07
*/
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define f first
#define s second
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define scd(t) scanf("%d", &t)
#define sclld(t) scanf("%lld", &t)
#define scc(t) scanf("%c", &t)
#define scs(t) scanf("%s", t)
#define scf(t) scanf("%f", &t)
#define sclf(t) scanf("%lf", &t)
#define memst(a, b) memset(a, (b), sizeof(a))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define FAST \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rp(i, n) for (int i = 0; i < (n); i++)
#define fr(i, a, b) for (int i = (a); i < (b); i++)
#define fre(i, a, b) for (int i = (a); i <= (b); i++)
#define frd(i, a, b) for (int i = (a); i >= (b); i--)
inline bool eq(double a, double b) { return fabs(a - b) < 1e-9; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res)
n -= n & (-n);
return res;
}
auto start = high_resolution_clock::now();
inline void measure();
int64 w[102], v[102], n;
int64 dp[102][100002];
int64 solve(int i, int va) {
if (va == 0)
return 0;
if (i < 1)
return inf;
if (dp[i][va] != -1)
return dp[i][va];
int64 ans = inf;
if (va >= v[i]) {
ans = w[i] + solve(i - 1, va - v[i]);
}
ans = min(ans, solve(i - 1, va));
dp[i][va] = ans;
return ans;
}
int main() {
FAST
// Do awesome things here
int64 wt,
sum = 0, ans = 0;
cin >> n >> wt;
memst(dp, -1);
fre(i, 1, n) {
cin >> w[i] >> v[i];
sum += v[i];
}
fre(i, 0, sum) {
int64 awt = solve(n, i);
if (awt <= wt)
ans = i;
}
cout << ans << endl;
return 0;
}
inline void measure() {
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
cout << duration.count() << endl;
}
|
replace
| 58 | 59 | 58 | 59 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 1;
int main() {
int N, W;
cin >> N >> W;
vector<ll> value(N), weight(N);
for (int i = 0; i < N; i++) {
cin >> weight[i] >> value[i];
}
vector<vector<ll>> dp(N + 1, vector<ll>(N * 1001, INF));
dp[0][0] = 0;
for (int n = 0; n < N; n++) {
for (ll v = 0; v <= N * 1010; v++) {
if (v >= value[n]) {
dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]);
} else {
dp[n + 1][v] = dp[n][v];
}
}
}
ll best_score = 0;
for (ll j = 0; j <= N * 1010; j++) {
if (dp[N][j] <= W) {
// cout<<dp[N][j]<<" ";
best_score = max(best_score, j);
}
}
cout << best_score << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 1;
int main() {
int N, W;
cin >> N >> W;
vector<ll> value(N), weight(N);
for (int i = 0; i < N; i++) {
cin >> weight[i] >> value[i];
}
vector<vector<ll>> dp(N + 1, vector<ll>(N * 1010 + 1, INF));
dp[0][0] = 0;
for (int n = 0; n < N; n++) {
for (ll v = 0; v <= N * 1010; v++) {
if (v >= value[n]) {
dp[n + 1][v] = min(dp[n][v - value[n]] + weight[n], dp[n][v]);
} else {
dp[n + 1][v] = dp[n][v];
}
}
}
ll best_score = 0;
for (ll j = 0; j <= N * 1010; j++) {
if (dp[N][j] <= W) {
// cout<<dp[N][j]<<" ";
best_score = max(best_score, j);
}
}
cout << best_score << endl;
return 0;
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ll n, limit;
cin >> n >> limit;
vector<pair<ll, ll>> luggage(n);
ll quota_max = 0;
for (int i = 0; i < n; ++i) {
cin >> luggage[i].first >> luggage[i].second;
quota_max += luggage[i].second;
}
vector<vector<ll>> dp(110, vector<ll>(100100, 1001001001001001));
dp[0][0] = 0;
for (int i = 0; i <= n; ++i) {
ll new_w = luggage[i].first;
ll new_v = luggage[i].second;
for (int j = 0; j <= quota_max; ++j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
dp[i + 1][j + new_v] = min(dp[i + 1][j + new_v], dp[i][j] + new_w);
}
}
ll ans = 0;
for (ll k = 0; k <= quota_max; ++k)
if (dp[n][k] <= limit)
ans = max(ans, k);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ll n, limit;
cin >> n >> limit;
vector<pair<ll, ll>> luggage(n);
ll quota_max = 0;
for (int i = 0; i < n; ++i) {
cin >> luggage[i].first >> luggage[i].second;
quota_max += luggage[i].second;
}
vector<vector<ll>> dp(110, vector<ll>(300300, 1001001001001001));
dp[0][0] = 0;
for (int i = 0; i <= n; ++i) {
ll new_w = luggage[i].first;
ll new_v = luggage[i].second;
for (int j = 0; j <= quota_max; ++j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
dp[i + 1][j + new_v] = min(dp[i + 1][j + new_v], dp[i][j] + new_w);
}
}
ll ans = 0;
for (ll k = 0; k <= quota_max; ++k)
if (dp[n][k] <= limit)
ans = max(ans, k);
cout << ans << endl;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03164
|
C++
|
Runtime Error
|
// https://atcoder.jp/contests/dp/tasks/dp_e
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <limits.h>
using namespace std;
struct object {
int weight, value;
};
object arr[107];
long long dp[1007][107];
long long res(int value, int n) {
if (value <= 0)
return 0;
if (n == 0)
return INT_MAX;
if (dp[value][n])
return dp[value][n];
dp[value][n] = min(res(value - arr[n - 1].value, n - 1) + arr[n - 1].weight,
res(value, n - 1));
return dp[value][n];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w, sum = 0;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> arr[i].weight >> arr[i].value;
sum += arr[i].value;
}
for (int i = sum; i >= 0; i--) {
if (res(i, n) <= w) {
cout << i << endl;
break;
}
}
return 0;
}
|
// https://atcoder.jp/contests/dp/tasks/dp_e
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <limits.h>
using namespace std;
struct object {
int weight, value;
};
object arr[107];
long long dp[100007][107];
long long res(int value, int n) {
if (value <= 0)
return 0;
if (n == 0)
return INT_MAX;
if (dp[value][n])
return dp[value][n];
dp[value][n] = min(res(value - arr[n - 1].value, n - 1) + arr[n - 1].weight,
res(value, n - 1));
return dp[value][n];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, w, sum = 0;
cin >> n >> w;
for (int i = 0; i < n; i++) {
cin >> arr[i].weight >> arr[i].value;
sum += arr[i].value;
}
for (int i = sum; i >= 0; i--) {
if (res(i, n) <= w) {
cout << i << endl;
break;
}
}
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
long long inf = 1e18L + 5;
long long dp[100001];
int main() {
int n, w;
cin >> n >> w;
pair<long long, long long> arr[n + 1];
arr[0] = make_pair(0, 0);
int sum = 0;
for (int i = 1; i <= n; ++i) {
long long a, b;
cin >> a >> b;
sum += b;
arr[i] = make_pair(a, b);
}
for (int i = 0; i <= sum; ++i) {
dp[i] = inf;
}
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = sum; j >= 0; --j) {
dp[j] = min(dp[j], dp[j - arr[i].second] + arr[i].first);
}
}
for (int i = sum; i >= 0; --i) {
if (dp[i] <= w) {
cout << i << endl;
break;
}
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
long long inf = 1e18L + 5;
long long dp[100001];
int main() {
int n, w;
cin >> n >> w;
pair<long long, long long> arr[n + 1];
arr[0] = make_pair(0, 0);
int sum = 0;
for (int i = 1; i <= n; ++i) {
long long a, b;
cin >> a >> b;
sum += b;
arr[i] = make_pair(a, b);
}
for (int i = 0; i <= sum; ++i) {
dp[i] = inf;
}
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = sum; j >= 0; --j) {
if (j - arr[i].second >= 0) {
dp[j] = min(dp[j], dp[j - arr[i].second] + arr[i].first);
} else {
break;
}
}
}
for (int i = sum; i >= 0; --i) {
if (dp[i] <= w) {
cout << i << endl;
break;
}
}
return 0;
}
|
replace
| 26 | 27 | 26 | 31 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9 + 5;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, W;
cin >> n >> W;
vector<int> value(n);
vector<int> weight(n);
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
int sum_value = 0;
for (int i = 0; i < n; i++)
sum_value += value[i];
vector<int> dp(sum_value + 1, INF);
dp[0] = 0;
// dp[i] = the min total weight of items with total value exactly equal to i
for (int item = 0; item < n; item++) {
for (int value_already = sum_value - value[item]; value_already >= 0;
value_already--) {
dp[value_already + value[item]] = min(dp[value_already + value[item]],
dp[value_already] + weight[item]);
}
}
int ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= W) {
ans = max(ans, i);
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e9 + 5;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/
int n, W;
cin >> n >> W;
vector<int> value(n);
vector<int> weight(n);
for (int i = 0; i < n; i++)
cin >> weight[i] >> value[i];
int sum_value = 0;
for (int i = 0; i < n; i++)
sum_value += value[i];
vector<int> dp(sum_value + 1, INF);
dp[0] = 0;
// dp[i] = the min total weight of items with total value exactly equal to i
for (int item = 0; item < n; item++) {
for (int value_already = sum_value - value[item]; value_already >= 0;
value_already--) {
dp[value_already + value[item]] = min(dp[value_already + value[item]],
dp[value_already] + weight[item]);
}
}
int ans = 0;
for (int i = 0; i <= sum_value; i++) {
if (dp[i] <= W) {
ans = max(ans, i);
}
}
cout << ans;
}
|
replace
| 9 | 13 | 9 | 13 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 105, W = 1e9 + 5, V = 1e3 + 5, INF = 1e9 + 5;
ll dp[N][N * V];
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
int n, w;
cin >> n >> w;
fill(dp[0], dp[0] + N * V, INF);
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
int wi, vi;
cin >> wi >> vi;
for (int j = 0; j < wi; j++)
dp[i][j] = dp[i - 1][j];
for (int j = vi; j < N * V; j++)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - vi] + wi);
}
for (int i = N * V - 1; i >= 0; i--)
if (dp[n][i] <= w) {
cout << i << "\n";
return 0;
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 105, W = 1e9 + 5, V = 1e3 + 5, INF = 1e9 + 5;
ll dp[N][N * V];
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
int n, w;
cin >> n >> w;
fill(dp[0], dp[0] + N * V, INF);
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
int wi, vi;
cin >> wi >> vi;
for (int j = 0; j < vi; j++)
dp[i][j] = dp[i - 1][j];
for (int j = vi; j < N * V; j++)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - vi] + wi);
}
for (int i = N * V - 1; i >= 0; i--)
if (dp[n][i] <= w) {
cout << i << "\n";
return 0;
}
}
|
replace
| 20 | 21 | 20 | 21 |
0
| |
p03164
|
C++
|
Time Limit Exceeded
|
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const li inf = 1e14;
// 12
void _main(int tc) {
int n, W, sumV = 0;
cin >> n >> W;
vector<int> w(n), v(n);
rep(i, n) {
cin >> w[i] >> v[i];
sumV += v[i];
}
vector<vector<li>> mem(n, vector<li>(sumV + 1, -1));
function<li(int, int)> knapsack2 = [&](int i, int V) -> li {
if (V == 0)
return 0;
if (i == n && V != 0)
return inf;
if (mem[i][V] != -1)
return mem[i][V];
rep(Val, sumV + 1) {
if (V - v[i] >= 0)
mem[i][V] = min(w[i] + knapsack2(i + 1, V - v[i]), knapsack2(i + 1, V));
else
mem[i][V] = knapsack2(i + 1, V);
}
return mem[i][V];
};
rrep(i, sumV + 1) {
if (knapsack2(0, i) <= W) {
cout << i << endl;
break;
}
}
// vector<vector<li>> mem(n + 1, vector<li>(sumV + 1, inf));
// rep(i, n + 1) mem[i][0] = 0;
// rrep(i, n) {
// rrep(V, sumV + 1) {
// if (V - v[i] >= 0)
// mem[i][V] = min(w[i] + mem[i + 1][V - v[i]], mem[i + 1][V]);
// else
// mem[i][V] = mem[i + 1][V];
// }
// }
// rrep(i, sumV + 1) {
// if (mem[0][i] <= W) {
// cout << i << endl;
// break;
// }
// }
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
_main(0);
return 0;
int tc;
cin >> tc;
rep(i, tc) _main(i + 1);
}
|
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const li inf = 1e14;
// 12
void _main(int tc) {
int n, W, sumV = 0;
cin >> n >> W;
vector<int> w(n), v(n);
rep(i, n) {
cin >> w[i] >> v[i];
sumV += v[i];
}
vector<vector<li>> mem(n, vector<li>(sumV + 1, -1));
function<li(int, int)> knapsack2 = [&](int i, int V) -> li {
if (V == 0)
return 0;
if (i == n && V != 0)
return inf;
if (mem[i][V] != -1)
return mem[i][V];
if (V - v[i] >= 0)
mem[i][V] = min(w[i] + knapsack2(i + 1, V - v[i]), knapsack2(i + 1, V));
else
mem[i][V] = knapsack2(i + 1, V);
return mem[i][V];
};
rrep(i, sumV + 1) {
if (knapsack2(0, i) <= W) {
cout << i << endl;
break;
}
}
// vector<vector<li>> mem(n + 1, vector<li>(sumV + 1, inf));
// rep(i, n + 1) mem[i][0] = 0;
// rrep(i, n) {
// rrep(V, sumV + 1) {
// if (V - v[i] >= 0)
// mem[i][V] = min(w[i] + mem[i + 1][V - v[i]], mem[i + 1][V]);
// else
// mem[i][V] = mem[i + 1][V];
// }
// }
// rrep(i, sumV + 1) {
// if (mem[0][i] <= W) {
// cout << i << endl;
// break;
// }
// }
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
_main(0);
return 0;
int tc;
cin >> tc;
rep(i, tc) _main(i + 1);
}
|
replace
| 43 | 49 | 43 | 47 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int v[100], w[100];
int dp[100][100005];
int f(int i, int value) {
if (value == 0)
return 0;
if (i < 0)
return 1000000000;
if (dp[i][value] != -1)
return dp[i][value];
return dp[i][value] = min(f(i - 1, value), f(i - 1, value - v[i]) + w[i]);
}
signed main() {
int N, W;
cin >> N >> W;
int sum = 0;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
sum += v[i];
}
for (int i = 0; i < N; i++)
for (int j = 0; j <= sum; j++)
dp[i][j] = -1;
int ans = 0;
for (int val = 1; val <= sum; val++) {
if (f(N - 1, val) <= W) {
ans = val;
}
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int v[100], w[100];
int dp[100][100005];
int f(int i, int value) {
if (value < 0)
return 1000000000;
if (value == 0)
return 0;
if (i < 0)
return 1000000000;
if (dp[i][value] != -1)
return dp[i][value];
return dp[i][value] = min(f(i - 1, value), f(i - 1, value - v[i]) + w[i]);
}
signed main() {
int N, W;
cin >> N >> W;
int sum = 0;
for (int i = 0; i < N; i++) {
cin >> w[i] >> v[i];
sum += v[i];
}
for (int i = 0; i < N; i++)
for (int j = 0; j <= sum; j++)
dp[i][j] = -1;
int ans = 0;
for (int val = 1; val <= sum; val++) {
if (f(N - 1, val) <= W) {
ans = val;
}
}
cout << ans;
return 0;
}
|
insert
| 7 | 7 | 7 | 9 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
int main() {
ll N = 0;
cin >> N;
ll VAL = 0;
cin >> VAL;
ll V = 0;
vector<vector<ll>> inp(N, vector<ll>(2));
for (ll i = 0; i < N; i++) {
cin >> inp[i][0] >> inp[i][1];
V += inp[i][1];
}
vector<ll> dp(V + 1, INT_MAX);
dp[0] = 0;
for (ll i = 0; i < N; i++) {
for (ll j = V - inp[i][1]; j >= 0; j--) {
dp[j + inp[i][1]] = min(dp[j + inp[i][1]], dp[j] + inp[i][0]);
}
}
// for(ll i=0;i<N;i++){for(ll j=0;j<=VAL;j++)cout<<dp[i][j]<<" ";cout<<endl;}
for (ll i = VAL; i >= 0; i--) {
if (dp[i] != INT_MAX) {
cout << dp[i] << endl;
break;
}
}
return 0;
}
|
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
#define ll long long
int main() {
ll N = 0;
cin >> N;
ll VAL = 0;
cin >> VAL;
ll V = 0;
vector<vector<ll>> inp(N, vector<ll>(2));
for (ll i = 0; i < N; i++) {
cin >> inp[i][0] >> inp[i][1];
V += inp[i][1];
}
vector<ll> dp(V + 1, INT_MAX);
dp[0] = 0;
for (ll i = 0; i < N; i++) {
for (ll j = V - inp[i][1]; j >= 0; j--) {
dp[j + inp[i][1]] = min(dp[j + inp[i][1]], dp[j] + inp[i][0]);
}
}
// for(ll i=0;i<N;i++){for(ll j=0;j<=VAL;j++)cout<<dp[i][j]<<" ";cout<<endl;}
// for(int i=0;i<V;i++) cout<<dp[i]<<" ";
// cout<<endl;
for (ll i = V; i >= 0; i--) {
if (dp[i] <= VAL) {
cout << i << endl;
break;
}
}
return 0;
}
|
replace
| 24 | 27 | 24 | 29 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#if !ONLINE_JUDGE
#define debug
#endif
using namespace std;
/******* All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i, k) for (int i = k; i >= 0; i--)
#define rep(i, k) for (int i = 0; i < k; i++)
#define repn(i, k1, k2) for (ll i = k1; i < k2; i++)
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001
#define trav(a, v) for (auto &a : v)
#define tt \
ll t; \
cin >> t; \
while (t--)
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr> vvpr;
typedef vector<vi> vvi;
//*X.find_by_order(2) element at index=2
// X.order_of_key(1) how many elements strictly less than 1
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef debug
#define dbg(...) \
{ \
cerr << "[ "; \
dump(#__VA_ARGS__, __VA_ARGS__); \
}
#undef endl
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) {
return out << "(" << x.ff << "," << x.ss << ")";
}
template <typename Arg1>
ostream &operator<<(ostream &out, const vector<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const unordered_map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> void dump(const string name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void dump(const string names, Arg1 &&arg1, Args &&...args) {
const string name = names.substr(0, names.find(','));
cerr << name << " : " << arg1 << " | ";
dump(names.substr(1 + (int)name.size()), args...);
}
#else
#define dbg(args...)
#endif
ll powmod(ll x, ll y) {
ll res = 1;
x = x % MOD;
while (y > 0) {
if (y & 1)
res = (res * x) % MOD;
y = y >> 1; // y = y/2
x = (x * x) % MOD;
}
return res;
}
ll possible[ee5];
ll we[101], v[101];
ll minw[ee5 + 5];
int main() {
#if !ONLINE_JUDGE
// freopen("in.txt","r",stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, W;
cin >> n >> W;
rep(i, n) { cin >> we[i + 1] >> v[i + 1]; }
ll maxi = 0;
for (int i = 1; i <= ee5; i++)
minw[i] = 1e12;
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (ll val = 100000; val >= 1; val--) {
if (minw[val - v[i]] + we[i] <= minw[val]) {
minw[val] = minw[val - v[i]] + we[i];
if (minw[val] <= W) {
ans = max(ans, val);
}
}
}
}
cout << ans;
}
|
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#if !ONLINE_JUDGE
#define debug
#endif
using namespace std;
/******* All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i, k) for (int i = k; i >= 0; i--)
#define rep(i, k) for (int i = 0; i < k; i++)
#define repn(i, k1, k2) for (ll i = k1; i < k2; i++)
#define sz(x) (ll)(x).size()
#define ff first
#define ss second
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001
#define trav(a, v) for (auto &a : v)
#define tt \
ll t; \
cin >> t; \
while (t--)
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr> vvpr;
typedef vector<vi> vvi;
//*X.find_by_order(2) element at index=2
// X.order_of_key(1) how many elements strictly less than 1
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#ifdef debug
#define dbg(...) \
{ \
cerr << "[ "; \
dump(#__VA_ARGS__, __VA_ARGS__); \
}
#undef endl
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const pair<Arg1, Arg2> &x) {
return out << "(" << x.ff << "," << x.ss << ")";
}
template <typename Arg1>
ostream &operator<<(ostream &out, const vector<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> ostream &operator<<(ostream &out, const set<Arg1> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1, typename Arg2>
ostream &operator<<(ostream &out, const unordered_map<Arg1, Arg2> &a) {
out << "[";
for (const auto &x : a)
out << x << ",";
return out << "]";
}
template <typename Arg1> void dump(const string name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << " ] " << endl;
}
template <typename Arg1, typename... Args>
void dump(const string names, Arg1 &&arg1, Args &&...args) {
const string name = names.substr(0, names.find(','));
cerr << name << " : " << arg1 << " | ";
dump(names.substr(1 + (int)name.size()), args...);
}
#else
#define dbg(args...)
#endif
ll powmod(ll x, ll y) {
ll res = 1;
x = x % MOD;
while (y > 0) {
if (y & 1)
res = (res * x) % MOD;
y = y >> 1; // y = y/2
x = (x * x) % MOD;
}
return res;
}
ll possible[ee5];
ll we[101], v[101];
ll minw[ee5 + 5];
int main() {
#if !ONLINE_JUDGE
// freopen("in.txt","r",stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, W;
cin >> n >> W;
rep(i, n) { cin >> we[i + 1] >> v[i + 1]; }
ll maxi = 0;
for (int i = 1; i <= ee5; i++)
minw[i] = 1e12;
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (ll val = 100000; val >= v[i]; val--) {
if (minw[val - v[i]] + we[i] <= minw[val]) {
minw[val] = minw[val - v[i]] + we[i];
if (minw[val] <= W) {
ans = max(ans, val);
}
}
}
}
cout << ans;
}
|
replace
| 146 | 147 | 146 | 147 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N;
scanf("%lld", &N);
ll W;
scanf("%lld", &W);
vector<ll> w(N);
vector<ll> v(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &w[i]);
scanf("%lld", &v[i]);
}
vector<vector<ll>> dp(N + 1, vector<ll>(N * 1000 + 10, 1e18));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= N * 1000; j++) {
if (dp[i][j - v[i]] != 1e18 && j >= v[i]) {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
ll ans = 0;
for (int i = 0; i <= N * 1000; i++) {
if (dp[N][i] <= W) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll N;
scanf("%lld", &N);
ll W;
scanf("%lld", &W);
vector<ll> w(N);
vector<ll> v(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &w[i]);
scanf("%lld", &v[i]);
}
vector<vector<ll>> dp(N + 1, vector<ll>(N * 1000 + 10, 1e18));
dp[0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= N * 1000; j++) {
if (j >= v[i] && dp[i][j - v[i]] != 1e18) {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
ll ans = 0;
for (int i = 0; i <= N * 1000; i++) {
if (dp[N][i] <= W) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 20 | 21 | 20 | 21 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int n, w;
int vi[105];
long long wi[105];
long long dp[100][100005];
void solve() {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 100000; j++)
dp[i][j] = 1e15;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
dp[i][0] = 0;
for (int j = 1; j <= 100000; j++) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j >= vi[i])
dp[i][j] = min(dp[i][j], dp[i - 1][j - vi[i]] + wi[i]);
}
}
for (int i = 0; i <= 100000; i++) {
if (dp[n][100000 - i] <= w) {
cout << 100000 - i << '\n';
return;
}
}
}
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> wi[i] >> vi[i];
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, w;
int vi[105];
long long wi[105];
long long dp[105][100005];
void solve() {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= 100000; j++)
dp[i][j] = 1e15;
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
dp[i][0] = 0;
for (int j = 1; j <= 100000; j++) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j >= vi[i])
dp[i][j] = min(dp[i][j], dp[i - 1][j - vi[i]] + wi[i]);
}
}
for (int i = 0; i <= 100000; i++) {
if (dp[n][100000 - i] <= w) {
cout << 100000 - i << '\n';
return;
}
}
}
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++)
cin >> wi[i] >> vi[i];
solve();
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
{ cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond &&mes)
using namespace std;
using ll = long long;
constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;
template <typename T> T round_up(const T &a, const T &b) {
return (a + (b - 1)) / b;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
os << p.first << p.second;
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
REP(i, (int)v.size()) is >> v[i];
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
REP(i, (int)v.size()) os << v[i] << endl;
return os;
}
template <typename T> T clamp(T &n, T a, T b) {
if (n < a)
n = a;
if (n > b)
n = b;
return n;
}
template <typename T> static T GCD(T u, T v) {
T r;
while (v != 0) {
r = u % v;
u = v;
v = r;
}
return u;
}
template <typename T> static T LCM(T u, T v) { return u / GCD(u, v) * v; }
std::vector<int> enum_div(int n) {
std::vector<int> ret;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
int N, W;
cin >> N >> W;
vector<pair<int, int>> wv(N);
cin >> wv;
vector<vector<ll>> dp(N + 1, vector<ll>(100 * 1000 + 100, INF));
dp[0][0] = 0;
REP(i, N) {
REP(v, 100 * 1000 + 1) {
chmin(dp[i + 1][v], dp[i][v]);
chmin(dp[i + 1][v + wv[i].second], dp[i][v] + wv[i].first);
}
}
int ans = 0;
REP(i, 100 * 1000 + 1) {
if (dp[N][i] > W || dp[N][i] <= 0)
continue;
chmax(ans, i);
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
{ cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond &&mes)
using namespace std;
using ll = long long;
constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;
template <typename T> T round_up(const T &a, const T &b) {
return (a + (b - 1)) / b;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
os << p.first << p.second;
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
REP(i, (int)v.size()) is >> v[i];
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
REP(i, (int)v.size()) os << v[i] << endl;
return os;
}
template <typename T> T clamp(T &n, T a, T b) {
if (n < a)
n = a;
if (n > b)
n = b;
return n;
}
template <typename T> static T GCD(T u, T v) {
T r;
while (v != 0) {
r = u % v;
u = v;
v = r;
}
return u;
}
template <typename T> static T LCM(T u, T v) { return u / GCD(u, v) * v; }
std::vector<int> enum_div(int n) {
std::vector<int> ret;
for (int i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
int N, W;
cin >> N >> W;
vector<pair<int, int>> wv(N);
cin >> wv;
vector<vector<ll>> dp(N + 1, vector<ll>(100 * 1000 + 100, INF));
dp[0][0] = 0;
REP(i, N) {
REP(v, 100 * 1000 + 1) {
chmin(dp[i + 1][v], dp[i][v]);
if (v - wv[i].second < 0)
continue;
chmin(dp[i + 1][v], dp[i][v - wv[i].second] + wv[i].first);
}
}
int ans = 0;
REP(i, 100 * 1000 + 1) {
if (dp[N][i] > W || dp[N][i] <= 0)
continue;
chmax(ans, i);
}
cout << ans << endl;
return 0;
}
|
replace
| 125 | 126 | 125 | 128 |
0
| |
p03164
|
C++
|
Time Limit Exceeded
|
/*
ID: seekho
PROG: friday
LANG: C++14
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
// find_by_order gives kth-largest element
// order_of_key gives the number of items in the set that are strictly smaller!!
// OT.find_by_order(k-1)
//
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) \
cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< endl
#define db4(x, y, z, w) \
cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int, int>
#define MOD (ll)(998244353)
#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(a, x) for (auto &a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long
//////////////////////
const int N = 100005;
int n, w;
int wt[101];
int val[101];
int memo[101][N];
int go(int ind, int value) {
if (value < 0)
return -1;
if (ind >= n and value != 0)
return -1;
else if (ind >= n)
return w;
if (memo[ind][value] != -inf)
return memo[ind][value];
rep(i, N) {
if (go(ind + 1, value - val[ind]) - wt[ind] >= 0) {
memo[ind][value] =
max(go(ind + 1, value - val[ind]) - wt[ind], go(ind + 1, value));
} else
memo[ind][value] = -1;
}
return memo[ind][value];
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> w;
rep(i, n) cin >> wt[i] >> val[i];
rep(i, n) { rep(j, N) memo[i][j] = -inf; }
repD(i, N - 1, 0) {
if (go(0, i) >= 0) {
cout << i << '\n';
return 0;
}
}
}
|
/*
ID: seekho
PROG: friday
LANG: C++14
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
// find_by_order gives kth-largest element
// order_of_key gives the number of items in the set that are strictly smaller!!
// OT.find_by_order(k-1)
//
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) \
cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< endl
#define db4(x, y, z, w) \
cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int, int>
#define MOD (ll)(998244353)
#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(a, x) for (auto &a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long
//////////////////////
const int N = 100005;
int n, w;
int wt[101];
int val[101];
int memo[101][N];
int go(int ind, int value) {
if (value < 0)
return -1;
if (ind >= n and value != 0)
return -1;
else if (ind >= n)
return w;
if (memo[ind][value] != -inf)
return memo[ind][value];
// rep(i,N) {
if (go(ind + 1, value - val[ind]) - wt[ind] >= 0) {
memo[ind][value] =
max(go(ind + 1, value - val[ind]) - wt[ind], go(ind + 1, value));
} else
memo[ind][value] = go(ind + 1, value);
// }
return memo[ind][value];
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> w;
rep(i, n) cin >> wt[i] >> val[i];
rep(i, n) { rep(j, N) memo[i][j] = -inf; }
repD(i, N - 1, 0) {
if (go(0, i) >= 0) {
cout << i << '\n';
return 0;
}
}
}
|
replace
| 69 | 76 | 69 | 76 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18L + 5;
int main() {
int n, W;
cin >> n >> W;
vector<vector<int>> v(n + 1, vector<int>(2));
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> v[i][0] >> v[i][1];
sum += v[i][1];
}
vector<long long int> dp(sum + 1, INF);
for (int item = 0; item <= n; item++) {
dp[0] = 0;
for (int val = sum; val >= 0; --val) {
dp[val] = min(dp[val], dp[val - v[item][1]] + v[item][0]);
}
}
long long int ans = 0;
for (int i = 0; i < sum + 1; i++) {
if (dp[i] <= W)
ans = max(ans, (long long int)i);
}
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18L + 5;
int main() {
int n, W;
cin >> n >> W;
vector<vector<int>> v(n + 1, vector<int>(2));
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> v[i][0] >> v[i][1];
sum += v[i][1];
}
vector<long long int> dp(sum + 1, INF);
for (int item = 0; item <= n; item++) {
dp[0] = 0;
for (int val = sum; val >= 0; --val) {
if (val >= v[item][1]) {
dp[val] = min(dp[val], dp[val - v[item][1]] + v[item][0]);
}
}
}
long long int ans = 0;
for (int i = 0; i < sum + 1; i++) {
if (dp[i] <= W)
ans = max(ans, (long long int)i);
}
cout << ans;
return 0;
}
|
replace
| 18 | 19 | 18 | 21 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
#define All(v) (v).begin(), (v).end()
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
int Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int mod = 1000000007;
const int inf = mod * mod;
const int d5 = 100100;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, W;
cin >> N >> W;
int dp[d5];
// dp[i]:価値iを達成するのに必要な最小の重さ
for (int i = 0; i < d5; i++)
dp[i] = inf;
dp[0] = 0;
for (int i = 0; i < N; i++) {
int w, v;
cin >> w >> v;
for (int j = d5; j >= 0; j--) {
if (dp[j] == inf)
continue;
dp[j + v] = min(dp[j + v], dp[j] + w);
}
}
int res = 0;
for (int i = 0; i < d5; i++) {
if (dp[i] <= W)
res = max(res, i);
}
cout << res << endl;
}
|
#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
#define All(v) (v).begin(), (v).end()
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};
int Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int mod = 1000000007;
const int inf = mod * mod;
const int d5 = 100100;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, W;
cin >> N >> W;
int dp[d5];
// dp[i]:価値iを達成するのに必要な最小の重さ
for (int i = 0; i < d5; i++)
dp[i] = inf;
dp[0] = 0;
for (int i = 0; i < N; i++) {
int w, v;
cin >> w >> v;
for (int j = d5; j >= 0; j--) {
if (dp[j] == inf)
continue;
if (j + v >= d5)
continue;
dp[j + v] = min(dp[j + v], dp[j] + w);
}
}
int res = 0;
for (int i = 0; i < d5; i++) {
if (dp[i] <= W)
res = max(res, i);
}
cout << res << endl;
}
|
insert
| 41 | 41 | 41 | 43 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, a, b) for (ll i = a; i < b; ++i)
const ll MOD = 1000003;
const ll INF = 1e9;
const ll IINF = 1e18;
const double EPS = 1e-8;
const double pi = acos(-1);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const ll MAX = 100010;
int main() {
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>(MAX, IINF));
dp[0][0] = 0;
rep(i, N) {
rep(j, MAX) {
chmin(dp[i + 1][j], dp[i][j]);
chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
}
ll ans = 0;
rep(i, MAX) {
if (dp[N][i] <= W)
ans = i;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, a, b) for (ll i = a; i < b; ++i)
const ll MOD = 1000003;
const ll INF = 1e9;
const ll IINF = 1e18;
const double EPS = 1e-8;
const double pi = acos(-1);
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const ll MAX = 100010;
int main() {
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>(MAX, IINF));
dp[0][0] = 0;
rep(i, N) {
rep(j, MAX) {
chmin(dp[i + 1][j], dp[i][j]);
if (j - v[i] >= 0)
chmin(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
}
ll ans = 0;
rep(i, MAX) {
if (dp[N][i] <= W)
ans = i;
}
cout << ans << endl;
}
|
replace
| 40 | 41 | 40 | 42 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <iostream>
using namespace std;
#define INF 100000000000
int N;
long long W, w[101], v[101];
long long dp[101][1000000];
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 (long long j = 0; j < 1000000; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i <= N; i++) {
for (long long j = 0; j < 1000000; j++) {
if (j < v[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
}
}
}
long long ans = INF;
for (long long i = 1; i < 1000000; i++)
if (W >= dp[N][i]) {
ans = i;
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
#define INF 100000000000
int N;
long long W, w[102], v[102];
long long dp[102][1000000];
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 (long long j = 0; j < 1000000; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i <= N; i++) {
for (long long j = 0; j < 1000000; j++) {
if (j < v[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
}
}
}
long long ans = INF;
for (long long i = 1; i < 1000000; i++)
if (W >= dp[N][i]) {
ans = i;
}
cout << ans << endl;
return 0;
}
|
replace
| 7 | 9 | 7 | 9 |
-11
| |
p03164
|
C++
|
Runtime Error
|
/*
@author: sharrad99
*/
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1000000000000000;
int main() {
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\sharr\\Documents\\Input.txt", "r", stdin);
freopen("C:\\Users\\sharr\\Documents\\Output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, W;
cin >> n >> W;
vector<long long> w(n), v(n);
for (long long i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
long long mx = *max_element(v.begin(), v.end());
mx *= n;
vector<long long> dp(mx + 1, oo);
dp[0] = 0;
for (long long i = 0; i < n; i++) {
for (long long j = mx; j - v[i] >= 0; j--) {
dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
}
}
long long res = oo;
for (long long j = 0; j <= mx; j++) {
if (dp[j] <= W)
res = j;
}
cout << res << '\n';
}
|
/*
@author: sharrad99
*/
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1000000000000000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, W;
cin >> n >> W;
vector<long long> w(n), v(n);
for (long long i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
long long mx = *max_element(v.begin(), v.end());
mx *= n;
vector<long long> dp(mx + 1, oo);
dp[0] = 0;
for (long long i = 0; i < n; i++) {
for (long long j = mx; j - v[i] >= 0; j--) {
dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
}
}
long long res = oo;
for (long long j = 0; j <= mx; j++) {
if (dp[j] <= W)
res = j;
}
cout << res << '\n';
}
|
delete
| 7 | 12 | 7 | 7 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define ct(a) cout << a << endl
#define tget(a, b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;
ll lim;
ll N, W[100], V[100];
ll dp[101][100001];
int main(void) {
cin >> N >> lim;
FOR(i, 0, N) cin >> W[i] >> V[i];
FOR(i, 0, 102) FOR(k, 0, 100002) dp[i][k] = INF;
dp[0][0] = 0;
FOR(i, 0, N) {
for (ll k = 0; k <= 100000; k++) {
if (k < V[i]) {
dp[i + 1][k] = dp[i][k];
} else {
dp[i + 1][k] = min(dp[i][k], dp[i][k - V[i]] + W[i]);
}
}
}
ll ans = 0;
FOR(i, 0, 100001) if (dp[N][i] <= lim) ans = i;
ct(ans);
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, a, b) for (int i = a; i > b; i--)
#define vint vector<int>
#define vvint vector<vint>
#define ct(a) cout << a << endl
#define tget(a, b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;
ll lim;
ll N, W[100], V[100];
ll dp[101][100001];
int main(void) {
cin >> N >> lim;
FOR(i, 0, N) cin >> W[i] >> V[i];
fill(dp[0], dp[0] + 100001, INF);
dp[0][0] = 0;
FOR(i, 0, N) {
for (ll k = 0; k <= 100000; k++) {
if (k < V[i]) {
dp[i + 1][k] = dp[i][k];
} else {
dp[i + 1][k] = min(dp[i][k], dp[i][k - V[i]] + W[i]);
}
}
}
ll ans = 0;
FOR(i, 0, 100001) if (dp[N][i] <= lim) ans = i;
ct(ans);
return 0;
}
|
replace
| 29 | 30 | 29 | 30 |
-11
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define Int long long
#define N 102
#define N2 100100
Int a[N];
Int dp[N][N2];
Int sum[N];
Int w[N], v[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, W;
for (int i = 0; i <= n; i++)
for (int j = 1; j <= 100000; j++)
dp[i][j] = (1 << 30);
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 = 1; j <= 100000; j++) {
// if(j<v[i]){dp[i][j]=min(w[i],dp[i-1][j]);continue;}
dp[i][j] = min((dp[i - 1][j - v[i]] + w[i]), dp[i - 1][j]);
}
}
Int t = 0;
for (Int i = 1; i <= 100000; i++)
if (dp[n][i] <= W)
t = max(t, i);
cout << t << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define Int long long
#define N 102
#define N2 100100
Int a[N];
Int dp[N][N2];
Int sum[N];
Int w[N], v[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, W;
for (int i = 0; i <= n; i++)
for (int j = 1; j <= 100000; j++)
dp[i][j] = (1 << 30);
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 = 1; j <= 100000; j++) {
if (j <= v[i]) {
dp[i][j] = min(w[i], dp[i - 1][j]);
continue;
}
dp[i][j] = min((dp[i - 1][j - v[i]] + w[i]), dp[i - 1][j]);
}
}
Int t = 0;
for (Int i = 1; i <= 100000; i++)
if (dp[n][i] <= W)
t = max(t, i);
cout << t << endl;
}
|
replace
| 24 | 25 | 24 | 28 |
-11
| |
p03164
|
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;
const int INF = 1100000000;
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(100, vector<ll>(100105, INF));
dp[0][0] = 0;
rep(i, n) {
rep(j, 100100) {
if (j - v[i] >= 0) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
ll ans = 0;
for (int i = 0; i < 100100; ++i) {
if (dp[n][i] <= W)
ans = i;
}
cout << ans << 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;
const int INF = 1100000000;
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>(100105, INF));
dp[0][0] = 0;
rep(i, n) {
rep(j, 100100) {
if (j - v[i] >= 0) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
}
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
}
}
ll ans = 0;
for (int i = 0; i < 100100; ++i) {
if (dp[n][i] <= W)
ans = i;
}
cout << ans << endl;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n;
long long f[N], W, w[N], v[N], s = 0;
int main() {
scanf("%d%lld", &n, &W);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &w[i], &v[i]);
s += v[i];
}
for (long long i = 0; i <= s; i++)
f[i] = 1e15;
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = s; j >= v[i]; j--) {
f[j] = min(f[j], f[j - v[i]] + w[i]);
}
}
for (long long i = s; i >= 0; i--) {
if (f[i] <= W) {
printf("%lld\n", i);
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
long long f[N], W, w[N], v[N], s = 0;
int main() {
scanf("%d%lld", &n, &W);
for (int i = 1; i <= n; i++) {
scanf("%lld%lld", &w[i], &v[i]);
s += v[i];
}
for (long long i = 0; i <= s; i++)
f[i] = 1e15;
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = s; j >= v[i]; j--) {
f[j] = min(f[j], f[j - v[i]] + w[i]);
}
}
for (long long i = s; i >= 0; i--) {
if (f[i] <= W) {
printf("%lld\n", i);
return 0;
}
}
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF = 1e12;
const ll MOD = 1000000007;
ll dp[100][100001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, W;
cin >> N >> W;
ll w[N], v[N];
rep(i, 0, N) cin >> w[i] >> v[i];
rep(i, 0, N) {
rep(j, 0, 100001) { dp[i][j] = INF; }
}
dp[0][0] = 0;
rep(i, 0, N) {
rep(j, 0, 100001) {
if (j < v[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
}
}
ll ans = 0;
rep(i, 1, 100001) {
if (W >= dp[N][i])
ans = i;
}
cout << ans << "\n";
}
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rer(i, a, b) for (int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF = 1e12;
const ll MOD = 1000000007;
ll dp[101][100001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, W;
cin >> N >> W;
ll w[N], v[N];
rep(i, 0, N) cin >> w[i] >> v[i];
rep(i, 0, N) {
rep(j, 0, 100001) { dp[i][j] = INF; }
}
dp[0][0] = 0;
rep(i, 0, N) {
rep(j, 0, 100001) {
if (j < v[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
}
}
ll ans = 0;
rep(i, 1, 100001) {
if (W >= dp[N][i])
ans = i;
}
cout << ans << "\n";
}
|
replace
| 17 | 18 | 17 | 18 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 101;
const int maxw = 100001;
const int inf = 1000000001;
ll dp[maxw];
int n, lim;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> lim;
fill(dp + 1, dp + lim + 1, inf);
for (int w, v, i = 0; i < n; ++i) {
cin >> w >> v;
for (int j = maxw - 1; j >= v; --j)
dp[j] = min(dp[j], dp[j - v] + w);
}
for (int i = maxw - 1; i >= 0; --i)
if (dp[i] <= lim)
return cout << i << '\n', 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
const int maxn = 101;
const int maxw = 100001;
const int inf = 1000000001;
ll dp[maxw];
int n, lim;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> lim;
fill(dp + 1, dp + maxw, inf);
for (int w, v, i = 0; i < n; ++i) {
cin >> w >> v;
for (int j = maxw - 1; j >= v; --j)
dp[j] = min(dp[j], dp[j - v] + w);
}
for (int i = maxw - 1; i >= 0; --i)
if (dp[i] <= lim)
return cout << i << '\n', 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X) << 1)
#define R(X) (((X) << 1) | 1)
#define M(X, Y) (((X) + (Y)) >> 1)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);
template <typename T> T max_self(T &a, T b) {
if (a < b)
a = b;
return a;
}
template <typename T> T min_self(T &a, T b) {
if (a > b)
a = b;
return a;
}
template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; }
template <typename T> T mul(T x, T y) {
return ((x % MOD) * (long long)(y % MOD)) % MOD;
}
template <typename T> T sub(T x, T y) { return add(x, -y + MOD); }
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> vector<T> read(vector<T> &v, int n) {
v.resize(n);
for (auto &x : v)
cin >> x;
}
template <typename T> void trav(vector<T> &v) {
for (int i = 0; i < (int)v.size(); ++i) {
cout << v[i];
if (i != (int)v.size() - 1)
cout << ' ';
}
}
int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; }
int lg2(int x) { return 32 - __builtin_clz(x) - 1; }
// Variables Declaration
int N, W;
vector<ll> w;
vector<ll> v;
ll dp[(int)(1e3 * 100) + 10];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, 0x3f, sizeof(dp));
cin >> N >> W;
w.resize(N);
v.resize(N);
for (int i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
}
dp[0] = 0;
for (int k = 0; k < N; ++k) {
for (int x = 100000; x >= 0; x--) {
dp[x + v[k]] = min(dp[x + v[k]], dp[x] + w[k]);
}
}
for (int i = 100000; i >= 0; --i) {
if (dp[i] <= W) {
cout << i << endl;
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X) << 1)
#define R(X) (((X) << 1) | 1)
#define M(X, Y) (((X) + (Y)) >> 1)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);
template <typename T> T max_self(T &a, T b) {
if (a < b)
a = b;
return a;
}
template <typename T> T min_self(T &a, T b) {
if (a > b)
a = b;
return a;
}
template <typename T> T add(T x, T y) { return ((x % MOD) + (y % MOD)) % MOD; }
template <typename T> T mul(T x, T y) {
return ((x % MOD) * (long long)(y % MOD)) % MOD;
}
template <typename T> T sub(T x, T y) { return add(x, -y + MOD); }
template <typename T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <typename T> vector<T> read(vector<T> &v, int n) {
v.resize(n);
for (auto &x : v)
cin >> x;
}
template <typename T> void trav(vector<T> &v) {
for (int i = 0; i < (int)v.size(); ++i) {
cout << v[i];
if (i != (int)v.size() - 1)
cout << ' ';
}
}
int lg2(long long x) { return 64 - __builtin_clzll(x) - 1; }
int lg2(int x) { return 32 - __builtin_clz(x) - 1; }
// Variables Declaration
int N, W;
vector<ll> w;
vector<ll> v;
ll dp[(int)(2e3 * 100)];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(dp, 0x3f, sizeof(dp));
cin >> N >> W;
w.resize(N);
v.resize(N);
for (int i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
}
dp[0] = 0;
for (int k = 0; k < N; ++k) {
for (int x = 100000; x >= 0; x--) {
dp[x + v[k]] = min(dp[x + v[k]], dp[x] + w[k]);
}
}
for (int i = 100000; i >= 0; --i) {
if (dp[i] <= W) {
cout << i << endl;
return 0;
}
}
return 0;
}
|
replace
| 62 | 63 | 62 | 63 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, W;
ll dp[100 * 1000 + 5];
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
// dp[w][i] = max(dp[w-wt[i]][i-1]+v[i], dp[w][i-1])
// dp[v] = min(wt[i] + dp[v-V[i]], dp[v])
ll wt[100 + 5], V[100 + 5];
ll MAXV = 100;
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> wt[i] >> V[i];
MAXV += V[i];
}
for (ll j = 0; j <= MAXV; j++)
dp[j] = 1e18;
dp[0] = 0;
for (ll i = 0; i < N; i++) {
for (ll v = MAXV; v >= V[i]; v--) {
dp[v] = min(dp[v], wt[i] + dp[v - V[i]]);
}
}
ll ans = 0;
for (ll v = MAXV; v >= 1; v--) {
if (dp[v] <= W) {
ans = v;
break;
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, W;
ll dp[100 * 1000 + 5];
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
// dp[w][i] = max(dp[w-wt[i]][i-1]+v[i], dp[w][i-1])
// dp[v] = min(wt[i] + dp[v-V[i]], dp[v])
ll wt[100 + 5], V[100 + 5];
ll MAXV = 1;
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++) {
cin >> wt[i] >> V[i];
MAXV += V[i];
}
for (ll j = 0; j <= MAXV; j++)
dp[j] = 1e18;
dp[0] = 0;
for (ll i = 0; i < N; i++) {
for (ll v = MAXV; v >= V[i]; v--) {
dp[v] = min(dp[v], wt[i] + dp[v - V[i]]);
}
}
ll ans = 0;
for (ll v = MAXV; v >= 1; v--) {
if (dp[v] <= W) {
ans = v;
break;
}
}
cout << ans << endl;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long w[110], v[110];
long long dp[110][100010];
#define INF 10000000000000
#define VMAX 100010
int main() {
long long W;
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 < VMAX; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < VMAX; j++) {
if (j < v[j]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
}
}
}
int ans = 0;
for (int i = 0; i < VMAX; i++)
if (dp[n][i] <= W)
ans = i;
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n;
long long w[110], v[110];
long long dp[110][100010];
#define INF 10000000000000
#define VMAX 100010
int main() {
long long W;
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 < VMAX; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < VMAX; j++) {
if (j < v[i]) {
dp[i + 1][j] = dp[i][j];
} else {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
}
}
}
int ans = 0;
for (int i = 0; i < VMAX; i++)
if (dp[n][i] <= W)
ans = i;
cout << ans << endl;
return 0;
}
|
replace
| 28 | 29 | 28 | 29 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 5;
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
ll W;
cin >> W;
vector<int> w(n + 1);
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> w[i];
cin >> v[i];
}
ll sum_value = 0;
for (int i = 1; i <= n; i++) {
sum_value += v[i];
}
const ll INF = 1e18l + 5;
ll dp[n + 1][sum_value + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= sum_value; j++) {
dp[i][j] = INF;
}
}
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= sum_value; j++) {
if (v[i] <= j)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
else
dp[i][j] = dp[i - 1][j];
// cout << dp[i][j] << " " << j << endl;
}
}
/*for (int i=0; i<=n; i++) {
for (int j=0; j<=sum_value; j++) {
if (dp[i][j] == INF)
cout << "I" << " ";
else
cout << dp[i][j] << " ";
}
cout << endl;
}*/
ll ans = 0;
for (int i = 1; i <= sum_value; i++) {
if (dp[n][i] <= W)
ans = max(ans, (ll)i);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9 + 5;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
ll W;
cin >> W;
vector<int> w(n + 1);
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> w[i];
cin >> v[i];
}
ll sum_value = 0;
for (int i = 1; i <= n; i++) {
sum_value += v[i];
}
const ll INF = 1e18l + 5;
ll dp[n + 1][sum_value + 1];
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= sum_value; j++) {
dp[i][j] = INF;
}
}
for (int i = 0; i <= n; i++) {
dp[i][0] = 0;
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= sum_value; j++) {
if (v[i] <= j)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
else
dp[i][j] = dp[i - 1][j];
// cout << dp[i][j] << " " << j << endl;
}
}
/*for (int i=0; i<=n; i++) {
for (int j=0; j<=sum_value; j++) {
if (dp[i][j] == INF)
cout << "I" << " ";
else
cout << dp[i][j] << " ";
}
cout << endl;
}*/
ll ans = 0;
for (int i = 1; i <= sum_value; i++) {
if (dp[n][i] <= W)
ans = max(ans, (ll)i);
}
cout << ans << endl;
return 0;
}
|
replace
| 5 | 7 | 5 | 6 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
const int maxn = n * n * 1000 + 1;
vector<vector<long long>> dp(n + 1, vector<long long>(maxn, 1e15));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = maxn - 1; j >= 0; j--) {
if (dp[i][j] == 1e15)
continue;
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
if (j + v[i] < maxn) {
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
}
}
}
int res = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < maxn; j++) {
if (dp[i][j] <= W) {
res = max(res, j);
}
}
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, W;
cin >> n >> W;
vector<int> w(n), v(n);
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
}
const int maxn = n * 1000 + 1;
vector<vector<long long>> dp(n + 1, vector<long long>(maxn, 1e15));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = maxn - 1; j >= 0; j--) {
if (dp[i][j] == 1e15)
continue;
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
if (j + v[i] < maxn) {
dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
}
}
}
int res = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < maxn; j++) {
if (dp[i][j] <= W) {
res = max(res, j);
}
}
}
cout << res << endl;
}
|
replace
| 11 | 12 | 11 | 12 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
long long N, G, i, j, mx;
long long p[1005], P, w[1005], a[1005], b[1005];
int main() {
// ifstream cin("rucsac.in");
cin >> N >> G;
for (i = 1; i <= N; i++) {
cin >> w[i] >> p[i];
P += p[i];
}
for (i = 1; i <= P; i++)
b[i] = 1000000000;
// cout << P << " ";
b[0] = 0;
for (i = 1; i <= N; ++i) {
for (j = 0; j <= P; ++j) {
if (p[i] > j)
a[j] = min(b[j], w[i]);
else {
a[j] = min(b[j], b[j - p[i]] + w[i]);
if (a[j] <= G) {
mx = max(mx, j);
}
}
}
// cout << "\n";
for (j = 0; j <= P; ++j) {
b[j] = a[j];
// if (a[j] >= 1000000000)cout << "inf ";
// else cout << a[j]<<" ";
// cout<<"("<<j<<") ";
}
// cout<<"|||\n";
}
cout << mx;
}
|
#include <algorithm>
#include <fstream>
#include <iostream>
using namespace std;
long long N, G, i, j, mx;
long long p[105], P, 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];
P += p[i];
}
for (i = 1; i <= P; i++)
b[i] = 1000000000;
// cout << P << " ";
b[0] = 0;
for (i = 1; i <= N; ++i) {
for (j = 0; j <= P; ++j) {
if (p[i] > j)
a[j] = min(b[j], w[i]);
else {
a[j] = min(b[j], b[j - p[i]] + w[i]);
if (a[j] <= G) {
mx = max(mx, j);
}
}
}
// cout << "\n";
for (j = 0; j <= P; ++j) {
b[j] = a[j];
// if (a[j] >= 1000000000)cout << "inf ";
// else cout << a[j]<<" ";
// cout<<"("<<j<<") ";
}
// cout<<"|||\n";
}
cout << mx;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int const maxsize = 100005;
int weight[maxsize], cost[maxsize];
long long int dp[103][maxsize];
int main() {
int n, w;
cin >> n >> w;
for (int x = 1; x <= n; x++)
cin >> weight[x] >> cost[x];
memset(dp, 63, sizeof(dp));
int ans = 0;
// for(int x=0;x<=100000;x++) dp[0][x] = 0;
// for(int x=0;x<=100;x++) dp[x][0] = 0;
dp[0][0] = 0;
for (int x = 1; x <= n; x++) {
for (int i = 0; i < maxsize; i++) {
dp[x][i] = dp[x - 1][i];
if (i - cost[x - 1] >= 0) {
dp[x][i] = min(dp[x][i], dp[x - 1][i - cost[x]] + weight[x]);
}
// dp[x][i] = min(d, dp[x][i]);
}
}
for (int x = 0; x < maxsize; x++)
if (dp[n][x] <= w)
ans = max(ans, x);
cout << ans;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int const maxsize = 100005;
int weight[maxsize], cost[maxsize];
long long int dp[103][maxsize];
int main() {
int n, w;
cin >> n >> w;
for (int x = 1; x <= n; x++)
cin >> weight[x] >> cost[x];
memset(dp, 63, sizeof(dp));
int ans = 0;
// for(int x=0;x<=100000;x++) dp[0][x] = 0;
// for(int x=0;x<=100;x++) dp[x][0] = 0;
dp[0][0] = 0;
for (int x = 1; x <= n; x++) {
for (int i = 0; i < maxsize; i++) {
dp[x][i] = dp[x - 1][i];
if (i - cost[x] >= 0) {
dp[x][i] = min(dp[x - 1][i], dp[x - 1][i - cost[x]] + weight[x]);
}
// dp[x][i] = min(d, dp[x][i]);
}
}
for (int x = 0; x < maxsize; x++)
if (dp[n][x] <= w)
ans = max(ans, x);
cout << ans;
return 0;
}
|
replace
| 22 | 24 | 22 | 24 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n, all, w[105], v[105];
long long dp[100105];
int main() {
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
scanf("%d%d", &n, &all);
for (int i = 1; i <= n; ++i)
scanf("%d%d", &w[i], &v[i]);
for (int i = 1; i <= n; ++i) {
for (int j = 100000; j != -1; --j)
dp[j + v[i]] = min(dp[j + v[i]], dp[j] + (long long)w[i]);
}
for (int i = 100000; i != -1; --i)
if (dp[i] <= all) {
printf("%d", i);
break;
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n, all, w[10000005], v[10000005];
long long dp[50010005];
int main() {
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
scanf("%d%d", &n, &all);
for (int i = 1; i <= n; ++i)
scanf("%d%d", &w[i], &v[i]);
for (int i = 1; i <= n; ++i) {
for (int j = 100000; j != -1; --j)
dp[j + v[i]] = min(dp[j + v[i]], dp[j] + (long long)w[i]);
}
for (int i = 100000; i != -1; --i)
if (dp[i] <= all) {
printf("%d", i);
break;
}
return 0;
}
|
replace
| 4 | 6 | 4 | 6 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
int N;
ll W, w[200], v[200];
ll memo[200][200 * 2000 + 1];
ll solve(int n, int V) {
if (V < 0)
return INT_MAX;
if (n == N) {
if (V == 0)
return 0LL;
else
return INT_MAX;
}
if (memo[n][V] != -1)
return memo[n][V];
return memo[n][V] = min(solve(n + 1, V), solve(n + 1, V - v[n]) + w[n]);
}
signed main() {
scanf("%d%d", &W, &N);
assert(1 <= W && W <= 1000000000);
assert(1 <= N && N <= 200);
rep(i, N) {
scanf("%d%d", w + i, v + i);
assert(1 <= w[i] && w[i] <= 1000000000);
assert(1 <= v[i] && v[i] <= 2000);
}
memset(memo, -1, sizeof(memo));
for (int i = 400000; i >= 0; i--) {
if (solve(0, i) <= W) {
printf("%d\n", i);
break;
}
}
}
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9 + 7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
int N;
ll W, w[200], v[200];
ll memo[200][200 * 2000 + 1];
ll solve(int n, int V) {
if (V < 0)
return INT_MAX;
if (n == N) {
if (V == 0)
return 0LL;
else
return INT_MAX;
}
if (memo[n][V] != -1)
return memo[n][V];
return memo[n][V] = min(solve(n + 1, V), solve(n + 1, V - v[n]) + w[n]);
}
signed main() {
scanf("%d%d", &N, &W);
assert(1 <= W && W <= 1000000000);
assert(1 <= N && N <= 200);
rep(i, N) {
scanf("%d%d", w + i, v + i);
assert(1 <= w[i] && w[i] <= 1000000000);
assert(1 <= v[i] && v[i] <= 2000);
}
memset(memo, -1, sizeof(memo));
for (int i = 400000; i >= 0; i--) {
if (solve(0, i) <= W) {
printf("%d\n", i);
break;
}
}
}
|
replace
| 28 | 29 | 28 | 29 |
-11
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m, V;
int w[110];
int v[110];
int f[1010]; // f[i]表示达到i价值的最优w
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
V += v[i];
}
memset(f, 0x3f, sizeof(f));
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = V; j >= v[i]; j--) {
f[j] = min(f[j], f[j - v[i]] + w[i]);
}
}
for (int i = V; i >= 1; i--) {
if (f[i] && f[i] <= m) {
printf("%d", i);
return 0;
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int n, m, V;
int w[1100];
int v[1100];
int f[1010000]; // f[i]表示达到i价值的最优w
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> v[i];
V += v[i];
}
memset(f, 0x3f, sizeof(f));
f[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = V; j >= v[i]; j--) {
f[j] = min(f[j], f[j - v[i]] + w[i]);
}
}
for (int i = V; i >= 1; i--) {
if (f[i] && f[i] <= m) {
printf("%d", i);
return 0;
}
}
return 0;
}
|
replace
| 8 | 11 | 8 | 11 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const long long maxv = 100000;
const long long oo = LLONG_MAX;
long long N, W;
unsigned long long w[101], v[101];
unsigned long long F[101][maxv + 1];
void Enter() {
// freopen("INPUT.TXT","r",stdin);
// freopen("OUTPUT.TXT","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> W;
for (long long i = 1; i <= N; ++i)
cin >> w[i] >> v[i];
}
int main() {
Enter();
memset(F, 0, sizeof(F));
for (long long i = 0; i <= N; ++i) {
for (long long j = 0; j <= maxv; ++j) {
F[i][j] = oo;
}
}
F[0][0] = 0;
for (long long i = 0; i <= N; ++i) {
for (long long j = 0; j <= maxv; ++j) {
if (F[i][j] == oo)
continue;
if (F[i][j] + w[i + 1] <= W)
F[i + 1][j + v[i + 1]] =
min(F[i][j] + w[i + 1], F[i + 1][j + v[i + 1]]);
F[i + 1][j] = min(F[i + 1][j], F[i][j]);
}
}
for (long long j = maxv; j >= 1; --j) {
if (F[N][j] != oo) {
cout << j;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long maxv = 100000;
const long long oo = LLONG_MAX;
long long N, W;
unsigned long long w[103], v[103];
unsigned long long F[103][maxv + 1];
void Enter() {
// freopen("INPUT.TXT","r",stdin);
// freopen("OUTPUT.TXT","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N >> W;
for (long long i = 1; i <= N; ++i)
cin >> w[i] >> v[i];
}
int main() {
Enter();
memset(F, 0, sizeof(F));
for (long long i = 0; i <= N; ++i) {
for (long long j = 0; j <= maxv; ++j) {
F[i][j] = oo;
}
}
F[0][0] = 0;
for (long long i = 0; i <= N; ++i) {
for (long long j = 0; j <= maxv; ++j) {
if (F[i][j] == oo)
continue;
if (F[i][j] + w[i + 1] <= W)
F[i + 1][j + v[i + 1]] =
min(F[i][j] + w[i + 1], F[i + 1][j + v[i + 1]]);
F[i + 1][j] = min(F[i + 1][j], F[i][j]);
}
}
for (long long j = maxv; j >= 1; --j) {
if (F[N][j] != oo) {
cout << j;
break;
}
}
return 0;
}
|
replace
| 7 | 9 | 7 | 9 |
0
| |
p03164
|
C++
|
Time Limit Exceeded
|
#pragma gcc optimize(o3)
#include <bits/stdc++.h>
#define IO \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define S second
#define F first
#define ll long long
#define ld long double
#define U unsigned
#define pi acos(-1)
using namespace std;
const ll N = 1e2 + 5, M = 1e5 + 5;
ll w[N], v[N], vis[N][M], vid;
ll n, W, mxV, V;
pair<ll, ll> dp[N][M];
pair<ll, ll> solve(ll ind, ll curV) {
if (curV > mxV)
return {-1e9, 1e9};
if (vis[ind][curV])
return dp[ind][curV];
if (ind == n)
return {0, 0};
pair<ll, ll> ret = max(make_pair(solve(ind + 1, curV + v[ind]).F + v[ind],
solve(ind + 1, curV + v[ind]).S - w[ind]),
solve(ind + 1, curV));
return dp[ind][curV] = ret;
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
mxV += v[i];
}
vid++;
ll s = 0, e = mxV, mid, best = 0;
for (int i = 0; i < mxV; i++) {
pair<ll, ll> xx = solve(0, i);
if (abs(xx.S) <= W) {
best = max(best, xx.F);
}
}
cout << best;
return 0;
}
|
#pragma gcc optimize(o3)
#include <bits/stdc++.h>
#define IO \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define S second
#define F first
#define ll long long
#define ld long double
#define U unsigned
#define pi acos(-1)
using namespace std;
const ll N = 1e2 + 5, M = 1e5 + 5;
ll w[N], v[N], vis[N][M], vid;
ll n, W, mxV, V;
pair<ll, ll> dp[N][M];
pair<ll, ll> solve(ll ind, ll curV) {
if (curV > mxV)
return {-1e9, 1e9};
if (vis[ind][curV])
return dp[ind][curV];
vis[ind][curV] = 1;
if (ind == n)
return {0, 0};
pair<ll, ll> ret = max(make_pair(solve(ind + 1, curV + v[ind]).F + v[ind],
solve(ind + 1, curV + v[ind]).S - w[ind]),
solve(ind + 1, curV));
return dp[ind][curV] = ret;
}
int main() {
cin >> n >> W;
for (int i = 0; i < n; i++) {
cin >> w[i] >> v[i];
mxV += v[i];
}
vid++;
ll s = 0, e = mxV, mid, best = 0;
for (int i = 0; i < mxV; i++) {
pair<ll, ll> xx = solve(0, i);
if (abs(xx.S) <= W) {
best = max(best, xx.F);
}
}
cout << best;
return 0;
}
|
insert
| 26 | 26 | 26 | 27 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
int N, W;
int w[110], v[110];
ll dp[110][10010]; // dp[i][j]で価値総和がjになる時の重さ総和min
cin >> N >> W;
for (int i = 0; i < 110; ++i) {
for (int j = 0; j < 100100; ++j) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 100100; ++j) {
if (j >= v[i]) {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
ll ans = 0;
for (int i = 0; i <= 100100; ++i) {
if (dp[N][i] <= W)
ans = i;
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
int N;
ll W;
ll w[110], v[110];
ll dp[110][100100]; // dp[i][j]で価値総和がjになる時の重さ総和min
cin >> N >> W;
for (int i = 0; i < 110; ++i) {
for (int j = 0; j < 100100; ++j) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < N; ++i) {
cin >> w[i] >> v[i];
}
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 100100; ++j) {
if (j >= v[i]) {
dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
} else {
dp[i + 1][j] = dp[i][j];
}
}
}
ll ans = 0;
for (int i = 0; i <= 100100; ++i) {
if (dp[N][i] <= W)
ans = i;
}
cout << ans << endl;
return 0;
}
|
replace
| 22 | 25 | 22 | 26 |
-11
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int n, C;
long long w[101];
int v[101];
long long dp[101][1003];
long long solve(int i, int value) {
if (value <= 0)
return 0;
if (i == n)
return 1000000000;
if (dp[i][value] != -1)
return dp[i][value];
dp[i][value] = solve(i + 1, value);
dp[i][value] = min(dp[i][value], solve(i + 1, value - v[i]) + w[i]);
return dp[i][value];
}
int main() {
cin >> n >> C;
long long v_sum = 0;
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
v_sum += v[i];
}
memset(dp, -1, sizeof dp);
for (int i = v_sum; i >= 0; i--) {
if (solve(0, i) <= C) {
cout << i << endl;
return 0;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, C;
long long w[101];
int v[101];
long long dp[101][1000001];
long long solve(int i, int value) {
if (value <= 0)
return 0;
if (i == n)
return 1000000000;
if (dp[i][value] != -1)
return dp[i][value];
dp[i][value] = solve(i + 1, value);
dp[i][value] = min(dp[i][value], solve(i + 1, value - v[i]) + w[i]);
return dp[i][value];
}
int main() {
cin >> n >> C;
long long v_sum = 0;
for (int i = 0; i < n; ++i) {
cin >> w[i] >> v[i];
v_sum += v[i];
}
memset(dp, -1, sizeof dp);
for (int i = v_sum; i >= 0; i--) {
if (solve(0, i) <= C) {
cout << i << endl;
return 0;
}
}
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;
typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;
template <class T> inline bool chmin(T &to, T compare) {
if (to > compare) {
to = compare;
return true;
}
return false;
};
template <class T> inline bool chmax(T &to, T compare) {
if (to < compare) {
to = compare;
return true;
}
return false;
};
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
llong N, W;
cin >> N >> W;
vecllong weight(N + 1, 0);
vecllong value(N + 1, 0);
llong maxValue = 0;
FOR(i, N) {
cin >> weight[i] >> value[i];
maxValue += weight[i];
}
vvecllong dp(N + 1, vecllong(maxValue + 1, INF)); // dp[i][value] = minWeight
dp[0][0] = 0;
FOR(i, N) {
FOR(v, maxValue + 1) {
if (v - value[i] >= 0) {
dp[i + 1][v] =
min({dp[i][v - value[i]] + weight[i], dp[i][v], dp[i + 1][v]});
} else {
dp[i + 1][v] = dp[i][v];
}
}
}
llong ans = 0;
for (llong v = maxValue; v >= 0; v--) {
if (dp[N][v] <= W) {
ans = v;
break;
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;
typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;
template <class T> inline bool chmin(T &to, T compare) {
if (to > compare) {
to = compare;
return true;
}
return false;
};
template <class T> inline bool chmax(T &to, T compare) {
if (to < compare) {
to = compare;
return true;
}
return false;
};
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
llong N, W;
cin >> N >> W;
vecllong weight(N + 1, 0);
vecllong value(N + 1, 0);
llong maxValue = 0;
FOR(i, N) {
cin >> weight[i] >> value[i];
maxValue += value[i];
}
vvecllong dp(N + 1, vecllong(maxValue + 1, INF)); // dp[i][value] = minWeight
dp[0][0] = 0;
FOR(i, N) {
FOR(v, maxValue + 1) {
if (v - value[i] >= 0) {
dp[i + 1][v] =
min({dp[i][v - value[i]] + weight[i], dp[i][v], dp[i + 1][v]});
} else {
dp[i + 1][v] = dp[i][v];
}
}
}
llong ans = 0;
for (llong v = maxValue; v >= 0; v--) {
if (dp[N][v] <= W) {
ans = v;
break;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 58 | 59 | 58 | 59 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e3 + 1;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;
const int inf = 1e15 + 7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, w;
cin >> n >> w;
int wt[n + 1], val[n + 1];
int V(0);
wt[0] = val[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> wt[i] >> val[i];
V += val[i];
}
std::vector<std::vector<int>> dp(n + 1, std::vector<int>(V + 2, inf));
// dp(i , j) --> represents minimum weight required to get value j if i items
// are availiable
dp[0][0] = 0;
for (int item = 1; item <= n; item++) {
dp[item][0] = 0;
}
for (int item = 1; item <= n; item++) {
for (int value = 0; value <= V; value++) {
if (value == 0)
dp[item][value] = 0;
else if (value >= val[item - 1]) {
dp[item][value] = min(wt[item] + dp[item - 1][value - val[item]],
dp[item - 1][value]);
} else
dp[item][value] = dp[item - 1][value];
}
}
for (int i = V; i >= 0; i--) {
if (dp[n][i] <= w) {
cout << i << ' ';
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int N = 1e3 + 1;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;
const int inf = 1e15 + 7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, w;
cin >> n >> w;
int wt[n + 1], val[n + 1];
int V(0);
wt[0] = val[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> wt[i] >> val[i];
V += val[i];
}
std::vector<std::vector<int>> dp(n + 1, std::vector<int>(V + 2, inf));
// dp(i , j) --> represents minimum weight required to get value j if i items
// are availiable
dp[0][0] = 0;
for (int item = 1; item <= n; item++) {
dp[item][0] = 0;
}
for (int item = 1; item <= n; item++) {
for (int value = 0; value <= V; value++) {
if (value == 0)
dp[item][value] = 0;
else if (value >= val[item]) {
dp[item][value] = min(wt[item] + dp[item - 1][value - val[item]],
dp[item - 1][value]);
} else
dp[item][value] = dp[item - 1][value];
}
}
for (int i = V; i >= 0; i--) {
if (dp[n][i] <= w) {
cout << i << ' ';
return 0;
}
}
return 0;
}
|
replace
| 34 | 35 | 34 | 35 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("YES"); } \
else { \
puts("NO"); \
}
const int MV = 1 << 30;
int main() {
int N, W;
cin >> N >> W;
vi we(N), va(N);
rep(i, N) { cin >> we[i] >> va[i]; }
v(ll) dp(MV, LINF);
dp[0] = 0;
rep(i, N) {
v(ll) nextdp(MV);
ll w = we[i];
ll val = va[i];
rep(x, MV) {
if (x - val >= 0) {
nextdp[x] = min(dp[x], dp[x - val] + w);
} else {
nextdp[x] = dp[x];
}
}
dp = nextdp;
}
drep(i, MV) {
if (dp[i] <= W) {
cout << i << endl;
break;
}
}
return 0;
}
|
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame \
{ \
puts("-1"); \
return 0; \
}
#define yn \
{ puts("YES"); } \
else { \
puts("NO"); \
}
const int MV = 100100;
int main() {
int N, W;
cin >> N >> W;
vi we(N), va(N);
rep(i, N) { cin >> we[i] >> va[i]; }
v(ll) dp(MV, LINF);
dp[0] = 0;
rep(i, N) {
v(ll) nextdp(MV);
ll w = we[i];
ll val = va[i];
rep(x, MV) {
if (x - val >= 0) {
nextdp[x] = min(dp[x], dp[x - val] + w);
} else {
nextdp[x] = dp[x];
}
}
dp = nextdp;
}
drep(i, MV) {
if (dp[i] <= W) {
cout << i << endl;
break;
}
}
return 0;
}
|
replace
| 54 | 55 | 54 | 55 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p03164
|
C++
|
Runtime Error
|
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 110
#define MAX_V 100010
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 long long INF = 1LL << 60;
// Input
int N;
long long W, weight[MAX_N], value[MAX_N];
// DP table
long long dp[MAX_N][MAX_V];
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> weight[i] >> value[i];
// Initialization
for (int i = 0; i < MAX_N; i++)
for (int j = 0; j < MAX_V; j++)
dp[i][j] = INF;
// Initial state
dp[0][0] = 0;
// Update
for (int i = 0; i < N; i++) {
for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
// Ans
long long res = 0;
for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
if (dp[N][sum_v] <= W)
res = sum_v;
}
cout << res << endl;
}
|
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 110
#define MAX_V 100010
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 long long INF = 1LL << 60;
// Input
int N;
long long W, weight[MAX_N], value[MAX_N];
// DP table
long long dp[MAX_N][MAX_V];
int main() {
cin >> N >> W;
for (int i = 0; i < N; i++)
cin >> weight[i] >> value[i];
// Initialization
for (int i = 0; i < MAX_N; i++)
for (int j = 0; j < MAX_V; j++)
dp[i][j] = INF;
// Initial state
dp[0][0] = 0;
// Update
for (int i = 0; i < N; i++) {
for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
if (sum_v - value[i] >= 0)
chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
// Ans
long long res = 0;
for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
if (dp[N][sum_v] <= W)
res = sum_v;
}
cout << res << endl;
}
|
replace
| 46 | 47 | 46 | 48 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
int N, V;
long long W, w[110], v[110];
long long dp[110][1010], ans;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// --------------------------------------
cin >> N >> W;
V = 0;
for (int i = 1; i < N + 1; i++) {
cin >> w[i] >> v[i];
V += v[i];
}
for (int i = 0; i <= N; i++) {
for (int sum_v = 1; sum_v <= V; sum_v++) {
dp[i][sum_v] = 1000000010;
}
}
for (int i = 0; i < N; i++) {
for (int sum_v = 0; sum_v <= V; sum_v++) {
if (sum_v - v[i + 1] >= 0) {
chmin(dp[i + 1][sum_v], dp[i][sum_v - v[i + 1]] + w[i + 1]);
}
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ans = 0;
for (int sum_v = 0; sum_v <= V; sum_v++) {
if (dp[N][sum_v] <= W) {
ans = sum_v;
}
}
cout << ans << "\n";
}
|
#include "bits/stdc++.h"
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
int N, V;
long long W, w[110], v[110];
long long dp[110][100010], ans;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// --------------------------------------
cin >> N >> W;
V = 0;
for (int i = 1; i < N + 1; i++) {
cin >> w[i] >> v[i];
V += v[i];
}
for (int i = 0; i <= N; i++) {
for (int sum_v = 1; sum_v <= V; sum_v++) {
dp[i][sum_v] = 1000000010;
}
}
for (int i = 0; i < N; i++) {
for (int sum_v = 0; sum_v <= V; sum_v++) {
if (sum_v - v[i + 1] >= 0) {
chmin(dp[i + 1][sum_v], dp[i][sum_v - v[i + 1]] + w[i + 1]);
}
chmin(dp[i + 1][sum_v], dp[i][sum_v]);
}
}
ans = 0;
for (int sum_v = 0; sum_v <= V; sum_v++) {
if (dp[N][sum_v] <= W) {
ans = sum_v;
}
}
cout << ans << "\n";
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p03164
|
C++
|
Time Limit Exceeded
|
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long int
#define ii int
#define jmp cout << "\n"
#define vl vector<ll>
#define pb push_back
#define printv(v) \
for (auto x : v) \
cout << x << " "; \
jmp;
#define endll "\n"
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define ff first
#define ss second
#define iin insert
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
const ll N = 1e5 + 5;
const ll inf = 0x3f3f3f3f;
ll dp[N];
ll w[N], val[N];
void solve() {
ll n, W;
cin >> n >> W;
// ll w[n], val[n];
for (ll i = 0; i < n; i++)
cin >> val[i] >> w[i];
memset(dp, inf, sizeof(dp));
dp[0] = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 1e5; j >= w[i]; j--)
dp[j] = min(dp[j], (dp[j - w[i]] + val[i]));
}
ll ans;
for (ll i = 1e5; i >= 0; i--) {
if (dp[i] <= W) {
ans = i;
break;
}
}
cout << ans;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// ll t;
// cin >> t;
// while (t--)
solve();
return 0;
}
|
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long int
#define ii int
#define jmp cout << "\n"
#define vl vector<ll>
#define pb push_back
#define printv(v) \
for (auto x : v) \
cout << x << " "; \
jmp;
#define endll "\n"
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define ff first
#define ss second
#define iin insert
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
const ll N = 1e5 + 5;
const ll inf = 0x3f3f3f3f;
ll dp[N];
ll w[N], val[N];
void solve() {
ll n, W;
cin >> n >> W;
// ll w[n], val[n];
for (ll i = 0; i < n; i++)
cin >> val[i] >> w[i];
memset(dp, inf, sizeof(dp));
dp[0] = 0;
for (ll i = 0; i < n; i++) {
for (ll j = 1e5; j >= w[i]; j--)
dp[j] = min(dp[j], (dp[j - w[i]] + val[i]));
}
ll ans;
for (ll i = 1e5; i >= 0; i--) {
if (dp[i] <= W) {
ans = i;
break;
}
}
cout << ans;
}
int main() {
solve();
return 0;
}
|
replace
| 51 | 58 | 51 | 52 |
TLE
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define M 1000000007
#define pb push_back
#define boost \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define NAYAN \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
int dp[102][10005];
int n, w;
int val[100001], wt[100001];
/*int solve(int i,int V)
{
//cout << i << " " << V << endl;
if(V==0)
return 0;
if(V<0 || i==n)
return 99999999999999;
if(dp[i][V]!=-1)
return dp[i][V];
int x=solve(i+1,V);
int y=wt[i]+solve(i+1,V-val[i]);
dp[i][V]=min(x,y);
return dp[i][V];
}*/
signed main() {
boost
// #ifndef ONLINE_JUDGE
// NAYAN
// #endif
// int n;
cin >>
n >> w;
// cout << n << endl;
int i, j;
for (i = 1; i <= n; i++) {
cin >> wt[i] >> val[i];
}
for (i = 0; i <= n; i++) {
for (j = 0; j <= 100000; j++) {
dp[i][j] = 1000000000000;
}
}
dp[0][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 100000; j >= 0; j--) {
// dp[i][j]=999999999999;
if (val[i] <= j)
dp[i][j] = min(dp[i - 1][j], wt[i] + dp[i - 1][j - val[i]]);
else
dp[i][j] = dp[i - 1][j];
}
}
int ans;
for (i = 100000; i >= 0; i--) {
ans = dp[n][i];
// cout << ans << " " << w << endl;
if (ans <= w)
break;
}
cout << i << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define M 1000000007
#define pb push_back
#define boost \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define NAYAN \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
int dp[102][100005];
int n, w;
int val[100001], wt[100001];
/*int solve(int i,int V)
{
//cout << i << " " << V << endl;
if(V==0)
return 0;
if(V<0 || i==n)
return 99999999999999;
if(dp[i][V]!=-1)
return dp[i][V];
int x=solve(i+1,V);
int y=wt[i]+solve(i+1,V-val[i]);
dp[i][V]=min(x,y);
return dp[i][V];
}*/
signed main() {
boost
// #ifndef ONLINE_JUDGE
// NAYAN
// #endif
// int n;
cin >>
n >> w;
// cout << n << endl;
int i, j;
for (i = 1; i <= n; i++) {
cin >> wt[i] >> val[i];
}
for (i = 0; i <= n; i++) {
for (j = 0; j <= 100000; j++) {
dp[i][j] = 1000000000000;
}
}
dp[0][0] = 0;
for (i = 1; i <= n; i++) {
for (j = 100000; j >= 0; j--) {
// dp[i][j]=999999999999;
if (val[i] <= j)
dp[i][j] = min(dp[i - 1][j], wt[i] + dp[i - 1][j - val[i]]);
else
dp[i][j] = dp[i - 1][j];
}
}
int ans;
for (i = 100000; i >= 0; i--) {
ans = dp[n][i];
// cout << ans << " " << w << endl;
if (ans <= w)
break;
}
cout << i << endl;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long int
ll const MOD = 1000000007;
ll const INF = (long long int)1 << 58;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, w;
cin >> n >> w;
vector<vector<ll>> in(n, vector<ll>(2));
for (int i = 0; i < n; i++) {
cin >> in[i][0] >> in[i][1];
}
vector<vector<ll>> dp(n + 1, vector<ll>(n * (1000) + 1, INF));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n * 1000; j++) {
dp[i + 1][j] = dp[i][j];
}
for (int j = 0; j <= n * 1000; j++) {
dp[i + 1][j + in[i][1]] =
min(dp[i + 1][j + in[i][1]], dp[i][j] + in[i][0]);
}
}
ll ans = 0;
for (int i = 0; i < n * 1000 + 1; i++) {
if (dp[n][i] <= w) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define ll long long int
ll const MOD = 1000000007;
ll const INF = (long long int)1 << 58;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, w;
cin >> n >> w;
vector<vector<ll>> in(n, vector<ll>(2));
for (int i = 0; i < n; i++) {
cin >> in[i][0] >> in[i][1];
}
vector<vector<ll>> dp(n + 1, vector<ll>(n * (1000) + 1, INF));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n * 1000; j++) {
dp[i + 1][j] = dp[i][j];
}
for (int j = 0; j <= n * 1000; j++) {
if (j + in[i][1] <= n * 1000) {
dp[i + 1][j + in[i][1]] =
min(dp[i + 1][j + in[i][1]], dp[i][j] + in[i][0]);
}
}
}
ll ans = 0;
for (int i = 0; i < n * 1000 + 1; i++) {
if (dp[n][i] <= w) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
replace
| 44 | 46 | 44 | 48 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define drep(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define MAGICLINE ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define se second
#define fs first
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, int> PLI;
typedef priority_queue<int> PQI;
typedef priority_queue<LL> PQL;
typedef priority_queue<PLI, vector<PLI>, greater<PLI>> dijQ;
const int MN = 1002;
const LL INF = 1e18 + 3;
LL T[MN][2];
int val[MN], weigh[MN];
void prefill(int m) {
rep(i, 1, m) {
T[i][0] = INF;
T[i][1] = INF;
}
}
void Move(int m) {
rep(i, 0, m) {
T[i][0] = min(T[i][0], T[i][1]);
T[i][1] = INF;
}
}
int main() {
MAGICLINE;
int n, m;
scanf("%d %d", &n, &m);
prefill(MN);
rep(i, 1, n + 1) scanf("%d %d", &weigh[i], &val[i]);
rep(j, 1, n + 1) {
rep(i, 1, MN) if (T[i - val[j]][0] + weigh[j] <= m) T[i][1] =
min(T[i][1], T[i - val[j]][0] + weigh[j]);
Move(MN);
}
int ans = -1;
rep(i, 0, MN) if (T[i][0] != INF) ans = i;
printf("%d\n", ans);
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define drep(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define MAGICLINE ios_base::sync_with_stdio(0)
#define pb push_back
#define mp make_pair
#define se second
#define fs first
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, int> PLI;
typedef priority_queue<int> PQI;
typedef priority_queue<LL> PQL;
typedef priority_queue<PLI, vector<PLI>, greater<PLI>> dijQ;
const int MN = 100002;
const LL INF = 1e18 + 3;
LL T[MN][2];
int val[MN], weigh[MN];
void prefill(int m) {
rep(i, 1, m) {
T[i][0] = INF;
T[i][1] = INF;
}
}
void Move(int m) {
rep(i, 0, m) {
T[i][0] = min(T[i][0], T[i][1]);
T[i][1] = INF;
}
}
int main() {
MAGICLINE;
int n, m;
scanf("%d %d", &n, &m);
prefill(MN);
rep(i, 1, n + 1) scanf("%d %d", &weigh[i], &val[i]);
rep(j, 1, n + 1) {
rep(i, 1, MN) if (T[i - val[j]][0] + weigh[j] <= m) T[i][1] =
min(T[i][1], T[i - val[j]][0] + weigh[j]);
Move(MN);
}
int ans = -1;
rep(i, 0, MN) if (T[i][0] != INF) ans = i;
printf("%d\n", ans);
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
0
| |
p03164
|
C++
|
Runtime Error
|
// {{{
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) \
for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) \
for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}
ll N, W;
ll w[101], v[101];
ll dp[101][100001];
void init() {}
void solve() {
FOR(i, 0, 100001) dp[1][i] = (i <= v[1] ? w[i] : LINF);
// FOR(i, 0, 100001){
// FOR(j, 1, N+1){
// if(i <= v[j]) dp[1][i] = min(dp[1][i], w[j]);
// }
// }
FOR(i, 2, N + 1) {
REP(j, 100001) {
dp[i][j] = dp[i - 1][j];
if (j - v[i] >= 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
}
}
}
REPR(i, 100000) {
if (dp[N][i] <= W) {
cout << i << endl;
break;
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> W;
FOR(i, 1, N + 1) cin >> w[i] >> v[i];
solve();
return 0;
}
// vim:set foldmethod=marker:
|
// {{{
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) \
for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) \
for (ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for (ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for (ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}
ll N, W;
ll w[101], v[101];
ll dp[101][100001];
void init() {}
void solve() {
FOR(i, 1, 100001) dp[1][i] = (i <= v[1] ? w[1] : LINF);
FOR(i, 2, N + 1) {
REP(j, 100001) {
dp[i][j] = dp[i - 1][j];
if (j - v[i] >= 0) {
dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]);
}
}
}
REPR(i, 100000) {
if (dp[N][i] <= W) {
cout << i << endl;
break;
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> W;
FOR(i, 1, N + 1) cin >> w[i] >> v[i];
solve();
return 0;
}
// vim:set foldmethod=marker:
|
replace
| 55 | 61 | 55 | 56 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
// fastio
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll n, W;
cin >> n >> W;
ll weg[n];
ll val[n];
ll sum = 0;
for (ll i = 0; i < n; i++) {
cin >> weg[i] >> val[i];
sum += val[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, 1000000000));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= sum; j++) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
if (j >= val[i])
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - val[i]] + weg[i]);
}
}
/*
for(int i=0;i<=n;i++){
for(int j=0;j<=sum;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}
//*/
ll ans = 0;
for (int i = 0; i <= sum; i++) {
if (dp[n][i] <= W) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
int main() {
// fastio
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, W;
cin >> n >> W;
ll weg[n];
ll val[n];
ll sum = 0;
for (ll i = 0; i < n; i++) {
cin >> weg[i] >> val[i];
sum += val[i];
}
vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, 1000000000));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= sum; j++) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
if (j >= val[i])
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - val[i]] + weg[i]);
}
}
/*
for(int i=0;i<=n;i++){
for(int j=0;j<=sum;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}
//*/
ll ans = 0;
for (int i = 0; i <= sum; i++) {
if (dp[n][i] <= W) {
ans = i;
}
}
cout << ans << endl;
return 0;
}
|
delete
| 10 | 15 | 10 | 10 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll long long
#define INF 10000000000000000LL
#define pll pair<long long, long long>
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
const int TOT_PRIMES = 19;
const int MAX_A = 70;
using namespace std;
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
ll n, w;
cin >> n >> w;
ll tot = 0;
ll cost[n + 1], wt[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wt[i] >> cost[i];
tot = tot + cost[i];
}
ll dp[n + 1][tot + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= tot; j++) {
dp[i][j] = INF;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= tot; j++) {
if (j == 0)
dp[i][j] = 0;
else if (i == 1) {
if (j == cost[i])
dp[i][j] = wt[i];
else
dp[i][j] = INF;
} else {
if (j - cost[i] >= 0)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - cost[i]] + wt[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
for (int i = tot; i >= 0; i--) {
// cout<<dp[n][i]<<" ";
if (dp[n][i] <= w) {
cout << i;
return 0;
}
}
}
|
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll long long
#define INF 10000000000000000LL
#define pll pair<long long, long long>
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
const int TOT_PRIMES = 19;
const int MAX_A = 70;
using namespace std;
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen("inp.txt" ,"r", stdin );
// freopen("out.txt", "w", stdout);
// #endif
ll n, w;
cin >> n >> w;
ll tot = 0;
ll cost[n + 1], wt[n + 1];
for (int i = 1; i <= n; i++) {
cin >> wt[i] >> cost[i];
tot = tot + cost[i];
}
ll dp[n + 1][tot + 1];
for (int i = 0; i <= n; i++)
for (int j = 0; j <= tot; j++) {
dp[i][j] = INF;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= tot; j++) {
if (j == 0)
dp[i][j] = 0;
else if (i == 1) {
if (j == cost[i])
dp[i][j] = wt[i];
else
dp[i][j] = INF;
} else {
if (j - cost[i] >= 0)
dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - cost[i]] + wt[i]);
else
dp[i][j] = dp[i - 1][j];
}
}
}
for (int i = tot; i >= 0; i--) {
// cout<<dp[n][i]<<" ";
if (dp[n][i] <= w) {
cout << i;
return 0;
}
}
}
|
replace
| 16 | 20 | 16 | 20 |
-11
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define llt long long int
#define pb push_back
#define pii pair<int, int>
#define mk make_pair
#define ff first
#define ss second
#define mod 1000000007
int dp[101][100001];
bool cmp(pii a, pii b) {
if (a.ss < b.ss)
return false;
else if (a.ss == b.ss) {
if (a.ff < b.ff)
return false;
}
return true;
}
int32_t main() {
int n, w, x, y;
cin >> n >> w;
vector<pii> v;
for (int i = 0; i < n; i++) {
cin >> x >> y;
v.pb(mk(x, y));
}
sort(v.begin(), v.end(), cmp);
/* for(int i=0;i<n;i++){
cout<<v[i].ff<<" "<<v[i].ss<<endl;
}*/
memset(dp, 0, sizeof dp);
int mx = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 100001; j++) {
if (v[i - 1].ss > j) {
dp[i][j] = dp[i - 1][j];
} else if (v[i - 1].ss == j) {
if (dp[i - 1][j] == 0)
dp[i][j] = v[i - 1].ff;
else
dp[i][j] =
min(dp[i - 1][j - v[i - 1].ss] + v[i - 1].ff, dp[i - 1][j]);
} else {
if (dp[i - 1][j - v[i - 1].ss] != 0) {
if (dp[i - 1][j] == 0)
dp[i][j] = dp[i - 1][j - v[i - 1].ss] + v[i - 1].ff;
else
dp[i][j] =
min(dp[i - 1][j - v[i - 1].ss] + v[i - 1].ff, dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
if (dp[i][j] <= w && dp[i][j] != 0)
mx = max(mx, j);
}
}
cout << mx;
/*for(int i=0;i<=n;i++){
for(int j=0;j<40;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define pii pair<int, int>
#define mk make_pair
#define ff first
#define ss second
#define mod 1000000007
int dp[101][100001];
bool cmp(pii a, pii b) {
if (a.ss < b.ss)
return false;
else if (a.ss == b.ss) {
if (a.ff < b.ff)
return false;
}
return true;
}
int32_t main() {
int n, w, x, y;
cin >> n >> w;
vector<pii> v;
for (int i = 0; i < n; i++) {
cin >> x >> y;
v.pb(mk(x, y));
}
sort(v.begin(), v.end(), cmp);
/* for(int i=0;i<n;i++){
cout<<v[i].ff<<" "<<v[i].ss<<endl;
}*/
memset(dp, 0, sizeof dp);
int mx = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j < 100001; j++) {
if (v[i - 1].ss > j) {
dp[i][j] = dp[i - 1][j];
} else if (v[i - 1].ss == j) {
if (dp[i - 1][j] == 0)
dp[i][j] = v[i - 1].ff;
else
dp[i][j] =
min(dp[i - 1][j - v[i - 1].ss] + v[i - 1].ff, dp[i - 1][j]);
} else {
if (dp[i - 1][j - v[i - 1].ss] != 0) {
if (dp[i - 1][j] == 0)
dp[i][j] = dp[i - 1][j - v[i - 1].ss] + v[i - 1].ff;
else
dp[i][j] =
min(dp[i - 1][j - v[i - 1].ss] + v[i - 1].ff, dp[i - 1][j]);
} else {
dp[i][j] = dp[i - 1][j];
}
}
if (dp[i][j] <= w && dp[i][j] != 0)
mx = max(mx, j);
}
}
cout << mx;
/*for(int i=0;i<=n;i++){
for(int j=0;j<40;j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}*/
return 0;
}
|
replace
| 2 | 3 | 2 | 3 |
0
| |
p03164
|
C++
|
Runtime Error
|
// template {{{
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
using ld = long double;
using ll = long long;
inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}
const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9 + 7;
const int V = 100500;
ll dp[V];
void solve() {
int n, W;
cin >> n >> W;
fill(dp + 1, dp + V, INFL);
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
for (int j = V - 1; j >= 0; j--) {
if (dp[j - v] + w <= W)
dp[j] = min(dp[j], dp[j - v] + w);
}
}
for (int i = V - 1; i >= 0; i--) {
if (dp[i] <= W) {
cout << i << endl;
return;
}
}
}
// main {{{
int main() {
cin.sync_with_stdio(0);
cin.tie(NULL);
solve();
return 0;
}
inline ll addm(ll __a, ll __b, ll __m = MOD) { return ((__a + __b) % __m); }
inline ll subm(ll __a, ll __b, ll __m = MOD) {
return (((__a - __b) % __m + __m) % __m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) { return ((__a * __b) % __m); }
ll powm(ll __a, ll __b, ll __m = MOD) {
ll ret = (!__b) ? 1 : powm(__a, __b / 2, __m);
return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b % 2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) { return powm(__x, __m - 2, __m); }
// }}}
|
// template {{{
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
using ld = long double;
using ll = long long;
inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}
const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9 + 7;
const int V = 100500;
ll dp[V];
void solve() {
int n, W;
cin >> n >> W;
fill(dp + 1, dp + V, INFL);
for (int i = 0; i < n; i++) {
int w, v;
cin >> w >> v;
for (int j = V - 1; j >= v; j--) {
if (dp[j - v] + w <= W)
dp[j] = min(dp[j], dp[j - v] + w);
}
}
for (int i = V - 1; i >= 0; i--) {
if (dp[i] <= W) {
cout << i << endl;
return;
}
}
}
// main {{{
int main() {
cin.sync_with_stdio(0);
cin.tie(NULL);
solve();
return 0;
}
inline ll addm(ll __a, ll __b, ll __m = MOD) { return ((__a + __b) % __m); }
inline ll subm(ll __a, ll __b, ll __m = MOD) {
return (((__a - __b) % __m + __m) % __m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) { return ((__a * __b) % __m); }
ll powm(ll __a, ll __b, ll __m = MOD) {
ll ret = (!__b) ? 1 : powm(__a, __b / 2, __m);
return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b % 2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) { return powm(__x, __m - 2, __m); }
// }}}
|
replace
| 32 | 33 | 32 | 33 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;
ll n, w;
ll a[mnx];
ll b[mnx];
ll dp[mnx];
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
fill(dp, dp + mnx, mod);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 200000; j >= 0; j--) {
if (dp[j - b[i]] != mod)
dp[j] = min(dp[j], dp[j - b[i]] + a[i]);
}
}
ll ans = 0;
for (int i = 0; i <= 200000; i++) {
if (dp[i] <= w)
ans = i;
}
cout << ans << '\n';
return 0;
}
/*
3
10 40 70
20 50 80
30 60 90
10 40 70
90 120 120
150 180 210
*/
|
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;
ll n, w;
ll a[mnx];
ll b[mnx];
ll dp[mnx];
int main() {
cin >> n >> w;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
fill(dp, dp + mnx, mod);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 200000; j >= 0; j--) {
if (dp[j] != mod)
dp[j + b[i]] = min(dp[j + b[i]], dp[j] + a[i]);
}
}
ll ans = 0;
for (int i = 0; i <= 200000; i++) {
if (dp[i] <= w)
ans = i;
}
cout << ans << '\n';
return 0;
}
/*
3
10 40 70
20 50 80
30 60 90
10 40 70
90 120 120
150 180 210
*/
|
replace
| 26 | 28 | 26 | 28 |
0
| |
p03164
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define f(n) for (ll i = 0; i < n; i++)
#define fn(a, n) for (ll a = 0; a < n; a++)
#define flr(a, l, r) for (ll a = l; a <= r; a++)
#define mp make_pair
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define vec std::vector<ll>
#define vp std::vector<pair<ll, ll>>
#define all(a) a.begin(), a.end()
#define inf (long long)1e18
#define infi (int)1e9
#define endl '\n'
#define ff(a, b) \
for (ll i = 0; i < a; i++) \
for (ll j = 0; j < b; j++)
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define vvl vector<vector<ll>>
#define vvc std::vector<std::vector<char>>
#define vvi std::vector<std::vector<int>>
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define graph(n) vvl g(n + 1, vector<ll>(0));
#define in(a, n) \
vec a(n); \
f(n) cin >> a[i];
#define MOD 1000000007
#define MODLL 1000000000000000007
using namespace std;
void print_width(ll x) {
std::cout << std::fixed;
std::cout << std::setprecision(x);
}
ll power(ll x, ll y, ll p = MOD) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
void printArr(ll a[], ll n) {
f(n) cout << a[i] << " ";
cout << endl;
}
void printVector(std::vector<ll> v) {
f(v.size()) cout << v[i] << " ";
cout << endl;
}
void printVectorPair(std::vector<pair<ll, ll>> v) {
f(v.size()) pp2(v[i].first, v[i].second);
cout << endl;
}
void initialize(ll arr[], ll n) {
for (ll i = 0; i <= n; i++)
arr[i] = i;
}
ll root(ll arr[], ll i) {
while (arr[i] != i) {
arr[i] = arr[arr[i]];
i = arr[i];
}
return i;
}
void Union(ll arr[], ll a, ll b) {
ll root_a = root(arr, a);
ll root_b = root(arr, b);
arr[root_a] = root_b;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power_wm(ll x, ll y) {
ll res = 1; // Initialize result
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x);
// y must be even now
y = y >> 1; // y = y/2
x = (x * x);
}
return res;
}
std::vector<ll> vsum(std::vector<ll> a) {
std::vector<ll> s(a.size());
s[0] = a[0];
flr(i, 1, a.size() - 1) { s[i] = s[i - 1] + a[i]; }
return s;
}
void time() {
#ifndef ONLINE_JUDGE
cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}
ll sti(string s) {
ll ans = 0;
ll p = 1;
for (ll i = s.size() - 1; i >= 0; i--) {
ans = (ans + ((ll)(s[i] - '0') * p) % MOD) % MOD;
p = (p * 10) % MOD;
}
return ans;
}
int main() {
// Using text files for input output
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
// FastIO
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// start your code here
// print_width(15);
ll n, w;
cin >> n >> w;
vec dp(200000 + 1, inf);
f(n) {
ll wt, val;
cin >> wt >> val;
for (ll j = 200000; j >= 0; j--) {
if ((j - val) >= 0)
dp[j] = min(wt + dp[j - val], dp[j]);
else
dp[j] = min(wt, dp[j]);
}
}
// printVector(dp);
ll ans = -1;
f(200000) {
if (dp[i] <= w)
ans = i;
}
cout << ans + 1;
// time();
return 0;
}
|
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:2000000")
#pragma comment(linker, "/HEAP:2000000")
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define f(n) for (ll i = 0; i < n; i++)
#define fn(a, n) for (ll a = 0; a < n; a++)
#define flr(a, l, r) for (ll a = l; a <= r; a++)
#define mp make_pair
#define sorta(a) sort(a.begin(), a.end());
#define sortd(a) sort(a.begin(), a.end(), greater<ll>());
#define sortdp(a) sort(a.begin(), a.end(), greater<pair<ll, ll>>());
#define vec std::vector<ll>
#define vp std::vector<pair<ll, ll>>
#define all(a) a.begin(), a.end()
#define inf (long long)1e18
#define infi (int)1e9
#define endl '\n'
#define ff(a, b) \
for (ll i = 0; i < a; i++) \
for (ll j = 0; j < b; j++)
#define pp1(a) cout << a << endl;
#define pp2(a, b) cout << a << " " << b << endl;
#define pp3(a, b, c) cout << a << " " << b << " " << c << endl;
#define pp4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl;
#define vvl vector<vector<ll>>
#define vvc std::vector<std::vector<char>>
#define vvi std::vector<std::vector<int>>
#define blb(a, b) lower_bound(all(a), b) - a.begin();
#define bub(a, b) upper_bound(all(a), b) - a.begin();
#define graph(n) vvl g(n + 1, vector<ll>(0));
#define in(a, n) \
vec a(n); \
f(n) cin >> a[i];
#define MOD 1000000007
#define MODLL 1000000000000000007
using namespace std;
void print_width(ll x) {
std::cout << std::fixed;
std::cout << std::setprecision(x);
}
ll power(ll x, ll y, ll p = MOD) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
// equal to p
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x) % p;
// y must be even now
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
void printArr(ll a[], ll n) {
f(n) cout << a[i] << " ";
cout << endl;
}
void printVector(std::vector<ll> v) {
f(v.size()) cout << v[i] << " ";
cout << endl;
}
void printVectorPair(std::vector<pair<ll, ll>> v) {
f(v.size()) pp2(v[i].first, v[i].second);
cout << endl;
}
void initialize(ll arr[], ll n) {
for (ll i = 0; i <= n; i++)
arr[i] = i;
}
ll root(ll arr[], ll i) {
while (arr[i] != i) {
arr[i] = arr[arr[i]];
i = arr[i];
}
return i;
}
void Union(ll arr[], ll a, ll b) {
ll root_a = root(arr, a);
ll root_b = root(arr, b);
arr[root_a] = root_b;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
ll power_wm(ll x, ll y) {
ll res = 1; // Initialize result
while (y > 0) {
// If y is odd, multiply x with result
if (y & 1)
res = (res * x);
// y must be even now
y = y >> 1; // y = y/2
x = (x * x);
}
return res;
}
std::vector<ll> vsum(std::vector<ll> a) {
std::vector<ll> s(a.size());
s[0] = a[0];
flr(i, 1, a.size() - 1) { s[i] = s[i - 1] + a[i]; }
return s;
}
void time() {
#ifndef ONLINE_JUDGE
cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}
ll sti(string s) {
ll ans = 0;
ll p = 1;
for (ll i = s.size() - 1; i >= 0; i--) {
ans = (ans + ((ll)(s[i] - '0') * p) % MOD) % MOD;
p = (p * 10) % MOD;
}
return ans;
}
int main() {
// FastIO
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// start your code here
// print_width(15);
ll n, w;
cin >> n >> w;
vec dp(200000 + 1, inf);
f(n) {
ll wt, val;
cin >> wt >> val;
for (ll j = 200000; j >= 0; j--) {
if ((j - val) >= 0)
dp[j] = min(wt + dp[j - val], dp[j]);
else
dp[j] = min(wt, dp[j]);
}
}
// printVector(dp);
ll ans = -1;
f(200000) {
if (dp[i] <= w)
ans = i;
}
cout << ans + 1;
// time();
return 0;
}
|
delete
| 154 | 160 | 154 | 154 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.