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> using namespace std; #define MOD 1000000007 int main() { int N, W; cin >> N >> W; vector<long long> weight(N), value(N); long long sum = 0; for (int i = 0; i < N; i++) { cin >> weight.at(i) >> value.at(i); sum += value.at(i); } long long dp[110][1100]; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum; j++) { dp[i][j] = 1LL << 60; } } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum; j++) { if (j >= value[i]) { dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]); } else { dp[i + 1][j] = dp[i][j]; } } } long long ans = 0; for (long long i = 0; i <= sum; i++) { if (dp[N][i] <= W) ans = max(ans, i); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int main() { int N, W; cin >> N >> W; vector<long long> weight(N), value(N); long long sum = 0; for (int i = 0; i < N; i++) { cin >> weight.at(i) >> value.at(i); sum += value.at(i); } long long dp[110][sum + 1]; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum; j++) { dp[i][j] = 1LL << 60; } } dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum; j++) { if (j >= value[i]) { dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + weight[i]); } else { dp[i + 1][j] = dp[i][j]; } } } long long ans = 0; for (long long i = 0; i <= sum; i++) { if (dp[N][i] <= W) ans = max(ans, i); } cout << ans << endl; }
replace
16
17
16
17
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define s(x) (x).begin(), (x).end(); using namespace std; typedef long long ll; 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; int main() { int N, W; cin >> N >> W; ll weight[110], varue[110]; rep(i, N) cin >> weight[i] >> varue[i]; ll max_v = 110000; ll dp[110][max_v]; rep(i, max_v) { rep(j, 110000) dp[i][j] = 1000000; } dp[0][0] = 0; rep(i, N) { rep(j, max_v) { if (j >= varue[i]) chmin(dp[i + 1][j], dp[i][j - varue[i]] + weight[i]); chmin(dp[i + 1][j], dp[i][j]); } } ll ans = 0; rep(i, max_v) { if (dp[N][i] <= W) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define s(x) (x).begin(), (x).end(); using namespace std; typedef long long ll; 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; int main() { int N, W; cin >> N >> W; ll weight[110], varue[110]; rep(i, N) cin >> weight[i] >> varue[i]; ll max_v = 110000; ll dp[110][max_v]; rep(i, 110) { rep(j, max_v) dp[i][j] = INF; } dp[0][0] = 0; rep(i, N) { rep(j, max_v) { if (j >= varue[i]) chmin(dp[i + 1][j], dp[i][j - varue[i]] + weight[i]); chmin(dp[i + 1][j], dp[i][j]); } } ll ans = 0; rep(i, max_v) { if (dp[N][i] <= W) ans = i; } cout << ans << endl; }
replace
31
32
31
32
-11
p03164
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <string> #include <unordered_map> #include <vector> using namespace std; const long long kInf = (long long)1e13; int main() { int n, W; cin >> n >> W; vector<long long> w(n), v(n); long long sum = 0; for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; sum += v[i]; } vector<vector<long long>> dp(n + 1, vector<long long>(sum + 1, kInf)); for (int i = 0; i <= n; ++i) { dp[i][0] = 0; } for (int val = 1; val <= sum; ++val) { for (int i = 1; i <= n; ++i) { dp[i][val] = min(dp[i - 1][val], dp[i - 1][val - v[i - 1]] + w[i - 1]); } } for (int val = sum; val >= 0; --val) { if (dp[n][val] <= W) { cout << val << endl; break; } } }
#include <algorithm> #include <iostream> #include <map> #include <string> #include <unordered_map> #include <vector> using namespace std; const long long kInf = (long long)1e13; int main() { int n, W; cin >> n >> W; vector<long long> w(n), v(n); long long sum = 0; for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; sum += v[i]; } vector<vector<long long>> dp(n + 1, vector<long long>(sum + 1, kInf)); for (int i = 0; i <= n; ++i) { dp[i][0] = 0; } for (int val = 1; val <= sum; ++val) { for (int i = 1; i <= n; ++i) { dp[i][val] = dp[i - 1][val]; if (val - v[i - 1] >= 0) { dp[i][val] = min(dp[i][val], dp[i - 1][val - v[i - 1]] + w[i - 1]); } } } for (int val = sum; val >= 0; --val) { if (dp[n][val] <= W) { cout << val << endl; break; } } }
replace
28
29
28
32
0
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int N, W; long long int A[MAXN], P[MAXN]; map<long long int, long long int> dp; deque<pair<long long int, long long int>> buffer; long long int calcDP() { for (int i = 0; i < N; i++) { map<long long int, long long int>::reverse_iterator it = dp.rbegin(); for (; it != dp.rend(); it++) { long long int weight = it->first; long long int value = it->second; if (weight + P[i] <= W && dp[weight] + A[i] > dp[weight + P[i]]) buffer.push_back({weight + P[i], dp[weight] + A[i]}); } dp[P[i]] = A[i]; while (!buffer.empty()) { dp[buffer.front().first] = buffer.front().second; buffer.pop_front(); } } long long int sol = 0; for (auto adj : dp) { sol = max(sol, adj.second); } return sol; } int main() { cin >> N >> W; for (int i = 0; i < N; i++) cin >> P[i] >> A[i]; cout << calcDP(); }
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int N, W; long long int A[MAXN], P[MAXN]; map<long long int, long long int> dp; deque<pair<long long int, long long int>> buffer; long long int calcDP() { for (int i = 0; i < N; i++) { map<long long int, long long int>::reverse_iterator it = dp.rbegin(); for (; it != dp.rend(); it++) { long long int weight = it->first; long long int value = it->second; if (weight + P[i] <= W && dp[weight] + A[i] > dp[weight + P[i]]) buffer.push_back({weight + P[i], dp[weight] + A[i]}); } dp[P[i]] = A[i]; while (!buffer.empty()) { dp[buffer.front().first] = buffer.front().second; buffer.pop_front(); } map<long long int, long long int>::iterator firstIt = dp.begin(); firstIt++; map<long long int, long long int>::iterator secondIt = dp.begin(); for (; firstIt != dp.end();) { if (firstIt->second <= secondIt->second) { map<long long int, long long int>::iterator tmp = firstIt; firstIt++; dp.erase(tmp); } else firstIt++, secondIt++; } } long long int sol = 0; for (auto adj : dp) { sol = max(sol, adj.second); } return sol; } int main() { cin >> N >> W; for (int i = 0; i < N; i++) cin >> P[i] >> A[i]; cout << calcDP(); }
insert
23
23
23
34
TLE
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int n; long long int w[200], v[200]; long long int dp[200][100006]; long long int sum = 0, W; long long int knapsack(int i, int v1) { if (v1 <= 0) return 0; if (i == n) { return INT_MAX; } // long long int res1=0,res2=0; // // if(dp[i][v1]!=-1) // return dp[i][v1]; // if(v1-v[i]>=0) // res1=w[i]+knapsack(i+1,v1-v[i]); // res2=knapsack(i+1,v1); // cout<<i<<" "<<res1<<" "<<res2<<" "; // cout<<min(res1,res2)<<endl; return dp[i][v1] = min(w[i] + knapsack(i + 1, v1 - v[i]), knapsack(i + 1, v1)); } int main() { memset(dp, -1, sizeof dp); cin >> n >> W; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; sum += v[i]; } // cout<<knapsack(0,0)<<endl; for (int i = sum; i >= 0; i--) { long long int k1 = knapsack(0, i); // cout<<k1<<endl; if (k1 <= W) { cout << i << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; int n; long long int w[200], v[200]; long long int dp[200][100006]; long long int sum = 0, W; long long int knapsack(int i, int v1) { if (v1 <= 0) return 0; if (i == n) { return INT_MAX; } // long long int res1=0,res2=0; // if (dp[i][v1] != -1) return dp[i][v1]; // if(v1-v[i]>=0) // res1=w[i]+knapsack(i+1,v1-v[i]); // res2=knapsack(i+1,v1); // cout<<i<<" "<<res1<<" "<<res2<<" "; // cout<<min(res1,res2)<<endl; return dp[i][v1] = min(w[i] + knapsack(i + 1, v1 - v[i]), knapsack(i + 1, v1)); } int main() { memset(dp, -1, sizeof dp); cin >> n >> W; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; sum += v[i]; } // cout<<knapsack(0,0)<<endl; for (int i = sum; i >= 0; i--) { long long int k1 = knapsack(0, i); // cout<<k1<<endl; if (k1 <= W) { cout << i << endl; break; } } return 0; }
replace
17
19
17
19
TLE
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define all(x) (x).begin(), (x).end() #define endl '\n' const ll inf = LLONG_MAX; long double pi = M_PI; void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } int main() { ll n, w; cin >> n >> w; vll ww(n), v(n); for (ll i = 0; i < n; i++) cin >> ww[i] >> v[i]; vector<vll> dp(n, vll(1e5 + 1, inf)); dp[0][0] = 0; for (ll i = 1; i <= 1e5; i++) { if (i <= v[0]) dp[0][i] = ww[0]; else break; } for (ll i = 1; i < n; i++) { dp[i] = dp[i - 1]; for (ll j = 1; j <= 1e5; j++) { if (dp[i - 1][max(0ll, j - v[i])] < inf) { dp[i][j] = min(dp[i][j], dp[i - 1][max(0ll, j - v[i])] + ww[i]); } } } for (ll i = 0; i <= 1e5; i++) { if (dp[n - 1][i] > w) { cout << i - 1 << endl; return 0; } } while (1) { cout << 0 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define all(x) (x).begin(), (x).end() #define endl '\n' const ll inf = LLONG_MAX; long double pi = M_PI; void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } int main() { ll n, w; cin >> n >> w; vll ww(n), v(n); for (ll i = 0; i < n; i++) cin >> ww[i] >> v[i]; vector<vll> dp(n, vll(1e5 + 1, inf)); dp[0][0] = 0; for (ll i = 1; i <= 1e5; i++) { if (i <= v[0]) dp[0][i] = ww[0]; else break; } for (ll i = 1; i < n; i++) { dp[i] = dp[i - 1]; for (ll j = 1; j <= 1e5; j++) { if (dp[i - 1][max(0ll, j - v[i])] < inf) { dp[i][j] = min(dp[i][j], dp[i - 1][max(0ll, j - v[i])] + ww[i]); } } } for (ll i = 0; i <= 1e5; i++) { if (dp[n - 1][i] > w) { cout << i - 1 << endl; return 0; } } cout << 1e5 << endl; }
replace
42
45
42
43
TLE
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define mod 1000000007 #define inf 1e18L using namespace std; typedef long long int ll; ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } void memset(int *arr, int n, int value) { for (int i = 0; i < n; i++) { arr[i] = value; } } void knapsack(ll *weight, ll *values, ll n, ll W, int val_sum, ll **dp) { for (int i = 1; i <= n; i++) { for (int j = 1; j < val_sum; j++) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - values[i - 1]] + weight[i - 1]); } } ll ans = inf; for (int i = 0; i < val_sum; i++) { if (dp[n][i] <= W) { ans = i; } } /*for(int i= 0 ; i<=n ; i++) { for(int j = 0; j<=val_sum ; j++) { cout<<dp[i][j]<<" "; } cout<<endl; }*/ cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, W; cin >> n >> W; ll *weight = new ll[n]; ll *values = new ll[n]; for (int i = 0; i < n; i++) { cin >> weight[i] >> values[i]; } int val_sum = 0; for (int i = 0; i < n; i++) { val_sum += values[i]; } val_sum += 1; ll **dp = new ll *[n + 1]; for (int i = 0; i <= n; i++) { dp[i] = new ll[val_sum]; for (int k = 0; k < val_sum; k++) { dp[i][k] = inf; } } dp[0][0] = 0; for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i < val_sum; i++) { dp[0][i] = inf; } knapsack(weight, values, n, W, val_sum, dp); return 0; }
#include <bits/stdc++.h> #define mod 1000000007 #define inf 1e18L using namespace std; typedef long long int ll; ll max(ll a, ll b) { return (a > b) ? a : b; } ll min(ll a, ll b) { return (a < b) ? a : b; } void memset(int *arr, int n, int value) { for (int i = 0; i < n; i++) { arr[i] = value; } } void knapsack(ll *weight, ll *values, ll n, ll W, int val_sum, ll **dp) { for (int i = 1; i <= n; i++) { for (int j = 1; j < val_sum; j++) { dp[i][j] = dp[i - 1][j]; if (values[i - 1] <= j) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - values[i - 1]] + weight[i - 1]); } } } ll ans = inf; for (int i = 0; i < val_sum; i++) { if (dp[n][i] <= W) { ans = i; } } /*for(int i= 0 ; i<=n ; i++) { for(int j = 0; j<=val_sum ; j++) { cout<<dp[i][j]<<" "; } cout<<endl; }*/ cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, W; cin >> n >> W; ll *weight = new ll[n]; ll *values = new ll[n]; for (int i = 0; i < n; i++) { cin >> weight[i] >> values[i]; } int val_sum = 0; for (int i = 0; i < n; i++) { val_sum += values[i]; } val_sum += 1; ll **dp = new ll *[n + 1]; for (int i = 0; i <= n; i++) { dp[i] = new ll[val_sum]; for (int k = 0; k < val_sum; k++) { dp[i][k] = inf; } } dp[0][0] = 0; for (int i = 0; i <= n; i++) { dp[i][0] = 0; } for (int i = 1; i < val_sum; i++) { dp[0][i] = inf; } knapsack(weight, values, n, W, val_sum, dp); return 0; }
replace
17
19
17
22
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) ll dp[102][1002]; ll n, w; ll weight[100002], val[100002]; ll solve(ll r, ll idx) { if (idx == n) return r == 0 ? 0 : INT_MAX; if (dp[idx][r] != -1) return dp[idx][r]; ll ans = solve(r, idx + 1); if (val[idx] <= r) ans = min(ans, weight[idx] + solve(r - val[idx], idx + 1)); return dp[idx][r] = ans; } ll s(ll v_max) { for (ll i = v_max; i >= 0; i--) { if (solve(i, 0) <= w) return i; } return 0; } int main() { cin >> n >> w; ll max_value = 0; for (ll i = 0; i < n; i++) { cin >> weight[i] >> val[i]; max_value += val[i]; } memset(dp, -1, sizeof(dp)); cout << s(max_value); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) ll dp[102][100002]; ll n, w; ll weight[100002], val[100002]; ll solve(ll r, ll idx) { if (idx == n) return r == 0 ? 0 : INT_MAX; if (dp[idx][r] != -1) return dp[idx][r]; ll ans = solve(r, idx + 1); if (val[idx] <= r) ans = min(ans, weight[idx] + solve(r - val[idx], idx + 1)); return dp[idx][r] = ans; } ll s(ll v_max) { for (ll i = v_max; i >= 0; i--) { if (solve(i, 0) <= w) return i; } return 0; } int main() { cin >> n >> w; ll max_value = 0; for (ll i = 0; i < n; i++) { cin >> weight[i] >> val[i]; max_value += val[i]; } memset(dp, -1, sizeof(dp)); cout << s(max_value); return 0; }
replace
4
5
4
5
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define test() \ ull t; \ cin >> t; \ while (t--) #define pb push_back #define mkp make_pair #define nl cout << endl #define MOD 1000000007 #define loop(i, start, end) for (ll i = start; i < end; i++) #define N 100001 #define all(v) v.begin(), v.end() #define oa(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; \ nl #define ov(a) \ for (int i = 0; i < a.size(); i++) \ cout << a[i] << " "; \ nl int main() { fastio(); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ll n, w, smv; cin >> n >> w; vector<ll> a(n + 1), v(n + 1); for (int i = 0; i < n; i++) cin >> a[i + 1] >> v[i + 1], smv += v[i + 1]; vector<ll> dp(smv + 10, 1e18); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = smv - v[i]; j >= 0; j--) { dp[j + v[i]] = min(dp[j] + a[i], dp[j + v[i]]); } } for (int i = smv; i >= 0; i--) if (dp[i] <= w) { cout << i; return 0; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define test() \ ull t; \ cin >> t; \ while (t--) #define pb push_back #define mkp make_pair #define nl cout << endl #define MOD 1000000007 #define loop(i, start, end) for (ll i = start; i < end; i++) #define N 100001 #define all(v) v.begin(), v.end() #define oa(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; \ nl #define ov(a) \ for (int i = 0; i < a.size(); i++) \ cout << a[i] << " "; \ nl int main() { fastio(); ll n, w, smv; cin >> n >> w; vector<ll> a(n + 1), v(n + 1); for (int i = 0; i < n; i++) cin >> a[i + 1] >> v[i + 1], smv += v[i + 1]; vector<ll> dp(smv + 10, 1e18); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = smv - v[i]; j >= 0; j--) { dp[j + v[i]] = min(dp[j] + a[i], dp[j + v[i]]); } } for (int i = smv; i >= 0; i--) if (dp[i] <= w) { cout << i; return 0; } return 0; }
delete
29
33
29
29
-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; #define int long long int32_t main() { int n, W; cin >> n >> W; vector<int> weight(n), value(n); for (int i = 0; i < n; cin >> weight[i] >> value[i++]) ; int sum_val = 0; for (int i : value) sum_val += i; vector<int> dp(sum_val + 1, 1e9); dp[0] = 0; for (int i = 0; i < n; ++i) { for (int j = sum_val - value[i]; j >= 0; --j) { dp[j + value[i]] = min(dp[j + value[i]], dp[j] + weight[i]); } } int ans = 0; for (int i = 0; i <= sum_val; ++i) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n, W; cin >> n >> W; vector<int> weight(n), value(n); for (int i = 0; i < n; ++i) cin >> weight[i] >> value[i]; int sum_val = 0; for (int i : value) sum_val += i; vector<int> dp(sum_val + 1, 1e9); dp[0] = 0; for (int i = 0; i < n; ++i) { for (int j = sum_val - value[i]; j >= 0; --j) { dp[j + value[i]] = min(dp[j + value[i]], dp[j] + weight[i]); } } int ans = 0; for (int i = 0; i <= sum_val; ++i) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << "\n"; }
replace
9
11
9
11
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define maxx 100100 long long dp[100][maxx], peso[maxx], valor[maxx]; int main() { long long w; int n; cin >> n >> w; long long v = 0; for (int i = 1; i <= n; i++) { cin >> peso[i] >> valor[i]; v += valor[i]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= v + 10; j++) { dp[i][j] = 1e11; if (j == 0) dp[i][j] = 0; } } long long ans = 0; for (int i = 1; i <= n; i++) { for (long long j = 1; j <= v; j++) { if (j - valor[i] >= 0 && (dp[i - 1][j - valor[i]] + peso[i]) <= w) { ans = max(j, ans); dp[i][j] = min(peso[i] + dp[i - 1][j - valor[i]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } /* for(int i = 0; i <= n; i++){ for(int j = 0; j <= v; j++){ cout << dp[i][j] << " "; } cout << endl; }*/ cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define maxx 100100 long long dp[200][maxx], peso[200], valor[200]; int main() { long long w; int n; cin >> n >> w; long long v = 0; for (int i = 1; i <= n; i++) { cin >> peso[i] >> valor[i]; v += valor[i]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= v + 10; j++) { dp[i][j] = 1e11; if (j == 0) dp[i][j] = 0; } } long long ans = 0; for (int i = 1; i <= n; i++) { for (long long j = 1; j <= v; j++) { if (j - valor[i] >= 0 && (dp[i - 1][j - valor[i]] + peso[i]) <= w) { ans = max(j, ans); dp[i][j] = min(peso[i] + dp[i - 1][j - valor[i]], dp[i - 1][j]); } else dp[i][j] = dp[i - 1][j]; } } /* for(int i = 0; i <= n; i++){ for(int j = 0; j <= v; j++){ cout << dp[i][j] << " "; } cout << endl; }*/ cout << ans << endl; return 0; }
replace
3
4
3
4
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, W, w[101], v[101]; int dp[101][101010]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> W; rep(i, 0, N) cin >> w[i] >> v[i]; rep(i, 0, N + 1) rep(val, 0, N * 1010 + 1) dp[i][val] = inf; dp[0][0] = 0; rep(i, 0, N) rep(val, 0, N * 1010 + 1) { chmin(dp[i + 1][val], dp[i][val]); chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]); } int ans = 0; rep(val, 0, N * 1010 + 1) if (dp[N][val] <= W) chmax(ans, val); cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, W, w[101], v[101]; int dp[101][201010]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> W; rep(i, 0, N) cin >> w[i] >> v[i]; rep(i, 0, N + 1) rep(val, 0, N * 1010 + 1) dp[i][val] = inf; dp[0][0] = 0; rep(i, 0, N) rep(val, 0, N * 1010 + 1) { chmin(dp[i + 1][val], dp[i][val]); chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]); } int ans = 0; rep(val, 0, N * 1010 + 1) if (dp[N][val] <= W) chmax(ans, val); cout << ans << endl; }
replace
42
43
42
43
0
p03164
C++
Runtime Error
/*author* Priyanshu Shrivastav (from IIT Palakkad) * * *_ __ ___ _ ______ ___ _ ____ ___ ___| |_ * * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| * * | | | | | | | | (_| (_) | | | \ V /| | (__| |_ * * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| * When I wrote this, only God and I understood what I was doing ** * * * * * * * Now, only God knows * * * * * * */ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr) #define PREC \ cout.precision(10); \ cout << fixed #define bg(x) " [ " << #x << " : " << (x) << " ] " #define x first #define y second using ll = long long; using ff = long double; using pii = pair<int, int>; #define debug(args...) \ { \ /* WARNING : do NOT compile this debug func calls with following flags: // \ * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) { it->empty(); cerr << " (Line : " << __LINE__ << ")" << '\n'; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << fixed << setprecision(15) << " [ " << *it << " : " << a << " ] " << ' '; err(++it, args...); } const int N = 105, V = 1004; const ll inf = (ll)1e18; ll dp[N][V]; int n, mxv, W; int w[N], v[N]; void solve() { for (int i = 0; i <= n; ++i) for (int j = 0; j <= mxv; ++j) dp[i][j] = inf; dp[0][0] = 0; for (int i = 1; i <= n; ++i) for (int j = 0; j <= mxv; ++j) { dp[i][j] = dp[i - 1][j]; if (j >= v[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } int mx_val = 0; for (int i = mxv; i >= 0; --i) { if (dp[n][i] <= W) { mx_val = i; break; } } cout << mx_val << '\n'; } signed main() { IOS; PREC; cin >> n >> W; mxv = 0; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i], mxv += v[i]; solve(); return EXIT_SUCCESS; }
/*author* Priyanshu Shrivastav (from IIT Palakkad) * * *_ __ ___ _ ______ ___ _ ____ ___ ___| |_ * * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| * * | | | | | | | | (_| (_) | | | \ V /| | (__| |_ * * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| * When I wrote this, only God and I understood what I was doing ** * * * * * * * Now, only God knows * * * * * * */ #include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr) #define PREC \ cout.precision(10); \ cout << fixed #define bg(x) " [ " << #x << " : " << (x) << " ] " #define x first #define y second using ll = long long; using ff = long double; using pii = pair<int, int>; #define debug(args...) \ { \ /* WARNING : do NOT compile this debug func calls with following flags: // \ * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } void err(istream_iterator<string> it) { it->empty(); cerr << " (Line : " << __LINE__ << ")" << '\n'; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << fixed << setprecision(15) << " [ " << *it << " : " << a << " ] " << ' '; err(++it, args...); } const int N = 105, V = 1004; const ll inf = (ll)1e18; ll dp[N][N * V]; int n, mxv, W; int w[N], v[N]; void solve() { for (int i = 0; i <= n; ++i) for (int j = 0; j <= mxv; ++j) dp[i][j] = inf; dp[0][0] = 0; for (int i = 1; i <= n; ++i) for (int j = 0; j <= mxv; ++j) { dp[i][j] = dp[i - 1][j]; if (j >= v[i]) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i]] + w[i]); } int mx_val = 0; for (int i = mxv; i >= 0; --i) { if (dp[n][i] <= W) { mx_val = i; break; } } cout << mx_val << '\n'; } signed main() { IOS; PREC; cin >> n >> W; mxv = 0; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i], mxv += v[i]; solve(); return EXIT_SUCCESS; }
replace
50
51
50
51
0
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define _69e27 \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; const int N = 1e2 + 5, M = 1e5 + 5, oo = 0x3f3f3f3f, mod = 1e9 + 7; int n, w, arrw[N], arrv[N], mem[N][M], ans; int solve(int i, int v) { if (v == 0) return 0; if (i == n) return oo; int op1 = solve(i + 1, v); int op2 = oo; if (arrv[i] <= v) op2 = solve(i + 1, v - arrv[i]) + arrw[i]; return mem[i][v] = min(op1, op2); } int main() { _69e27 memset(mem, -1, sizeof mem); cin >> n >> w; for (int i = 0; i < n; i++) cin >> arrw[i] >> arrv[i]; for (int i = 1; i <= 100000; i++) { if (solve(0, i) <= w) ans = i; } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define _69e27 \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); using namespace std; const int N = 1e2 + 5, M = 1e5 + 5, oo = 0x3f3f3f3f, mod = 1e9 + 7; int n, w, arrw[N], arrv[N], mem[N][M], ans; int solve(int i, int v) { if (v == 0) return 0; if (i == n) return oo; if (mem[i][v] != -1) return mem[i][v]; int op1 = solve(i + 1, v); int op2 = oo; if (arrv[i] <= v) op2 = solve(i + 1, v - arrv[i]) + arrw[i]; return mem[i][v] = min(op1, op2); } int main() { _69e27 memset(mem, -1, sizeof mem); cin >> n >> w; for (int i = 0; i < n; i++) cin >> arrw[i] >> arrv[i]; for (int i = 1; i <= 100000; i++) { if (solve(0, i) <= w) ans = i; } cout << ans; return 0; }
insert
16
16
16
18
TLE
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long INF = 1000000001, n, k, w[200], c[200], dp[101][100001], ans, sum, minn = 1000000001; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> w[i] >> c[i]; minn = min(minn, c[i]); sum += c[i]; } dp[0][0] = 0; for (int i = 0; i <= n; i++) { for (int j = 1; j <= sum; j++) dp[i][j] = INF; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (j >= minn) { if (dp[i - 1][j - c[i]] != INF && j - c[i] >= 0) dp[i][j] = min(dp[i][j], dp[i - 1][j - c[i]] + w[i]); if (dp[i - 1][j] != INF && dp[i - 1][j]) dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } } for (int i = 1; i <= sum; i++) { if (dp[n][i] != INF && dp[n][i] <= k) ans = i; } cout << ans; }
#include <bits/stdc++.h> using namespace std; long long INF = 1000000001, n, k, w[200], c[200], dp[101][100001], ans, sum, minn = 1000000001; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> w[i] >> c[i]; minn = min(minn, c[i]); sum += c[i]; } dp[0][0] = 0; for (int i = 0; i <= n; i++) { for (int j = 1; j <= sum; j++) dp[i][j] = INF; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (j >= minn) { if (j - c[i] >= 0 && dp[i - 1][j - c[i]] != INF) dp[i][j] = min(dp[i][j], dp[i - 1][j - c[i]] + w[i]); if (dp[i - 1][j] != INF && dp[i - 1][j]) dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } } for (int i = 1; i <= sum; i++) { if (dp[n][i] != INF && dp[n][i] <= k) ans = i; } cout << ans; }
replace
19
20
19
20
0
p03164
C++
Runtime Error
// fahadmd16(IIEST Shibpur) #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pf push_front #define eb emplace_back #define mp make_pair #define ff first #define ss second #define db double #define pll pair<ll, ll> #define ALL(a) (a).begin(), (a).end() #define endl "\n" #define forn(i, n) for (ll i = 0; i < n; i++) #define forn1(i, n) for (ll i = 1; i < n; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define ford1(i, n) for (ll i = n - 1; i >= 1; i--) #define forab(i, a, b) for (ll i = a; i < b; i++) #define forabd(i, a, b) for (ll i = a; i >= b; i--) #define eps 1e-10 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define trace1(x) cout << #x << ": " << x << endl #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define tracen(x, n) \ { \ cout << (#x) << ":"; \ for (int i = 0; i < n; i++) \ cout << (#x) << "[" << i << "]:" << x[i] << " "; \ cout << endl; \ } #define tracenm(x, n, m) \ { \ cout << (#x) << endl; \ for (int i = 0; i < n; i++) { \ cout << "Row #" << i << ":"; \ for (int j = 0; j < m; j++) \ cout << x[i][j] << " "; \ cout << endl; \ } \ } using namespace std; const ll sz = 1e5 + 2; const ll mod = 1e9 + 7; const db PI = acos(-1); typedef vector<ll> VL; typedef vector<pll> VLL; typedef vector<vector<ll>> VVL; ll power(ll n, ll k, ll m) { ll ans = 1; while (k) { if (k & 1) ans = (ans * n) % m; k /= 2; n = (n * n) % m; } return ans; } const ll INF = 1e18L; ll dp[101][sz]; void solver() { ll n, w; cin >> n >> w; VLL a(n); forn(i, n) cin >> a[i].ff >> a[i].ss; ll sum_val = 0; forn(i, n) sum_val += a[i].ss; forn(i, n + 1) { forn(j, sum_val + 1) { if (j == 0) { dp[i][j] = 0; } else if (i == 0) { dp[i][j] = INF; } else { dp[i][j] = min((j - a[i - 1].ss >= 0) ? dp[i - 1][j - a[i - 1].ss] + a[i - 1].ff : INF, dp[i - 1][j]); } // trace3(i, j, dp[i][j]); } } ll ans = 0; forn(j, sum_val + 1) { if (dp[n][j] <= w) ans = j; } cout << ans << endl; // cout << "Case #" << test << ": " << ans << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; ll T = 1; // cin >> T; forn1(i, T + 1) { clock_t z = clock(); solver(); debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC); } return 0; }
// fahadmd16(IIEST Shibpur) #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pf push_front #define eb emplace_back #define mp make_pair #define ff first #define ss second #define db double #define pll pair<ll, ll> #define ALL(a) (a).begin(), (a).end() #define endl "\n" #define forn(i, n) for (ll i = 0; i < n; i++) #define forn1(i, n) for (ll i = 1; i < n; i++) #define ford(i, n) for (ll i = n - 1; i >= 0; i--) #define ford1(i, n) for (ll i = n - 1; i >= 1; i--) #define forab(i, a, b) for (ll i = a; i < b; i++) #define forabd(i, a, b) for (ll i = a; i >= b; i--) #define eps 1e-10 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define trace1(x) cout << #x << ": " << x << endl #define trace2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl #define tracen(x, n) \ { \ cout << (#x) << ":"; \ for (int i = 0; i < n; i++) \ cout << (#x) << "[" << i << "]:" << x[i] << " "; \ cout << endl; \ } #define tracenm(x, n, m) \ { \ cout << (#x) << endl; \ for (int i = 0; i < n; i++) { \ cout << "Row #" << i << ":"; \ for (int j = 0; j < m; j++) \ cout << x[i][j] << " "; \ cout << endl; \ } \ } using namespace std; const ll sz = 1e5 + 2; const ll mod = 1e9 + 7; const db PI = acos(-1); typedef vector<ll> VL; typedef vector<pll> VLL; typedef vector<vector<ll>> VVL; ll power(ll n, ll k, ll m) { ll ans = 1; while (k) { if (k & 1) ans = (ans * n) % m; k /= 2; n = (n * n) % m; } return ans; } const ll INF = 1e18L; ll dp[101][sz]; void solver() { ll n, w; cin >> n >> w; VLL a(n); forn(i, n) cin >> a[i].ff >> a[i].ss; ll sum_val = 0; forn(i, n) sum_val += a[i].ss; forn(i, n + 1) { forn(j, sum_val + 1) { if (j == 0) { dp[i][j] = 0; } else if (i == 0) { dp[i][j] = INF; } else { dp[i][j] = min((j - a[i - 1].ss >= 0) ? dp[i - 1][j - a[i - 1].ss] + a[i - 1].ff : INF, dp[i - 1][j]); } // trace3(i, j, dp[i][j]); } } ll ans = 0; forn(j, sum_val + 1) { if (dp[n][j] <= w) ans = j; } cout << ans << endl; // cout << "Case #" << test << ": " << ans << endl; } int main() { IOS; ll T = 1; // cin >> T; forn1(i, T + 1) { clock_t z = clock(); solver(); debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC); } return 0; }
replace
119
123
119
120
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define vi vector<ll> v #define vii vector<pair<ll, ll>> v #define pb push_back #define mod 1000000007 #define f(i, a, b) for (ll i = a; i < b; i++) #define while_ \ int t; \ cin >> t; \ while (t--) #define vmax 100000 using namespace std; ll dp[101][vmax + 1]; ll maxP(ll W, ll n, ll w[], ll v[]) { for (int i = 0; i <= vmax; i++) dp[0][i] = 1e18; dp[0][0] = 0; for (ll an = 1; an <= n; an++) { for (ll av = 0; av <= vmax; av++) { if (v[an - 1] > av) dp[an][av] = dp[an - 1][av]; else dp[an][av] = min(dp[an - 1][av], w[an - 1] + dp[an - 1][av - v[an - 1]]); } } ll ans = 0; f(i, 0, vmax + 1) if (dp[n][i] <= W) ans = i; return ans; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio ll n, W; cin >> n >> W; ll w[n], v[n]; f(i, 0, n) cin >> w[i] >> v[i]; cout << maxP(W, n, w, v); }
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define vi vector<ll> v #define vii vector<pair<ll, ll>> v #define pb push_back #define mod 1000000007 #define f(i, a, b) for (ll i = a; i < b; i++) #define while_ \ int t; \ cin >> t; \ while (t--) #define vmax 100000 using namespace std; ll dp[101][vmax + 1]; ll maxP(ll W, ll n, ll w[], ll v[]) { for (int i = 0; i <= vmax; i++) dp[0][i] = 1e18; dp[0][0] = 0; for (ll an = 1; an <= n; an++) { for (ll av = 0; av <= vmax; av++) { if (v[an - 1] > av) dp[an][av] = dp[an - 1][av]; else dp[an][av] = min(dp[an - 1][av], w[an - 1] + dp[an - 1][av - v[an - 1]]); } } ll ans = 0; f(i, 0, vmax + 1) if (dp[n][i] <= W) ans = i; return ans; } int main() { /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ fastio ll n, W; cin >> n >> W; ll w[n], v[n]; f(i, 0, n) cin >> w[i] >> v[i]; cout << maxP(W, n, w, v); }
replace
39
43
39
43
-11
p03164
C++
Time Limit Exceeded
/**Bismillahir Rahmanir Raheem Author:Refatul Fahad**/ #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ff first #define ss second #define pb push_back #define vi vector<int> #define pii pair<int, int> #define pil pair<int, ll> #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl '\n' #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() const int N = 1e5 + 5; const ll M = (ll)1e18; const double pi = 2 * acos(0.0); const double esp = 1e-9; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; ll cost[105], val[105], sum = 0ll; int main() { // IOS; /// freopen("input.txt","r",stdin); /// freopen("output.txt","w",stdout); int test = 1; // cin>>test; for (int cs = 1; cs <= test; ++cs) { int n, w, ans = 0; cin >> n >> w; for (int i = 1; i <= n; ++i) { cin >> cost[i] >> val[i]; sum += val[i]; } vector<ll> dp(sum + 1, M); dp[0] = 0; for (int i = 1; i <= n; ++i) { for (int j = sum - val[i]; i >= 0; --i) { dp[j + val[i]] = min(dp[j + val[i]], dp[i] + cost[i]); } } for (int i = 1; i <= sum; ++i) { if (dp[i] <= w) ans = max(ans, i); } cout << ans << endl; } return 0; }
/**Bismillahir Rahmanir Raheem Author:Refatul Fahad**/ #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ff first #define ss second #define pb push_back #define vi vector<int> #define pii pair<int, int> #define pil pair<int, ll> #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define endl '\n' #define sz(s) (int)s.size() #define all(s) s.begin(), s.end() const int N = 1e5 + 5; const ll M = (ll)1e18; const double pi = 2 * acos(0.0); const double esp = 1e-9; int Set(int N, int pos) { return N = N | (1 << pos); } int reset(int N, int pos) { return N = N & ~(1 << pos); } bool check(int N, int pos) { return (bool)(N & (1 << pos)); } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; ll cost[105], val[105], sum = 0ll; int main() { // IOS; /// freopen("input.txt","r",stdin); /// freopen("output.txt","w",stdout); int test = 1; // cin>>test; for (int cs = 1; cs <= test; ++cs) { int n, w, ans = 0; cin >> n >> w; for (int i = 1; i <= n; ++i) { cin >> cost[i] >> val[i]; sum += val[i]; } vector<ll> dp(sum + 1, M); dp[0] = 0; for (int i = 1; i <= n; ++i) { for (int j = sum - val[i]; j >= 0; --j) { dp[j + val[i]] = min(dp[j + val[i]], dp[j] + cost[i]); } } for (int i = 1; i <= sum; ++i) { if (dp[i] <= w) ans = max(ans, i); } cout << ans << endl; } return 0; }
replace
50
52
50
52
TLE
p03164
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; const ll MOD = 1000000007; const long long INF = 1LL << 60; const double pi = acos(-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; } vector<ll> v; vector<ll> w; vector<vector<ll>> table; ll dp(ll n, ll sv) { if (sv <= 0) return 0; if (n < 0) { return INF; } if (table.at(n).at(sv) < INF) return table.at(n).at(sv); chmin(table.at(n).at(sv), dp(n - 1, sv - v.at(n)) + w.at(n)); chmin(table.at(n).at(sv), dp(n - 1, sv)); return table.at(n).at(sv); } int main() { ll N, W; cin >> N >> W; v = vector<ll>(N); w = vector<ll>(N); rep(i, N) { cin >> w.at(i) >> v.at(i); } table = vector<vector<ll>>(N, vector<ll>(100001, INF)); for (int sv = 100000; sv >= 0; sv--) { if (dp(N - 1, sv) <= W) { cout << sv << endl; break; } } return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) using ll = long long; const ll MOD = 1000000007; const long long INF = 1LL << 60; const double pi = acos(-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; } vector<ll> v; vector<ll> w; vector<vector<ll>> table; ll dp(ll n, ll sv) { if (sv <= 0) return 0; if (n < 0) { return INF; } if (table.at(n).at(sv) < INF) return table.at(n).at(sv); chmin(table.at(n).at(sv), dp(n - 1, sv - v.at(n)) + w.at(n)); chmin(table.at(n).at(sv), dp(n - 1, sv)); chmin(table.at(n).at(sv), (ll)1000000001); return table.at(n).at(sv); } int main() { ll N, W; cin >> N >> W; v = vector<ll>(N); w = vector<ll>(N); rep(i, N) { cin >> w.at(i) >> v.at(i); } table = vector<vector<ll>>(N, vector<ll>(100001, INF)); for (int sv = 100000; sv >= 0; sv--) { if (dp(N - 1, sv) <= W) { cout << sv << endl; break; } } return 0; }
insert
38
38
38
39
TLE
p03164
C++
Runtime Error
#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> #define ll long long #define pb push_back #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define all(v) v.begin(), v.end() #define f first #define s second using namespace std; const ll V = 1e5; ll dp[105][V + 5]; std::vector<int> wt(105); std::vector<int> v(105); int main() { flash ll n, w; cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> wt[i] >> v[i]; } // std::vector<std::vector<int>> dp( n+1 , std::vector<int>(w+1,0)); for (int i = 0; i <= n; i++) { for (int j = 0; j <= V; j++) { dp[i][j] = -1; } } for (int i = 0; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= V; j++) { if (v[i - 1] > j) dp[i][j] = dp[i - 1][j]; else { ll w1 = dp[i - 1][j]; ll w2 = dp[i - 1][j - v[i]]; if (w1 == -1 && w2 == -1) { dp[i][j] = -1; } else if (w1 == -1) { dp[i][j] = w2 + wt[i]; } else if (w2 == -1) dp[i][j] = w1; else dp[i][j] = min(w2 + wt[i], w1); } } } ll result; for (int i = 0; i <= V; i++) { if (dp[n][i] == -1) continue; else if (dp[n][i] <= w) { // cout<<dp[n][i]<<endl; result = i; } } cout << result << "\n"; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> #define ll long long #define pb push_back #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define all(v) v.begin(), v.end() #define f first #define s second using namespace std; const ll V = 1e5; ll dp[105][V + 5]; std::vector<int> wt(105); std::vector<int> v(105); int main() { flash ll n, w; cin >> n >> w; for (int i = 1; i <= n; i++) { cin >> wt[i] >> v[i]; } // std::vector<std::vector<int>> dp( n+1 , std::vector<int>(w+1,0)); for (int i = 0; i <= n; i++) { for (int j = 0; j <= V; j++) { dp[i][j] = -1; } } for (int i = 0; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= V; j++) { if (v[i] > j) dp[i][j] = dp[i - 1][j]; else { ll w1 = dp[i - 1][j]; ll w2 = dp[i - 1][j - v[i]]; if (w1 == -1 && w2 == -1) { dp[i][j] = -1; } else if (w1 == -1) { dp[i][j] = w2 + wt[i]; } else if (w2 == -1) dp[i][j] = w1; else dp[i][j] = min(w2 + wt[i], w1); } } } ll result; for (int i = 0; i <= V; i++) { if (dp[n][i] == -1) continue; else if (dp[n][i] <= w) { // cout<<dp[n][i]<<endl; result = i; } } cout << result << "\n"; }
replace
47
48
47
48
0
p03164
C++
Runtime Error
// Author : ZERO_IQ // Practice is the only shortcut to improve #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(x, y) \ cerr << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl #define debug2(x, y, z) \ cerr << (#x) << " " << (#y) << " " << (#z) << " is " << (x) << " " << (y) \ << " " << (z) << endl #define endl '\n' ll const N = 1e7 + 1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif long long n, m; cin >> n >> m; vector<pair<long long, long long>> input; long long summ = 0; for (int i = 0; i < n; ++i) { long long q, qq; cin >> q >> qq; input.push_back({q, qq}); summ += qq; } vector<vector<long long>> dp(n, vector<long long>(summ + 2, 1e18)); for (int var = 0; var < n; ++var) { dp[var][0] = 0; } ll maxx = 0; for (int i = 1; i <= summ; ++i) { for (int j = 0; j < n; ++j) { if (!j) { if (i == input[j].second) dp[j][i] = input[j].first; } else if (input[j].second > i) { dp[j][i] = dp[j - 1][i]; } else { dp[j][i] = min(dp[j - 1][i], dp[j - 1][i - input[j].second] + input[j].first); } } } for (int i = 0; i <= summ; i++) { if (dp[n - 1][i] <= m) { maxx = i; } } cout << maxx << endl; return 0; }
// Author : ZERO_IQ // Practice is the only shortcut to improve #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(x, y) \ cerr << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl #define debug2(x, y, z) \ cerr << (#x) << " " << (#y) << " " << (#z) << " is " << (x) << " " << (y) \ << " " << (z) << endl #define endl '\n' ll const N = 1e7 + 1; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ long long n, m; cin >> n >> m; vector<pair<long long, long long>> input; long long summ = 0; for (int i = 0; i < n; ++i) { long long q, qq; cin >> q >> qq; input.push_back({q, qq}); summ += qq; } vector<vector<long long>> dp(n, vector<long long>(summ + 2, 1e18)); for (int var = 0; var < n; ++var) { dp[var][0] = 0; } ll maxx = 0; for (int i = 1; i <= summ; ++i) { for (int j = 0; j < n; ++j) { if (!j) { if (i == input[j].second) dp[j][i] = input[j].first; } else if (input[j].second > i) { dp[j][i] = dp[j - 1][i]; } else { dp[j][i] = min(dp[j - 1][i], dp[j - 1][i - input[j].second] + input[j].first); } } } for (int i = 0; i <= summ; i++) { if (dp[n - 1][i] <= m) { maxx = i; } } cout << maxx << endl; return 0; }
replace
24
28
24
28
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03164
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int INF = (int)1e9 + 7; 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; } int main() { const int MAXV = (int)1e3; int N, W; cin >> N >> W; vector<int> w(N), v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; vector<vector<int>> dp(N + 1, vector<int>(N * MAXV + 1, INF)); dp[0][0] = 0; for (int i = 0; i < N; i++) for (int val = 0; val <= N * MAXV; val++) { chmin(dp[i + 1][val], dp[i][val]); chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]); } int ans = 0; for (int val = 0; val <= N * MAXV; val++) if (dp[N][val] <= W) { chmax(ans, val); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; const int INF = (int)1e9 + 7; 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; } int main() { const int MAXV = (int)1e3; int N, W; cin >> N >> W; vector<int> w(N), v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; vector<vector<int>> dp(N + 1, vector<int>((N + 1) * MAXV + 1, INF)); dp[0][0] = 0; for (int i = 0; i < N; i++) for (int val = 0; val <= N * MAXV; val++) { chmin(dp[i + 1][val], dp[i][val]); chmin(dp[i + 1][val + v[i]], dp[i][val] + w[i]); } int ans = 0; for (int val = 0; val <= N * MAXV; val++) if (dp[N][val] <= W) { chmax(ans, val); } cout << ans << endl; return 0; }
replace
28
29
28
29
0
p03164
C++
Runtime Error
#include <algorithm> #include <array> #include <cstdlib> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { const long long inf = 2000000000; int n, w; cin >> n >> w; int cost[n]; int value[n]; const int max_n = 100; const int max_v = 1000; vector<vector<long long>> dp(max_n + 2); for (int i = 0; i < n; ++i) { cin >> cost[i] >> value[i]; } for (int i = 0; i <= n + 1; ++i) { dp[i].resize(max_n * max_v + 1); } for (int i = 0; i < n; ++i) { for (int j = 0; j < max_n * max_v + 1; ++j) { if (i == 0 && j == 0) { dp[0][0] = 0; } else { dp[i][j] = inf; } } } for (int i = 0; i <= n; ++i) { for (int j = 0; j < max_n * max_v + 1; ++j) { if (j - value[i] >= 0) { dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + cost[i]); } else { dp[i + 1][j] = dp[i][j]; } } } int res; for (int i = 0; i < max_n * max_v + 1; ++i) { if (dp[n + 1][i] <= w) { res = i; } } cout << res << endl; return 0; }
#include <algorithm> #include <array> #include <cstdlib> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; int main() { const long long inf = 2000000000; int n, w; cin >> n >> w; long long cost[n]; long long value[n]; const int max_n = 100; const int max_v = 1000; vector<vector<long long>> dp(max_n + 2); for (int i = 0; i < n; ++i) { cin >> cost[i] >> value[i]; } for (int i = 0; i <= n + 1; ++i) { dp[i].resize(max_n * max_v + 1); } for (int i = 0; i < n; ++i) { for (int j = 0; j < max_n * max_v + 1; ++j) { if (i == 0 && j == 0) { dp[0][0] = 0; } else { dp[i][j] = inf; } } } for (int i = 0; i <= n; ++i) { for (int j = 0; j < max_n * max_v + 1; ++j) { if (j - value[i] >= 0) { dp[i + 1][j] = min(dp[i][j], dp[i][j - value[i]] + cost[i]); } else { dp[i + 1][j] = dp[i][j]; } } } int res; for (int i = 0; i < max_n * max_v + 1; ++i) { if (dp[n + 1][i] <= w) { res = i; } } cout << res << endl; return 0; }
replace
15
17
15
17
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (lli i = 0; i < (n); i++) #define rrep(i, n) for (lli i = (n)-1; i >= 0; i--) using namespace std; using lli = long long int; lli v[105], w[105]; lli dp[105][100005] = {}; // i まででjを達成するのに必要なWの最小値 int main() { lli n, W; cin >> n >> W; rep(i, n) cin >> w[i] >> v[i]; rep(i, 105) rep(j, 100005) dp[i][j] = i == 0 && j == 0 ? 0 : 1e18; rep(i, n) { rep(j, 100005) { dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]); if (j + v[i] < 100005) dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } rrep(j, 1000005) { // cout << dp[n][j] << " "; if (dp[n][j] <= W) { cout << j << endl; return 0; } } }
#include <bits/stdc++.h> #define rep(i, n) for (lli i = 0; i < (n); i++) #define rrep(i, n) for (lli i = (n)-1; i >= 0; i--) using namespace std; using lli = long long int; lli v[105], w[105]; lli dp[105][100005] = {}; // i まででjを達成するのに必要なWの最小値 int main() { lli n, W; cin >> n >> W; rep(i, n) cin >> w[i] >> v[i]; rep(i, 105) rep(j, 100005) dp[i][j] = i == 0 && j == 0 ? 0 : 1e18; rep(i, n) { rep(j, 100005) { dp[i + 1][j] = min(dp[i][j], dp[i + 1][j]); if (j + v[i] < 100005) dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } rrep(j, 100005) { // cout << dp[n][j] << " "; if (dp[n][j] <= W) { cout << j << endl; return 0; } } }
replace
21
22
21
22
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n, W, ans, INF = 1e9 + 1, sum, dp[101][10001]; pair<long long, long long> v[101]; int main() { cin >> n >> W; for (int i = 1; i <= n; i++) cin >> v[i].first >> v[i].second, sum += v[i].second; sort(v + 1, v + 1 + n); for (int i = 0; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= sum; j++) dp[i][j] = INF; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (j >= v[1].second) { if (j >= v[i].second && dp[i - 1][j - v[i].second] != INF) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i].second] + v[i].first); if (dp[i - 1][j] && dp[i - 1][j] != INF) dp[i][j] = min(dp[i - 1][j], dp[i][j]); } } } for (int i = 1; i <= sum; i++) { if (dp[n][i] <= W && dp[n][i]) ans = i; } cout << ans; }
#include <bits/stdc++.h> using namespace std; long long n, W, ans, INF = 1e9 + 1, sum, dp[101][100001]; pair<long long, long long> v[101]; int main() { cin >> n >> W; for (int i = 1; i <= n; i++) cin >> v[i].first >> v[i].second, sum += v[i].second; sort(v + 1, v + 1 + n); for (int i = 0; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= sum; j++) dp[i][j] = INF; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= sum; j++) { if (j >= v[1].second) { if (j >= v[i].second && dp[i - 1][j - v[i].second] != INF) dp[i][j] = min(dp[i][j], dp[i - 1][j - v[i].second] + v[i].first); if (dp[i - 1][j] && dp[i - 1][j] != INF) dp[i][j] = min(dp[i - 1][j], dp[i][j]); } } } for (int i = 1; i <= sum; i++) { if (dp[n][i] <= W && dp[n][i]) ans = i; } cout << ans; }
replace
2
3
2
3
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i >= b; i--) typedef long long int ll; typedef vector<ll> vi; int main() { ll n, wt; cin >> n >> wt; ll w[n + 5], v[n + 5]; rep(i, 0, n) cin >> w[i] >> v[i]; ll tot = 0; for (ll &i : v) tot += i; vi dp(tot + 5, 1e18 + 5); dp[0] = 0; rep(i, 0, n) rrep(val, (tot - v[i]), 0) dp[val + v[i]] = min(dp[val + v[i]], dp[val] + w[i]); ll ans = 0; rep(val, 0, (tot + 1)) if (dp[val] <= wt) ans = val; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = a; i >= b; i--) typedef long long int ll; typedef vector<ll> vi; int main() { ll n, wt; cin >> n >> wt; ll w[n], v[n]; rep(i, 0, n) cin >> w[i] >> v[i]; ll tot = 0; for (ll &i : v) tot += i; vi dp(tot + 5, 1e18 + 5); dp[0] = 0; rep(i, 0, n) rrep(val, (tot - v[i]), 0) dp[val + v[i]] = min(dp[val + v[i]], dp[val] + w[i]); ll ans = 0; rep(val, 0, (tot + 1)) if (dp[val] <= wt) ans = val; cout << ans << endl; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03164
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; // #define int long long #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pbds; int32_t main() { // c_p_c(); int n, w; cin >> n >> w; vi a(n + 1); vi v(n + 1); int maxvalue = n * 100; int dp[n + 1][maxvalue + 1]; for (int i = 1; i <= n; i++) { cin >> a[i] >> v[i]; } // for(int i=1;i<=n;i++)cout<<a[i]<<" "<<v[i]<<endl; for (int i = 0; i <= maxvalue; i++) dp[1][i] = inf; dp[1][0] = 0; dp[1][v[1]] = a[1]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= maxvalue; j++) { if (v[i] <= j) { dp[i][j] = dp[i - 1][j]; dp[i][j] = min(dp[i][j], a[i] + dp[i - 1][j - v[i]]); } else dp[i][j] = dp[i - 1][j]; // cout<<dp[i][j]<<" "; } // cout<<endl; } int ans = 0; for (int i = 0; i <= maxvalue; i++) { if (dp[n][i] <= w) ans = i; } cout << ans; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; // #define int long long #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pbds; int32_t main() { // c_p_c(); int n, w; cin >> n >> w; vi a(n + 1); vi v(n + 1); int maxvalue = n * 1000; int dp[n + 1][maxvalue + 1]; for (int i = 1; i <= n; i++) { cin >> a[i] >> v[i]; } // for(int i=1;i<=n;i++)cout<<a[i]<<" "<<v[i]<<endl; for (int i = 0; i <= maxvalue; i++) dp[1][i] = inf; dp[1][0] = 0; dp[1][v[1]] = a[1]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= maxvalue; j++) { if (v[i] <= j) { dp[i][j] = dp[i - 1][j]; dp[i][j] = min(dp[i][j], a[i] + dp[i - 1][j - v[i]]); } else dp[i][j] = dp[i - 1][j]; // cout<<dp[i][j]<<" "; } // cout<<endl; } int ans = 0; for (int i = 0; i <= maxvalue; i++) { if (dp[n][i] <= w) ans = i; } cout << ans; return 0; }
replace
37
38
37
38
0
p03164
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define X first #define Y second #define pb push_back #define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X)) #define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X)) #define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X)) #define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X)) #define repe(X, Y) for ((X) = 0; (X) < (Y); ++(X)) #define peat(X, Y) for (; (X) < (Y); ++(X)) #define all(X) (X).begin(), (X).end() #define rall(X) (X).rbegin(), (X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)), (X).end()) #define Endl endl using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class T> using vv = vector<vector<T>>; template <class T> ostream &operator<<(ostream &os, const deque<T> &t) { os << "{"; rep(i, t.size()) { os << t[i] << ","; } os << "}" << endl; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "{"; rep(i, t.size()) { os << t[i] << ","; } os << "}" << endl; return os; } template <class T, size_t n> ostream &operator<<(ostream &os, const array<T, n> &t) { os << "{"; rep(i, n) { os << t[i] << ","; } os << "}" << endl; return os; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) { return os << "(" << t.first << "," << t.second << ")"; } template <class S, class T, class U> ostream &operator<<(ostream &os, const tuple<S, T, U> &t) { return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")"; } template <class S, class T, class U, class V> ostream &operator<<(ostream &os, const tuple<S, T, U, V> &t) { return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << "," << get<3>(t) << ")"; } template <class S, class T, class U, class V, class W> ostream &operator<<(ostream &os, const tuple<S, T, U, V, W> &t) { return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << "," << get<3>(t) << "," << get<4>(t) << ")"; } template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; } template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; } // #undef NUIP #ifdef NUIP #define out(args...) \ { \ vector<string> a_r_g_s = s_p_l_i_t(#args, ','); \ e_r_r(a_r_g_s.begin(), args); \ } vector<string> s_p_l_i_t(const string &s, char c) { vector<string> v; int d = 0, f = 0; string t; for (char c : s) { if (!d && c == ',') v.pb(t), t = ""; else t += c; if (c == '\"' || c == '\'') f ^= 1; if (!f && c == '(') ++d; if (!f && c == ')') --d; } v.pb(t); return move(v); } void e_r_r(vector<string>::iterator it) {} template <typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args) { if (*it == " 1" || *it == "1") cerr << endl; else cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", "; e_r_r(++it, args...); } #else #define out #endif #ifdef __cpp_init_captures template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); } template <class... Args> auto table(int n, Args... args) { auto val = table(args...); return vector<decltype(val)>(n, move(val)); } #endif const ll MOD = 1e9 + 7; ll dp[212345]; int main() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(0); int n, w; cin >> n >> w; vector<pii> wv(n); rep(i, n) cin >> wv[i].X >> wv[i].Y; fill(dp, dp + 212345, MOD); dp[0] = 0; for (pii p : wv) { rrep(i, 212345) MN(dp[i + p.Y], dp[i] + p.X); // rep(i,100) cout<<(dp[i]==MOD?-1:dp[i])<<",";cout<<endl; } rrep(i, 212345) if (dp[i] <= w) { cout << i << endl; break; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define X first #define Y second #define pb push_back #define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X)) #define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X)) #define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X)) #define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X)) #define repe(X, Y) for ((X) = 0; (X) < (Y); ++(X)) #define peat(X, Y) for (; (X) < (Y); ++(X)) #define all(X) (X).begin(), (X).end() #define rall(X) (X).rbegin(), (X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)), (X).end()) #define Endl endl using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <class T> using vv = vector<vector<T>>; template <class T> ostream &operator<<(ostream &os, const deque<T> &t) { os << "{"; rep(i, t.size()) { os << t[i] << ","; } os << "}" << endl; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &t) { os << "{"; rep(i, t.size()) { os << t[i] << ","; } os << "}" << endl; return os; } template <class T, size_t n> ostream &operator<<(ostream &os, const array<T, n> &t) { os << "{"; rep(i, n) { os << t[i] << ","; } os << "}" << endl; return os; } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &t) { return os << "(" << t.first << "," << t.second << ")"; } template <class S, class T, class U> ostream &operator<<(ostream &os, const tuple<S, T, U> &t) { return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")"; } template <class S, class T, class U, class V> ostream &operator<<(ostream &os, const tuple<S, T, U, V> &t) { return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << "," << get<3>(t) << ")"; } template <class S, class T, class U, class V, class W> ostream &operator<<(ostream &os, const tuple<S, T, U, V, W> &t) { return os << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << "," << get<3>(t) << "," << get<4>(t) << ")"; } template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; } template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; } // #undef NUIP #ifdef NUIP #define out(args...) \ { \ vector<string> a_r_g_s = s_p_l_i_t(#args, ','); \ e_r_r(a_r_g_s.begin(), args); \ } vector<string> s_p_l_i_t(const string &s, char c) { vector<string> v; int d = 0, f = 0; string t; for (char c : s) { if (!d && c == ',') v.pb(t), t = ""; else t += c; if (c == '\"' || c == '\'') f ^= 1; if (!f && c == '(') ++d; if (!f && c == ')') --d; } v.pb(t); return move(v); } void e_r_r(vector<string>::iterator it) {} template <typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args) { if (*it == " 1" || *it == "1") cerr << endl; else cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << ", "; e_r_r(++it, args...); } #else #define out #endif #ifdef __cpp_init_captures template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); } template <class... Args> auto table(int n, Args... args) { auto val = table(args...); return vector<decltype(val)>(n, move(val)); } #endif const ll MOD = 1e9 + 7; ll dp[212345]; int main() { ios_base::sync_with_stdio(false); cout << fixed << setprecision(0); int n, w; cin >> n >> w; vector<pii> wv(n); rep(i, n) cin >> wv[i].X >> wv[i].Y; fill(dp, dp + 212345, MOD); dp[0] = 0; for (pii p : wv) { rrep(i, 112345) MN(dp[i + p.Y], dp[i] + p.X); // rep(i,100) cout<<(dp[i]==MOD?-1:dp[i])<<",";cout<<endl; } rrep(i, 212345) if (dp[i] <= w) { cout << i << endl; break; } return 0; }
replace
145
146
145
146
-11
p03164
C++
Runtime Error
#include <bits/stdc++.h> #ifdef PRAGMA #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #endif #define fst first #define snd second #define fore(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define mp make_pair #define bs binary_search #define ALL(s) s.begin(), s.end() #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define SZ(n) ((int)(n).size()) #define MAXI ((ll)1e16) #define MINI ((ll)-1e16) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } ll n, w, res; ll weight[101]; ll val[101]; ll dp[101][1001]; ll solve(ll i, ll value) { if (value < 0) return MAXI; if (i == -1 && (value < 0 || value > 0)) return MAXI; if (i == -1) return 0; if (dp[i][value] != -1) return dp[i][value]; dp[i][value] = min(weight[i] + solve(i - 1, value - val[i]), solve(i - 1, value)); return dp[i][value]; } int main() { FIN; cin >> n >> w; fore(i, 0, n) { cin >> weight[i] >> val[i]; } memset(dp, -1, sizeof(dp)); for (int i = 100000; i > -1; i--) { if (solve(n - 1, i) <= w) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> #ifdef PRAGMA #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #endif #define fst first #define snd second #define fore(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define mp make_pair #define bs binary_search #define ALL(s) s.begin(), s.end() #define FIN \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define SZ(n) ((int)(n).size()) #define MAXI ((ll)1e16) #define MINI ((ll)-1e16) using namespace std; typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } ll n, w, res; ll weight[101]; ll val[101]; ll dp[101][100001]; ll solve(ll i, ll value) { if (value < 0) return MAXI; if (i == -1 && (value < 0 || value > 0)) return MAXI; if (i == -1) return 0; if (dp[i][value] != -1) return dp[i][value]; dp[i][value] = min(weight[i] + solve(i - 1, value - val[i]), solve(i - 1, value)); return dp[i][value]; } int main() { FIN; cin >> n >> w; fore(i, 0, n) { cin >> weight[i] >> val[i]; } memset(dp, -1, sizeof(dp)); for (int i = 100000; i > -1; i--) { if (solve(n - 1, i) <= w) { cout << i << endl; return 0; } } }
replace
28
29
28
29
-11
p03164
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) #define Rep(i, sta, n) for (int i = sta; i < (n); ++i) #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; const int mod = 1000000007; const int INF = 1e9; const ll LINF = 1e18; ll dp[101][100100]; int main() { int n; ll W; cin >> n >> W; vector<ll> w(n); vector<int> v(n); int MAXV = 0; rep(i, n) { cin >> w[i] >> v[i]; MAXV += v[i]; } rep(i, n + 1) rep(j, MAXV + 1) { dp[i][j] = LINF; } dp[0][0] = 0; rep(i, n + 1) { rep(j, MAXV + 1) { 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, MAXV + 1) { // cout << "i: " << i << " j: " << j<< " dp: " << dp[i][j] << endl; if (dp[i][j] <= W) ans = max(ans, j); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define rep(i, n) for (int i = 0; i < (n); ++i) #define Rep(i, sta, n) for (int i = sta; i < (n); ++i) #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; const int mod = 1000000007; const int INF = 1e9; const ll LINF = 1e18; ll dp[105][100100]; int main() { int n; ll W; cin >> n >> W; vector<ll> w(n); vector<int> v(n); int MAXV = 0; rep(i, n) { cin >> w[i] >> v[i]; MAXV += v[i]; } rep(i, n + 1) rep(j, MAXV + 1) { dp[i][j] = LINF; } dp[0][0] = 0; rep(i, n + 1) { rep(j, MAXV + 1) { 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, MAXV + 1) { // cout << "i: " << i << " j: " << j<< " dp: " << dp[i][j] << endl; if (dp[i][j] <= W) ans = max(ans, j); } } cout << ans << endl; return 0; }
replace
19
20
19
20
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) using namespace std; using P = pair<int, int>; using ll = long long; ll INF = 100100100100100100; int main() { // input int n; int w; cin >> n >> w; vector<int> weights(n + 1); vector<int> values(n + 1); ll max_value_sum = 0; ll max_weight_sum = 0; rep(i, n) { cin >> weights[i + 1]; // weight cin >> values[i + 1]; // values max_value_sum += values[i + 1]; max_weight_sum += weights[i + 1]; } // dp vector<vector<ll>> dp(n + 1, vector<ll>(max_value_sum + 1)); rep(i, n + 1) rep(v, max_value_sum + 1) dp[i][v] = INF; dp[0][0] = 0; for (int i = 0; i < n; i++) { for (ll v = 0; v <= max_value_sum; v++) { if (values[i] <= v) dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i + 1]] + weights[i + 1]); else dp[i + 1][v] = dp[i][v]; } } // output ll ans = 0; for (ll v = 0; v <= max_value_sum; v++) { if (dp[n][v] <= w) { ans = max(ans, (ll)v); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) using namespace std; using P = pair<int, int>; using ll = long long; ll INF = 100100100100100100; int main() { // input int n; int w; cin >> n >> w; vector<int> weights(n + 1); vector<int> values(n + 1); ll max_value_sum = 0; ll max_weight_sum = 0; rep(i, n) { cin >> weights[i + 1]; // weight cin >> values[i + 1]; // values max_value_sum += values[i + 1]; max_weight_sum += weights[i + 1]; } // dp vector<vector<ll>> dp(n + 1, vector<ll>(max_value_sum + 1)); rep(i, n + 1) rep(v, max_value_sum + 1) dp[i][v] = INF; dp[0][0] = 0; for (int i = 0; i < n; i++) { for (ll v = 0; v <= max_value_sum; v++) { if (values[i + 1] <= v) dp[i + 1][v] = min(dp[i][v], dp[i][v - values[i + 1]] + weights[i + 1]); else dp[i + 1][v] = dp[i][v]; } } // output ll ans = 0; for (ll v = 0; v <= max_value_sum; v++) { if (dp[n][v] <= w) { ans = max(ans, (ll)v); } } cout << ans << endl; return 0; }
replace
34
35
34
35
0
p03164
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 100100100; const ll INFLL = 100100100100100100; const int MOD = (int)1e9 + 7; const ll MODLL = (ll)1e9 + 7; const double EPS = 1e-9; int main() { int n, w; cin >> n >> w; vector<ll> c(n); vector<ll> v(n); REP(i, n) cin >> c[i] >> v[i]; vector<vector<ll>> dp(n + 1, vector<ll>(100100, INFLL)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 100100; j++) { if (dp[i][j] != INFLL) { dp[i + 1][j] = dp[i][j]; } if (dp[i][j - v[i]] != INFLL && j - v[i] >= 0) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + c[i]); } } } int ans = 0; for (int j = 0; j < 100100; j++) { if (dp[n][j] <= w) { ans = j; } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 100100100; const ll INFLL = 100100100100100100; const int MOD = (int)1e9 + 7; const ll MODLL = (ll)1e9 + 7; const double EPS = 1e-9; int main() { int n, w; cin >> n >> w; vector<ll> c(n); vector<ll> v(n); REP(i, n) cin >> c[i] >> v[i]; vector<vector<ll>> dp(n + 1, vector<ll>(100100, INFLL)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 100100; j++) { if (dp[i][j] != INFLL) { dp[i + 1][j] = dp[i][j]; } if (j - v[i] >= 0 && dp[i][j - v[i]] != INFLL) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + c[i]); } } } int ans = 0; for (int j = 0; j < 100100; j++) { if (dp[n][j] <= w) { ans = j; } } cout << ans << endl; return 0; }
replace
39
40
39
40
-11
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define N 100 #define V 1000 int v[N + 1], w[N + 1], dp[2][N * V + 1], Sum[N + 1]; signed main() { int n, m, i; scanf("%lld%lld", &n, &m); for (i = 1; i <= n; i++) scanf("%lld%lld", w + i, v + i), Sum[i] = Sum[i - 1] + v[i]; memset(dp, 0x3f, sizeof(dp)); dp[0][0] = 0; for (i = 1; i <= n; i++) for (int j = 0; j <= Sum[i]; j++) dp[i & 1][j] = min(dp[i - 1 & 1][j], dp[i - 1 & 1][j - v[i]] + w[i]); for (i = Sum[n];; i--) if (dp[n & 1][i] <= m) return printf("%lld\n", i), 0; } /*1 3 8 3 30 4 50 5 60 */ /*2 1 1000000000 1000000000 10 */ /*3 6 15 6 5 5 6 6 4 6 6 3 5 7 2 */
#include <bits/stdc++.h> using namespace std; #define int long long #define N 100 #define V 1000 int v[N + 1], w[N + 1], dp[2][N * V + 1], Sum[N + 1]; signed main() { int n, m, i; scanf("%lld%lld", &n, &m); for (i = 1; i <= n; i++) scanf("%lld%lld", w + i, v + i), Sum[i] = Sum[i - 1] + v[i]; memset(dp, 0x3f, sizeof(dp)); dp[0][0] = 0; for (i = 1; i <= n; i++) for (int j = 0; j <= Sum[i]; j++) dp[i & 1][j] = min(dp[i - 1 & 1][j], (j >= v[i] ? dp[i - 1 & 1][j - v[i]] + w[i] : 0x3f3f3f3f)); for (i = Sum[n];; i--) if (dp[n & 1][i] <= m) return printf("%lld\n", i), 0; } /*1 3 8 3 30 4 50 5 60 */ /*2 1 1000000000 1000000000 10 */ /*3 6 15 6 5 5 6 6 4 6 6 3 5 7 2 */
replace
15
16
15
18
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define smax(a, b) ((a) < (b) ? ((a) = (b), true) : false) #define smin(a, b) ((a) > (b) ? ((a) = (b), true) : false) #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; typedef long long ll; const ll MAX = 1e18; ll n, w; ll item[100][2]; ll dp[100][100001]; int main() { cin >> n >> w; ll tval = 0; for (int i = 1; i <= n; i++) { // value, weight cin >> item[i][1] >> item[i][0]; tval += item[i][0]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= tval; j++) { dp[i][j] = MAX; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= tval; j++) { dp[i][j] = dp[i - 1][j]; } for (int j = 0; j <= tval; j++) { if (dp[i - 1][j] != MAX) { dp[i][j + item[i][0]] = min(dp[i][j + item[i][0]], dp[i - 1][j] + item[i][1]); } } } ll ans = MAX; for (int i = 0; i <= tval; i++) { if (dp[n][i] <= w) ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define smax(a, b) ((a) < (b) ? ((a) = (b), true) : false) #define smin(a, b) ((a) > (b) ? ((a) = (b), true) : false) #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using namespace std; typedef long long ll; const ll MAX = 1e18; ll n, w; ll item[101][2]; ll dp[101][100001]; int main() { cin >> n >> w; ll tval = 0; for (int i = 1; i <= n; i++) { // value, weight cin >> item[i][1] >> item[i][0]; tval += item[i][0]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= tval; j++) { dp[i][j] = MAX; } } dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= tval; j++) { dp[i][j] = dp[i - 1][j]; } for (int j = 0; j <= tval; j++) { if (dp[i - 1][j] != MAX) { dp[i][j + item[i][0]] = min(dp[i][j + item[i][0]], dp[i - 1][j] + item[i][1]); } } } ll ans = MAX; for (int i = 0; i <= tval; i++) { if (dp[n][i] <= w) ans = i; } cout << ans << endl; return 0; }
replace
9
11
9
11
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define lp(i, a, b) for (int i = a; i < b; i++) #define ll long long #define ff first #define ss second const int maxn = 10; const int maxv = 100; const int inf = 1e9 + 10; using namespace std; ll dp[maxn * maxv]; pair<ll, ll> v[maxn]; int ans; int main() { lp(i, 1, maxn * maxv) dp[i] = inf; dp[0] = 0; int n, w; scanf("%d%d", &n, &w); lp(i, 0, n) scanf("%lld%lld", &v[i].ff, &v[i].ss); lp(i, 0, n) { for (int j = ans + v[i].ss; j >= v[i].ss; j--) { if (dp[j - v[i].ss] + v[i].ff <= w) { dp[j] = min(dp[j], dp[j - v[i].ss] + v[i].ff), ans = max(ans, j); } } } printf("%d\n", ans); }
#include <bits/stdc++.h> #define lp(i, a, b) for (int i = a; i < b; i++) #define ll long long #define ff first #define ss second const int maxn = 105; const int maxv = 1005; const int inf = 1e9 + 10; using namespace std; ll dp[maxn * maxv]; pair<ll, ll> v[maxn]; int ans; int main() { lp(i, 1, maxn * maxv) dp[i] = inf; dp[0] = 0; int n, w; scanf("%d%d", &n, &w); lp(i, 0, n) scanf("%lld%lld", &v[i].ff, &v[i].ss); lp(i, 0, n) { for (int j = ans + v[i].ss; j >= v[i].ss; j--) { if (dp[j - v[i].ss] + v[i].ff <= w) { dp[j] = min(dp[j], dp[j - v[i].ss] + v[i].ff), ans = max(ans, j); } } } printf("%d\n", ans); }
replace
7
9
7
9
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ll long long int #define ull unsigned long long int #define ld long double #define mod 1000000007 #define inf 1000000000000000007 #define eps 0.000001 #define pi 3.141592653589793 #define pii pair<int, int> #define pdd pair<ld, ld> #define pll pair<ll, ll> #define ff first #define ss second #define vii vector<int> #define vpl vector<pll> #define vll vector<ll> #define sti stack<int> #define stll stack<ll> #define mseti set<ll> #define msetd multiset<ll, greater<ll>> #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define stp setprecision(20) // use fixed before stp #define endl '\n' int main() { FAST #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif ll n, w; cin >> n >> w; pll p[n]; for (ll i = 0; i < n; i++) { cin >> p[i].ff >> p[i].ss; } ll dp[100001]; for (ll i = 1; i <= 100000; i++) { dp[i] = inf; } dp[0] = 0; for (ll i = 0; i < n; i++) { for (ll j = (100000 - p[i].ss); j >= 0; j--) { if ((dp[j] + p[i].ff) < dp[j + p[i].ss]) { dp[j + p[i].ss] = (dp[j] + p[i].ff); } } } ll ans = 0; for (ll i = 100000; i > 0; i--) { if (dp[i] <= w) { ans = i; break; } } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ll long long int #define ull unsigned long long int #define ld long double #define mod 1000000007 #define inf 1000000000000000007 #define eps 0.000001 #define pi 3.141592653589793 #define pii pair<int, int> #define pdd pair<ld, ld> #define pll pair<ll, ll> #define ff first #define ss second #define vii vector<int> #define vpl vector<pll> #define vll vector<ll> #define sti stack<int> #define stll stack<ll> #define mseti set<ll> #define msetd multiset<ll, greater<ll>> #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define stp setprecision(20) // use fixed before stp #define endl '\n' int main() { FAST ll n, w; cin >> n >> w; pll p[n]; for (ll i = 0; i < n; i++) { cin >> p[i].ff >> p[i].ss; } ll dp[100001]; for (ll i = 1; i <= 100000; i++) { dp[i] = inf; } dp[0] = 0; for (ll i = 0; i < n; i++) { for (ll j = (100000 - p[i].ss); j >= 0; j--) { if ((dp[j] + p[i].ff) < dp[j + p[i].ss]) { dp[j + p[i].ss] = (dp[j] + p[i].ff); } } } ll ans = 0; for (ll i = 100000; i > 0; i--) { if (dp[i] <= w) { ans = i; break; } } cout << ans; }
replace
31
37
31
32
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define inf (ll)1e10 + 1 #define d(x) cerr << #x << "=" << x << endl; #define MAX 1000001 ll n, dp[MAX], W, maxv, v, w; int main(void) { cin >> n >> W; rep(i, MAX) dp[i] = inf; dp[0] = 0; rep(i, n) { cin >> w >> v; for (int j = MAX - 1; j >= 0; j--) dp[j + v] = min(dp[j + v], dp[j] + w); } rep(i, MAX) if (dp[i] <= W) maxv = i; cout << maxv << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define inf (ll)1e10 + 1 #define d(x) cerr << #x << "=" << x << endl; #define MAX 1000001 ll n, dp[MAX], W, maxv, v, w; int main(void) { cin >> n >> W; rep(i, MAX) dp[i] = inf; dp[0] = 0; rep(i, n) { cin >> w >> v; for (int j = MAX - v; j >= 0; j--) dp[j + v] = min(dp[j + v], dp[j] + w); } rep(i, MAX) if (dp[i] <= W) maxv = i; cout << maxv << endl; return 0; }
replace
20
21
20
21
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 5; const ll INFLL = 1e18l + 5; int main() { int n, W; cin >> n >> W; vector<ll> dp(100001, INFLL); // dp[i] min weight at value = i dp[0] = 0; for (int i = 0; i < n; i++) { int w, v; cin >> w >> v; for (int va = W - w; va >= 0; --va) { dp[va + v] = min(dp[va + v], dp[va] + w); } } int ans = 0; for (int i = 0; i < 100001; ++i) { if (dp[i] <= W) ans = max(ans, i); } cout << ans; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 5; const ll INFLL = 1e18l + 5; int main() { int n, W; cin >> n >> W; vector<ll> dp(100001, INFLL); // dp[i] min weight at value = i dp[0] = 0; for (int i = 0; i < n; i++) { int w, v; cin >> w >> v; for (int va = 100001 - v; va >= 0; --va) { dp[va + v] = min(dp[va + v], dp[va] + w); } } int ans = 0; for (int i = 0; i < 100001; ++i) { if (dp[i] <= W) ans = max(ans, i); } cout << ans; }
replace
15
16
15
16
0
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; const ll INF = 1LL << 60; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) int main() { int n, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>(100010, INF)); dp[0][0] = 0; for (int i = 0; i < n; ++i) { int u, v; cin >> u >> v; dp[i + 1] = dp[i]; for (int j = 0; j < 100010; ++j) { for (int k = 0; k <= v; ++k) { if (j + k >= 100010) break; dp[i + 1][j + k] = min(dp[i + 1][j + k], dp[i][j] + u); } } } int ans = 0; for (int i = 0; i < 100010; ++i) if (dp[n][i] <= w) ans = i; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; const ll INF = 1LL << 60; #define p_ary(ary, a, b, i) \ do { \ cout << "["; \ for (int(i) = (a); (i) < (b); ++(i)) \ cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); \ cout << "]\n"; \ } while (0) #define p_map(map, it) \ do { \ cout << "{"; \ for (auto(it) = map.begin();; ++(it)) { \ if ((it) == map.end()) { \ cout << "}\n"; \ break; \ } else \ cout << "" << (it)->first << "=>" << (it)->second << ", "; \ } \ } while (0) int main() { int n, w; cin >> n >> w; vector<vector<ll>> dp(n + 1, vector<ll>(100010, INF)); dp[0][0] = 0; for (int i = 0; i < n; ++i) { int u, v; cin >> u >> v; dp[i + 1] = dp[i]; for (int j = 0; j < 100010 - v; ++j) { dp[i + 1][j + v] = min(dp[i + 1][j + v], dp[i][j] + u); } } int ans = 0; for (int i = 0; i < 100010; ++i) if (dp[n][i] <= w) ans = i; cout << ans << endl; return 0; }
replace
35
41
35
37
TLE
p03164
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define ppi pair<int, int> #define mp make_pair #define inf 2e16 const int N = 2e5 + 11, K = 20, S = 1e3 + 11; const int mod = 1e9 + 7; ll dp[N][101]; int weg[N], v[N]; void clear() { for (int i = 0; i < N; i++) for (int j = 0; j < 101; j++) dp[i][j] = inf; } int main() { #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); #endif clear(); int n, w; cin >> n >> w; for (int i = 0; i < n; i++) scanf("%d%d", weg + i, v + i); int mx = (w >= weg[0] ? v[0] : 0); dp[v[0]][0] = weg[0]; for (int i = 1; i < n; i++) { dp[v[i]][i] = weg[i]; for (int j = 0; j < N; j++) { dp[j][i] = min(dp[j][i], dp[j][i - 1]); if (j >= v[i]) { dp[j][i] = min(dp[j][i], dp[j - v[i]][i - 1] + weg[i]); } if (dp[j][i] <= w) { mx = max(mx, j); } } } cout << mx; return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long #define ppi pair<int, int> #define mp make_pair #define inf 2e16 const int N = 2e5 + 11, K = 20, S = 1e3 + 11; const int mod = 1e9 + 7; ll dp[N][101]; int weg[N], v[N]; void clear() { for (int i = 0; i < N; i++) for (int j = 0; j < 101; j++) dp[i][j] = inf; } int main() { #ifndef ONLINE_JUDGE // freopen("inp.txt", "r", stdin); #endif clear(); int n, w; cin >> n >> w; for (int i = 0; i < n; i++) scanf("%d%d", weg + i, v + i); int mx = (w >= weg[0] ? v[0] : 0); dp[v[0]][0] = weg[0]; for (int i = 1; i < n; i++) { dp[v[i]][i] = weg[i]; for (int j = 0; j < N; j++) { dp[j][i] = min(dp[j][i], dp[j][i - 1]); if (j >= v[i]) { dp[j][i] = min(dp[j][i], dp[j - v[i]][i - 1] + weg[i]); } if (dp[j][i] <= w) { mx = max(mx, j); } } } cout << mx; return 0; }
replace
30
31
30
31
-11
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; int d[101][100001]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n, w; cin >> n >> w; for (int i = 0; i <= n; i++) for (int j = 1; j <= 100000; j++) d[i][j] = INT_MAX; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; for (int j = 1; j <= 100000; j++) d[i][j] = min(d[i - 1][j], d[i - 1][j - b] + a); } for (int j = 100000; j >= 0; j--) { if (d[n][j] <= w) { cout << j; return 0; } } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; int d[101][100001]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int n, w; cin >> n >> w; for (int i = 0; i <= n; i++) for (int j = 1; j <= 100000; j++) d[i][j] = INT_MAX; for (int i = 1; i <= n; i++) { int a, b; cin >> a >> b; for (int j = 1; j <= 100000; j++) d[i][j] = min(d[i - 1][j], (j - b >= 0 ? d[i - 1][j - b] + a : INT_MAX)); } for (int j = 100000; j >= 0; j--) { if (d[n][j] <= w) { cout << j; return 0; } } return 0; }
replace
27
28
27
28
0
p03164
C++
Runtime Error
// Target Expert /* * Author : raj1307 - Raj Singh * Institute : Jalpaiguri Government Engineering College * Date : 3.08.19 */ #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <assert.h> #include <complex> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define DEBUG #ifdef DEBUG #define deb(...) \ cerr << "Line:" << __LINE__ << " "; \ __f(#__VA_ARGS__, __VA_ARGS__) #define debarr(a, n) \ cerr << #a << " : "; \ for (int i = 0; i < n; i++) \ cerr << a[i] << " "; \ cerr << endl; #define debmat(mat, row, col) \ cerr << #mat << " :\n"; \ for (int i = 0; i < row; i++) { \ for (int j = 0; j < col; j++) \ cerr << mat[i][j] << " "; \ cerr << endl; \ } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define deb(...) \ {} #define debarr(a, n) \ {} #define debmat(mat, row, col) \ {} #define endl "\n" #endif #define fio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fr(i, a, b) for (int i = (a); i < (b); ++i) #define fb(i, b, a) for (int i = (b); i > (a); --i) #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define rr return #define int long long #define pb push_back #define sz(x) ((int)x.size()) int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a > b) return b; else return a; } const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1e18 + 5; int powm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } const int N = 5e5 + 5; int n, W; int cache[10005][105]; int v[105], w[105]; int dp(int sumv, int pos) { if (sumv == 0) return 0; else if (sumv < 0 or pos == n) return 1e18; else if (cache[sumv][pos] != -1) return cache[sumv][pos]; else { cache[sumv][pos] = min(w[pos] + dp(sumv - v[pos], pos + 1), dp(sumv, pos + 1)); return cache[sumv][pos]; } } void solve() { cin >> n >> W; int sumv = 0; fr(i, 0, n) { cin >> w[i]; cin >> v[i]; sumv += v[i]; } memset(cache, -1, sizeof(cache)); // cout<<dp(sumv,0); int ans = 0; fr(i, 1, sumv + 1) { // deb(ans); if (dp(i, 0) <= W) ans = i; } cout << ans; } signed main() { fio; cout << fixed << setprecision(10); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
// Target Expert /* * Author : raj1307 - Raj Singh * Institute : Jalpaiguri Government Engineering College * Date : 3.08.19 */ #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <assert.h> #include <complex> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <memory.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define DEBUG #ifdef DEBUG #define deb(...) \ cerr << "Line:" << __LINE__ << " "; \ __f(#__VA_ARGS__, __VA_ARGS__) #define debarr(a, n) \ cerr << #a << " : "; \ for (int i = 0; i < n; i++) \ cerr << a[i] << " "; \ cerr << endl; #define debmat(mat, row, col) \ cerr << #mat << " :\n"; \ for (int i = 0; i < row; i++) { \ for (int j = 0; j < col; j++) \ cerr << mat[i][j] << " "; \ cerr << endl; \ } template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define deb(...) \ {} #define debarr(a, n) \ {} #define debmat(mat, row, col) \ {} #define endl "\n" #endif #define fio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fr(i, a, b) for (int i = (a); i < (b); ++i) #define fb(i, b, a) for (int i = (b); i > (a); --i) #define rep(i, a, b) for (int i = (a); i <= (b); ++i) #define rr return #define int long long #define pb push_back #define sz(x) ((int)x.size()) int max(int a, int b) { if (a > b) return a; else return b; } int min(int a, int b) { if (a > b) return b; else return a; } const int mod = 1000 * 1000 * 1000 + 7; const int INF = 1e18 + 5; int powm(int a, int b) { int res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } const int N = 5e5 + 5; int n, W; int cache[100005][105]; int v[105], w[105]; int dp(int sumv, int pos) { if (sumv == 0) return 0; else if (sumv < 0 or pos == n) return 1e18; else if (cache[sumv][pos] != -1) return cache[sumv][pos]; else { cache[sumv][pos] = min(w[pos] + dp(sumv - v[pos], pos + 1), dp(sumv, pos + 1)); return cache[sumv][pos]; } } void solve() { cin >> n >> W; int sumv = 0; fr(i, 0, n) { cin >> w[i]; cin >> v[i]; sumv += v[i]; } memset(cache, -1, sizeof(cache)); // cout<<dp(sumv,0); int ans = 0; fr(i, 1, sumv + 1) { // deb(ans); if (dp(i, 0) <= W) ans = i; } cout << ans; } signed main() { fio; cout << fixed << setprecision(10); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
109
110
109
110
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MAX = 10005; vector<long long int> S(MAX, 10000000000), A(MAX), B(MAX); int N, W; void DP(int u) { for (int j = 1; j <= u; j++) { for (int i = N * 1000; i >= 0; i--) { if (i == 0 || (S[i] != 10000000000 && S[i] + A[j] <= W)) S[B[j] + i] = min(S[B[j] + i], S[i] + A[j]); } } int ans = 0; for (int i = 0; i <= N * 1000; i++) { if (S[i] != 10000000000) ans = i; } cout << ans << endl; } int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> A[i + 1] >> B[i + 1]; } S[0] = 0; DP(N); }
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; vector<long long int> S(MAX, 10000000000), A(MAX), B(MAX); int N, W; void DP(int u) { for (int j = 1; j <= u; j++) { for (int i = N * 1000; i >= 0; i--) { if (i == 0 || (S[i] != 10000000000 && S[i] + A[j] <= W)) S[B[j] + i] = min(S[B[j] + i], S[i] + A[j]); } } int ans = 0; for (int i = 0; i <= N * 1000; i++) { if (S[i] != 10000000000) ans = i; } cout << ans << endl; } int main() { cin >> N >> W; for (int i = 0; i < N; i++) { cin >> A[i + 1] >> B[i + 1]; } S[0] = 0; DP(N); }
replace
3
4
3
4
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vc = vector<char>; using vb = vector<bool>; vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1}; int main() { int n, w; cin >> n >> w; vi wei(n), val(n); rep(i, n) cin >> wei[i] >> val[i]; int vmax = n * 1000; vector<vi> dp(n + 1, vi(vmax + 1, w + 1)); dp[0][0] = 0; rep(i, n) rep(j, vmax + 1) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); dp[i + 1][j + val[i]] = min(dp[i + 1][j + val[i]], dp[i][j] + wei[i]); } int ans = 0; rep(j, vmax + 1) if (dp[n][j] <= w) ans = j; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i) #define all(n) begin(n), end(n) using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vc = vector<char>; using vb = vector<bool>; vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1}; int main() { int n, w; cin >> n >> w; vi wei(n), val(n); rep(i, n) cin >> wei[i] >> val[i]; int vmax = n * 1000; vector<vi> dp(n + 1, vi(vmax + 1, w + 1)); dp[0][0] = 0; rep(i, n) rep(j, vmax + 1) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); if (j + val[i] <= vmax) dp[i + 1][j + val[i]] = min(dp[i + 1][j + val[i]], dp[i][j] + wei[i]); } int ans = 0; rep(j, vmax + 1) if (dp[n][j] <= w) ans = j; cout << ans << endl; }
replace
24
25
24
26
-6
corrupted size vs. prev_size
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long using namespace std; vector<pair<int, int>> A; ll relaxed(int i, ll cap) { ll result = 0; while (i < A.size()) { if (A[i].first <= cap) { cap -= A[i].first; result += A[i].second; i++; } else { // result += (A[i].second * cap + A[i].first - 1) / A[i].first; result += A[i].second; break; } } return result; } ll backtrack(int i, ll cap) { if (i >= A.size()) return 0; if (A[i].first > cap) return backtrack(i + 1, cap); ll a = A[i].second + backtrack(i + 1, cap - A[i].first); ll b = relaxed(i + 1, cap); if (a >= b) return a; return max(a, backtrack(i + 1, cap)); } int main() { std::ios::sync_with_stdio(false); ll n, w, a, b; cin >> n >> w; A.resize(n); for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second; sort(A.begin(), A.end(), [](const pair<ll, ll> &x, const pair<ll, ll> &y) { if (x.second * y.first == y.second * x.first) return x.first < y.first; return x.second * y.first > y.second * x.first; }); cout << backtrack(0, w) << "\n"; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; vector<pair<int, int>> A; ll relaxed(int i, ll cap) { ll result = 0; while (i < A.size()) { if (A[i].first <= cap) { cap -= A[i].first; result += A[i].second; i++; } else { result += (A[i].second * cap + A[i].first - 1) / A[i].first; // result += A[i].second; break; } } return result; } ll backtrack(int i, ll cap) { if (i >= A.size()) return 0; if (A[i].first > cap) return backtrack(i + 1, cap); ll a = A[i].second + backtrack(i + 1, cap - A[i].first); ll b = relaxed(i + 1, cap); if (a >= b) return a; return max(a, backtrack(i + 1, cap)); } int main() { std::ios::sync_with_stdio(false); ll n, w, a, b; cin >> n >> w; A.resize(n); for (int i = 0; i < n; i++) cin >> A[i].first >> A[i].second; sort(A.begin(), A.end(), [](const pair<ll, ll> &x, const pair<ll, ll> &y) { if (x.second * y.first == y.second * x.first) return x.first < y.first; return x.second * y.first > y.second * x.first; }); cout << backtrack(0, w) << "\n"; return 0; }
replace
16
18
16
18
TLE
p03164
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) inline void chmin(int &a, int b) { if (a > b) a = b; } const int MAX_V = 1e7 + 10; const int INF = 1e9 + 10; int main() { int n, w; cin >> n >> w; vector<int> we(n), va(n); rep(i, n) cin >> we[i] >> va[i]; vector<vector<int>> dp(n + 1, vector<int>(MAX_V, INF)); dp[0][0] = 0; rep(i, n) { rep(j, MAX_V) { chmin(dp[i + 1][j], dp[i][j]); if (j >= va[i]) { chmin(dp[i + 1][j], dp[i][j - va[i]] + we[i]); } } } int ans = 0; rep(i, MAX_V) { if (dp[n][i] <= w) ans = i; } cout << ans << endl; }
#include <iostream> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) inline void chmin(int &a, int b) { if (a > b) a = b; } const int MAX_V = 1e5 + 10; const int INF = 1e9 + 10; int main() { int n, w; cin >> n >> w; vector<int> we(n), va(n); rep(i, n) cin >> we[i] >> va[i]; vector<vector<int>> dp(n + 1, vector<int>(MAX_V, INF)); dp[0][0] = 0; rep(i, n) { rep(j, MAX_V) { chmin(dp[i + 1][j], dp[i][j]); if (j >= va[i]) { chmin(dp[i + 1][j], dp[i][j - va[i]] + we[i]); } } } int ans = 0; rep(i, MAX_V) { if (dp[n][i] <= w) ans = i; } cout << ans << endl; }
replace
8
9
8
9
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define int long long int #define double long double #define mod 1000000007 #define w(t) \ int t; \ cin >> t; \ while (t--) #define f(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define pob pop_back #define mk make_pair #define ARMY \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; vector<string> v; int dp[101][100001]; int solve(int n, int *v, int *w, int wt) { for (int i = 0; i <= 100000; i++) dp[1][i] = 1e9 + 1; dp[1][0] = 0; dp[1][v[0]] = w[0]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= 100000; j++) { dp[i][j] = dp[i - 1][j]; if (v[i - 1] > j) continue; dp[i][j] = min(w[i - 1] + dp[i - 1][j - v[i - 1]], dp[i][j]); } } int ans = 0; f(i, 0, 100001) if (dp[n][i] <= wt) ans = i; return ans; } int32_t main() { ARMY w(t) { int n, wt; cin >> n >> wt; int a[n], w[n]; f(i, 0, n) cin >> w[i] >> a[i]; cout << solve(n, a, w, wt); } }
#include <bits/stdc++.h> #define int long long int #define double long double #define mod 1000000007 #define w(t) \ int t = 1; \ while (t--) #define f(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define pob pop_back #define mk make_pair #define ARMY \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; vector<string> v; int dp[101][100001]; int solve(int n, int *v, int *w, int wt) { for (int i = 0; i <= 100000; i++) dp[1][i] = 1e9 + 1; dp[1][0] = 0; dp[1][v[0]] = w[0]; for (int i = 2; i <= n; i++) { for (int j = 0; j <= 100000; j++) { dp[i][j] = dp[i - 1][j]; if (v[i - 1] > j) continue; dp[i][j] = min(w[i - 1] + dp[i - 1][j - v[i - 1]], dp[i][j]); } } int ans = 0; f(i, 0, 100001) if (dp[n][i] <= wt) ans = i; return ans; } int32_t main() { ARMY w(t) { int n, wt; cin >> n >> wt; int a[n], w[n]; f(i, 0, n) cin >> w[i] >> a[i]; cout << solve(n, a, w, wt); } }
replace
5
7
5
6
0
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll a[4][1000000]; ll n, w; ll dpdp[101][1000000]; ll inf = 1000000000000000; ll dp(ll x, ll m) { // cout << x << m<<" "; if (m <= 0) { dpdp[x][m] = 0; return 0; } if (x >= n) { dpdp[x][m] = inf; return inf; } if (dpdp[x][m] != inf) { // cout << "naklsjdf"; return dpdp[x][m]; } dpdp[x][m] = min(dp(x + 1, m - a[1][x]) + a[0][x], dp(x + 1, m)); // cout << dpdp[x][m]<<"\n"; return dpdp[x][m]; } int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); cin >> n >> w; for (int i = 0; i < n; ++i) { cin >> a[0][i] >> a[1][i]; } for (int i = 0; i < 101; ++i) { for (int j = 0; j < 100001; ++j) { dpdp[i][j] = inf; } } ll ans = 0; for (int i = 0; i < 100001; ++i) { if (dp(0, i) <= w) { ans = i; } // cout << dp(0, i)<<" "; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll a[4][1000000]; ll n, w; ll dpdp[101][1000000]; ll inf = 1000000000000000; ll dp(ll x, ll m) { // cout << x << m<<" "; if (m <= 0) { dpdp[x][m] = 0; return 0; } if (x >= n) { dpdp[x][m] = 2 * inf; return 2 * inf; } if (dpdp[x][m] != inf) { // cout << "naklsjdf"; return dpdp[x][m]; } dpdp[x][m] = min(dp(x + 1, m - a[1][x]) + a[0][x], dp(x + 1, m)); // cout << dpdp[x][m]<<"\n"; return dpdp[x][m]; } int main() { // ios_base::sync_with_stdio(false); // cin.tie(NULL); cin >> n >> w; for (int i = 0; i < n; ++i) { cin >> a[0][i] >> a[1][i]; } for (int i = 0; i < 101; ++i) { for (int j = 0; j < 100001; ++j) { dpdp[i][j] = inf; } } ll ans = 0; for (int i = 0; i < 100001; ++i) { if (dp(0, i) <= w) { ans = i; } // cout << dp(0, i)<<" "; } cout << ans << "\n"; return 0; }
replace
14
16
14
16
TLE
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, sum = 0, ans = INT_MIN; long long int w; long long int a[105][2]; long long int dp[105][10005]; cin >> n >> w; for (i = 1; i <= n; i++) { cin >> a[i][0] >> a[i][1]; sum += a[i][1]; } for (i = 0; i <= n; i++) { for (j = 0; j <= sum; j++) dp[i][j] = LLONG_MAX - INT_MAX; } for (i = 1; i <= n; i++) { for (j = 1; j <= sum; j++) { if (j <= a[i][1]) { dp[i][j] = min(dp[i - 1][j], a[i][0]); } else { if (dp[i - 1][j - a[i][1]] == INT_MAX) dp[i][j] = LLONG_MAX - INT_MAX; else { dp[i][j] = min(dp[i - 1][j], a[i][0] + dp[i - 1][j - a[i][1]]); } } if (dp[i][j] <= w) ans = max(ans, j); } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, i, j, sum = 0, ans = INT_MIN; long long int w; long long int a[105][2]; long long int dp[105][100005]; cin >> n >> w; for (i = 1; i <= n; i++) { cin >> a[i][0] >> a[i][1]; sum += a[i][1]; } for (i = 0; i <= n; i++) { for (j = 0; j <= sum; j++) dp[i][j] = LLONG_MAX - INT_MAX; } for (i = 1; i <= n; i++) { for (j = 1; j <= sum; j++) { if (j <= a[i][1]) { dp[i][j] = min(dp[i - 1][j], a[i][0]); } else { if (dp[i - 1][j - a[i][1]] == INT_MAX) dp[i][j] = LLONG_MAX - INT_MAX; else { dp[i][j] = min(dp[i - 1][j], a[i][0] + dp[i - 1][j - a[i][1]]); } } if (dp[i][j] <= w) ans = max(ans, j); } } cout << ans; return 0; }
replace
6
7
6
7
-11
p03164
C++
Runtime Error
#include <bits/stdc++.h> #include <iomanip> #include <math.h> #define rep(i, x) for (ll i = 0; i < x; i++) #define all(a) (a).begin(), (a).end() using ll = long long; using ld = long double; using namespace std; const ll INF = 1001001001; const ll mod = 1000000007; typedef pair<ll, ll> P; using graph = vector<vector<ll>>; ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b == 0) return b; else return gcd(b, a % b); } bool isp(ll n) { bool res = true; if (n == 1) return false; else { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res = false; break; } } return res; } } // printf("%.10f\n", N); /* ll memo[100000]; ll fibo(ll n){ if(memo[n] != 0)return memo[n]; if(n <= 1)return n; else return memo[n] = fibo(n - 1)+ fibo(n - 2); }*/ int main() { ll N, W; cin >> N >> W; vector<ll> weight(N); vector<ll> value(N); ll wa = 0; rep(i, N) { cin >> weight[i] >> value[i]; wa += value[i]; } vector<vector<ll>> memo(N + 1, vector<ll>(wa + 1, INF)); rep(i, N + 1) { memo[i][0] = 0; } rep(i, N) { rep(j, wa + 1) { if (memo[i + 1][j] < value[i]) { memo[i + 1][j] = min(memo[i][j], memo[i][0] + weight[i]); } else { memo[i + 1][j] = min(memo[i][j], memo[i][j - value[i]] + weight[i]); } } } ll ans = 0; rep(i, wa + 1) { if (memo[N][i] <= W) ans = i; } cout << ans << endl; }
#include <bits/stdc++.h> #include <iomanip> #include <math.h> #define rep(i, x) for (ll i = 0; i < x; i++) #define all(a) (a).begin(), (a).end() using ll = long long; using ld = long double; using namespace std; const ll INF = 1001001001; const ll mod = 1000000007; typedef pair<ll, ll> P; using graph = vector<vector<ll>>; ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (a % b == 0) return b; else return gcd(b, a % b); } bool isp(ll n) { bool res = true; if (n == 1) return false; else { for (ll i = 2; i * i <= n; i++) { if (n % i == 0) { res = false; break; } } return res; } } // printf("%.10f\n", N); /* ll memo[100000]; ll fibo(ll n){ if(memo[n] != 0)return memo[n]; if(n <= 1)return n; else return memo[n] = fibo(n - 1)+ fibo(n - 2); }*/ int main() { ll N, W; cin >> N >> W; vector<ll> weight(N); vector<ll> value(N); ll wa = 0; rep(i, N) { cin >> weight[i] >> value[i]; wa += value[i]; } vector<vector<ll>> memo(N + 1, vector<ll>(wa + 1, INF)); rep(i, N + 1) { memo[i][0] = 0; } rep(i, N) { rep(j, wa + 1) { if (j < value[i]) { memo[i + 1][j] = min(memo[i][j], memo[i][0] + weight[i]); } else { memo[i + 1][j] = min(memo[i][j], memo[i][j - value[i]] + weight[i]); } } } ll ans = 0; rep(i, wa + 1) { if (memo[N][i] <= W) ans = i; } cout << ans << endl; }
replace
57
58
57
58
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define tc(t) \ int t; \ cin >> t; \ while (t--) #define for0(i, n) for (int i = 0; i < n; i++) #define loop(i, a, b) for (int i = a; i <= b; i++) #define endl '\n' #define inf 1e18 #define fi first #define se second int XX[8] = {+1, +1, +1, 0, 0, -1, -1, -1}; int YY[8] = {+1, 0, -1, +1, -1, +1, 0, -1}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int wt[101], val[101]; int dp[101][1001]; int n, w; int knapsack(int ind, int v) { if (ind == n and v == 0) return 0; if (ind == n or v < 0) return inf; if (dp[ind][v] != -1) return dp[ind][v]; return dp[ind][v] = min(wt[ind] + knapsack(ind + 1, v - val[ind]), knapsack(ind + 1, v)); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> w; int sum = 0; for0(i, n) { cin >> wt[i] >> val[i]; sum += val[i]; } memset(dp, -1, sizeof(dp)); for (int i = sum; i >= 0; i--) { if (knapsack(0, i) <= w) { cout << i << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define tc(t) \ int t; \ cin >> t; \ while (t--) #define for0(i, n) for (int i = 0; i < n; i++) #define loop(i, a, b) for (int i = a; i <= b; i++) #define endl '\n' #define inf 1e18 #define fi first #define se second int XX[8] = {+1, +1, +1, 0, 0, -1, -1, -1}; int YY[8] = {+1, 0, -1, +1, -1, +1, 0, -1}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int wt[101], val[101]; int dp[101][100001]; int n, w; int knapsack(int ind, int v) { if (ind == n and v == 0) return 0; if (ind == n or v < 0) return inf; if (dp[ind][v] != -1) return dp[ind][v]; return dp[ind][v] = min(wt[ind] + knapsack(ind + 1, v - val[ind]), knapsack(ind + 1, v)); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> w; int sum = 0; for0(i, n) { cin >> wt[i] >> val[i]; sum += val[i]; } memset(dp, -1, sizeof(dp)); for (int i = sum; i >= 0; i--) { if (knapsack(0, i) <= w) { cout << i << endl; return 0; } } return 0; }
replace
30
31
30
31
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; void chmin(ll &a, ll b) { if (a > b) a = b; } 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]; } int sum_v = accumulate(v.begin(), v.end(), 0); vector<vector<ll>> dp(N + 1, vector<ll>(sum_v + 1, 1e9)); dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum_v; j++) { chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); chmin(dp[i + 1][j], dp[i][j]); } } int ans = 0; for (int i = 0; i <= sum_v; i++) { if (dp[N][i] <= W) ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; void chmin(ll &a, ll b) { if (a > b) a = b; } 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]; } int sum_v = accumulate(v.begin(), v.end(), 0); vector<vector<ll>> dp(N + 1, vector<ll>(sum_v + 1, 1e9)); dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j <= sum_v; j++) { if (j + v[i] <= sum_v + 1) chmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); chmin(dp[i + 1][j], dp[i][j]); } } int ans = 0; for (int i = 0; i <= sum_v; i++) { if (dp[N][i] <= W) ans = i; } cout << ans << endl; return 0; }
replace
23
24
23
25
0
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; typedef long long ll; int we[MAXN], val[MAXN]; ll mem[105][MAXN]; ll n, wmax; ll ans = 0; ll solve(int i, ll v) { if (v < 0) return 1e18; if (v == 0) return 0; if (i == n) return 1e18; ll &ret = mem[i][v]; ret = min(solve(i + 1, v), solve(i + 1, v - val[i]) + we[i]); return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> wmax; for (int i = 0; i < n; i++) cin >> we[i] >> val[i]; memset(mem, -1, sizeof(mem)); for (int i = 1; i <= 1e5; ++i) { if (solve(0, (ll)i) <= wmax) ans = i; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; typedef long long ll; int we[MAXN], val[MAXN]; ll mem[105][MAXN]; ll n, wmax; ll ans = 0; ll solve(int i, ll v) { if (v < 0) return 1e18; if (v == 0) return 0; if (i == n) return 1e18; ll &ret = mem[i][v]; if (ret != -1) return ret; ret = min(solve(i + 1, v), solve(i + 1, v - val[i]) + we[i]); return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> wmax; for (int i = 0; i < n; i++) cin >> we[i] >> val[i]; memset(mem, -1, sizeof(mem)); for (int i = 1; i <= 1e5; ++i) { if (solve(0, (ll)i) <= wmax) ans = i; } cout << ans; return 0; }
insert
17
17
17
19
TLE
p03164
C++
Memory Limit Exceeded
#include <bits/stdc++.h> #define N 505 #define ll long long int #define MP make_pair #define pb push_back #define ppb pop_back #define sp " " #define endl "\n" #define fi first #define se second #define ii pair<int, int> #define lli pair<ll, ll> #define fast \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(false) #define fast2 \ freopen("badhair.gir", "r", stdin); \ freopen("badhair.cik", "w", stdout); #define mod 1000000007 #define fs(x, y) \ for (ll i = 1; i <= y; i++) \ cin >> x[i] #define fo(i, x, y) for (ll i = x; i <= y; i++) #define INF 1000000000005 using namespace std; ll n, m, ar[N], sum, t, W, w[N], v[N], flag; ll dp[N][500005]; ll f(int ind, int val) { if (dp[ind][val] != -1) return dp[ind][val]; if (val == 0) return dp[ind][val] = 0; if (ind == n + 1) { return dp[ind][val] = 1e12; } return dp[ind][val] = min(f(ind + 1, val), f(ind + 1, val - v[ind]) + w[ind]); } int main() { fast; cin >> n >> W; fo(i, 1, n) cin >> w[i] >> v[i]; memset(dp, -1, sizeof(dp)); for (int i = 0; i <= 1e5 + 100; i++) { f(1, i); fo(j, 1, n) if (dp[j][i] <= W && dp[j][i] != -1) sum = i; } cout << sum; } /* cd onedrive\desktop\kod cls Sinav:21-22 aralik Aciklama: Muhtemelen 25 aralik */
#include <bits/stdc++.h> #define N 505 #define ll long long int #define MP make_pair #define pb push_back #define ppb pop_back #define sp " " #define endl "\n" #define fi first #define se second #define ii pair<int, int> #define lli pair<ll, ll> #define fast \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(false) #define fast2 \ freopen("badhair.gir", "r", stdin); \ freopen("badhair.cik", "w", stdout); #define mod 1000000007 #define fs(x, y) \ for (ll i = 1; i <= y; i++) \ cin >> x[i] #define fo(i, x, y) for (ll i = x; i <= y; i++) #define INF 1000000000005 using namespace std; ll n, m, ar[N], sum, t, W, w[N], v[N], flag; ll dp[N][200005]; ll f(int ind, int val) { if (dp[ind][val] != -1) return dp[ind][val]; if (val == 0) return dp[ind][val] = 0; if (ind == n + 1) { return dp[ind][val] = 1e12; } return dp[ind][val] = min(f(ind + 1, val), f(ind + 1, val - v[ind]) + w[ind]); } int main() { fast; cin >> n >> W; fo(i, 1, n) cin >> w[i] >> v[i]; memset(dp, -1, sizeof(dp)); for (int i = 0; i <= 1e5 + 100; i++) { f(1, i); fo(j, 1, n) if (dp[j][i] <= W && dp[j][i] != -1) sum = i; } cout << sum; } /* cd onedrive\desktop\kod cls Sinav:21-22 aralik Aciklama: Muhtemelen 25 aralik */
replace
29
30
29
30
MLE
p03164
C++
Runtime Error
// rohitaas_15 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #define co(x) cout << x << "\n"; #define ld long double #define ll long long #define int ll #define dd double #define rohitaas_15() \ ; \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define all(v) v.begin(), v.end() #define f(a, b) for (int i = a; i <= b; i++) #define f2(a, b) for (int j = a; j <= b; j++) #define f3(a, b) for (int kk = a; kk <= b; kk++) #define pb push_back #define mp make_pair #define pii pair<ll, ll> #define ff first #define ss second #define nl cout << "\n" #define lb(v, x) lower_bound(v.begin(), v.end(), x) #define ub(v, x) upper_bound(v.begin(), v.end(), x) #define pv(v, x, n) \ if (n != 0) { \ f(x, n - 1) { cout << v[i] << " "; } \ cout << endl; \ } #define cn(v, x, n) \ f(x, n) { cin >> v[i]; } #define M1 1000000007 #define M2 998244353 #define con continue #define maxv(v) *max_element(all(v)); #define minv(v) *min_element(all(v)); #define sumv(v) accumulate(all(v), 0ll) #define pf push_front #define popb pop_back #define popf pop_front #define br break #define rev(x) reverse(all(x)) #define vr vector<ll> #define vvr vector<vr> #define vvvr vector<vvr> #define vll vector<pii> #define PI 3.141592653 #define MLL map<ll, ll> #define fbo find_by_order #define ook order_of_key #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define debug1(a) cout << #a << " = " << (a) << endl; #define debug2(a, b) \ cout << #a << " = " << (a) << ", " << #b << " = " << (b) << endl #define debug3(a, b, c) \ cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c \ << " = " << (c) << endl #define debug4(a, b, c, d) \ cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c \ << " = " << (c) << ", " << #d << " = " << (d) << endl mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void randomize(vr &in, ll x) { f(0, in.size() - 1) in[i] = rand() % x + 1; } ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll modmul(ll a, ll b, ll mod) { return ((a % mod) * (b % mod)) % mod; } ll modadd(ll a, ll b, ll mod) { return ((a % mod) + (b % mod) + mod) % mod; } ll modsub(ll a, ll b, ll mod) { return ((a % mod) - (b % mod) + mod) % mod; } ll moduloMul(ll a, ll b, ll mod) { ll res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b >>= 1; } return res; } ll power(ll x, ll y, ll p = LLONG_MAX) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll XFEEA, YFEEA, GCDFEEA; double power2(double x, ll y) { double res = 1; while (y > 0) { if (y & 1) res = (double)(res * x); y = y >> 1; x = (double)(x * x); } return res; } void extendedEuclidAlgo(ll a, ll b) { if (b == 0) { XFEEA = 1; YFEEA = 0; GCDFEEA = a; return; } extendedEuclidAlgo(b, a % b); ll cx = YFEEA; ll cy = XFEEA - (a / b) * YFEEA; YFEEA = cy; XFEEA = cx; } ll modInverse(ll n, ll m) { extendedEuclidAlgo(n, m); return (XFEEA % m + m) % m; } ll CmP(ll n, ll r, ll p = M1) { if (r == 0) return 1; ll fac[n + 1]; fac[0] = 1; for (ll i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } bool isSAFE(ll i, ll j, ll m, ll n) { return (i >= 1 && i <= m && j >= 1 && j <= n); } typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedset; /*find_by_order(ll k){returns the iterator to the kth smallest element,start from 0,O(logn)} order_of_key(ll k){returns the number of elements in the set which are strictly less than our k,O(logn)}*/ // vector<vr> g; // vvr mat; vector<ll> in, w, v; ll n, W; vector<vll> dp; void solve() {} void ask() {} signed main() { rohitaas_15(); ll t = 1; // cin>>t; ll cases = t; while (t--) { cin >> n >> W; in.resize(n + 1); w.resize(n + 1); v.resize(n + 1); ll sum = 0; f(1, n) { ll x, y; cin >> x >> y; w[i] = x; v[i] = y; sum += y; } dp.resize(n + 1, vll(sum + 1, mp(0, 1e18))); f(0, n) { dp[i][0].ff = 1; dp[i][0].ss = 0; } f(1, n) { f2(1, sum) { if (dp[i - 1][j - v[i]].ss + w[i] <= W && v[i] <= j) { if (dp[i - 1][j - v[i]].ff) { dp[i][j].ff = 1; dp[i][j].ss = w[i] + dp[i - 1][j - v[i]].ss; } } if (dp[i - 1][j].ff) { dp[i][j].ff = 1; dp[i][j].ss = min(dp[i - 1][j].ss, ((v[i] <= j) ? w[i] + dp[i - 1][j - v[i]].ss : LLONG_MAX)); } } } ll ans = -1; f(1, sum) { if (dp[n][i].ff == 1) { ans = i; } } co(ans); } // printclock; } /*cout<<"Case #"<<cases-t<<": ";*/
// rohitaas_15 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; // #pragma GCC optimize("Ofast") // #pragma GCC target("avx,avx2,fma") #define co(x) cout << x << "\n"; #define ld long double #define ll long long #define int ll #define dd double #define rohitaas_15() \ ; \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define all(v) v.begin(), v.end() #define f(a, b) for (int i = a; i <= b; i++) #define f2(a, b) for (int j = a; j <= b; j++) #define f3(a, b) for (int kk = a; kk <= b; kk++) #define pb push_back #define mp make_pair #define pii pair<ll, ll> #define ff first #define ss second #define nl cout << "\n" #define lb(v, x) lower_bound(v.begin(), v.end(), x) #define ub(v, x) upper_bound(v.begin(), v.end(), x) #define pv(v, x, n) \ if (n != 0) { \ f(x, n - 1) { cout << v[i] << " "; } \ cout << endl; \ } #define cn(v, x, n) \ f(x, n) { cin >> v[i]; } #define M1 1000000007 #define M2 998244353 #define con continue #define maxv(v) *max_element(all(v)); #define minv(v) *min_element(all(v)); #define sumv(v) accumulate(all(v), 0ll) #define pf push_front #define popb pop_back #define popf pop_front #define br break #define rev(x) reverse(all(x)) #define vr vector<ll> #define vvr vector<vr> #define vvvr vector<vvr> #define vll vector<pii> #define PI 3.141592653 #define MLL map<ll, ll> #define fbo find_by_order #define ook order_of_key #define printclock \ cerr << "Time : " << 1000 * (ld)clock() / (ld)CLOCKS_PER_SEC << "ms\n"; #define debug1(a) cout << #a << " = " << (a) << endl; #define debug2(a, b) \ cout << #a << " = " << (a) << ", " << #b << " = " << (b) << endl #define debug3(a, b, c) \ cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c \ << " = " << (c) << endl #define debug4(a, b, c, d) \ cout << #a << " = " << (a) << ", " << #b << " = " << (b) << ", " << #c \ << " = " << (c) << ", " << #d << " = " << (d) << endl mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void randomize(vr &in, ll x) { f(0, in.size() - 1) in[i] = rand() % x + 1; } ll gcd(ll a, ll b) { if (!b) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll modmul(ll a, ll b, ll mod) { return ((a % mod) * (b % mod)) % mod; } ll modadd(ll a, ll b, ll mod) { return ((a % mod) + (b % mod) + mod) % mod; } ll modsub(ll a, ll b, ll mod) { return ((a % mod) - (b % mod) + mod) % mod; } ll moduloMul(ll a, ll b, ll mod) { ll res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b >>= 1; } return res; } ll power(ll x, ll y, ll p = LLONG_MAX) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll XFEEA, YFEEA, GCDFEEA; double power2(double x, ll y) { double res = 1; while (y > 0) { if (y & 1) res = (double)(res * x); y = y >> 1; x = (double)(x * x); } return res; } void extendedEuclidAlgo(ll a, ll b) { if (b == 0) { XFEEA = 1; YFEEA = 0; GCDFEEA = a; return; } extendedEuclidAlgo(b, a % b); ll cx = YFEEA; ll cy = XFEEA - (a / b) * YFEEA; YFEEA = cy; XFEEA = cx; } ll modInverse(ll n, ll m) { extendedEuclidAlgo(n, m); return (XFEEA % m + m) % m; } ll CmP(ll n, ll r, ll p = M1) { if (r == 0) return 1; ll fac[n + 1]; fac[0] = 1; for (ll i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } bool isSAFE(ll i, ll j, ll m, ll n) { return (i >= 1 && i <= m && j >= 1 && j <= n); } typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedset; /*find_by_order(ll k){returns the iterator to the kth smallest element,start from 0,O(logn)} order_of_key(ll k){returns the number of elements in the set which are strictly less than our k,O(logn)}*/ // vector<vr> g; // vvr mat; vector<ll> in, w, v; ll n, W; vector<vll> dp; void solve() {} void ask() {} signed main() { rohitaas_15(); ll t = 1; // cin>>t; ll cases = t; while (t--) { cin >> n >> W; in.resize(n + 1); w.resize(n + 1); v.resize(n + 1); ll sum = 0; f(1, n) { ll x, y; cin >> x >> y; w[i] = x; v[i] = y; sum += y; } dp.resize(n + 1, vll(sum + 1, mp(0, 1e18))); f(0, n) { dp[i][0].ff = 1; dp[i][0].ss = 0; } f(1, n) { f2(1, sum) { if (v[i] <= j && dp[i - 1][j - v[i]].ss + w[i] <= W) { if (dp[i - 1][j - v[i]].ff) { dp[i][j].ff = 1; dp[i][j].ss = w[i] + dp[i - 1][j - v[i]].ss; } } if (dp[i - 1][j].ff) { dp[i][j].ff = 1; dp[i][j].ss = min(dp[i - 1][j].ss, ((v[i] <= j) ? w[i] + dp[i - 1][j - v[i]].ss : LLONG_MAX)); } } } ll ans = -1; f(1, sum) { if (dp[n][i].ff == 1) { ans = i; } } co(ans); } // printclock; } /*cout<<"Case #"<<cases-t<<": ";*/
replace
182
183
182
183
0
p03164
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define mkp make_pair #define pi pair<int, int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define repd(i, l, r) for (int i = (int)(l); i >= (int)(r); i--) int power(int x, unsigned int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } int powermod(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } #define print2d(mat, n, m) \ { \ for (int i = 0; i < (int)(n); i++) { \ for (int j = 0; j < (m); j++) { \ cout << mat[i][j] << " "; \ } \ cout << endl; \ } \ } #define print1d(mat, n) \ { \ for (int i = 0; i < (int)(n); i++) \ cout << mat[i] << " "; \ cout << endl; \ } #define clr(a, x) memset(a, x, sizeof(a)) #define rr(v) for (auto &val : v) #define printpair(v) \ for (auto val : v) { \ cout << val.fi << ":" << val.se << ", "; \ } \ cout << endl; #define print(v) \ for (const auto itr : v) { \ cout << itr << ' '; \ } \ cout << endl; #define init(v, x) \ for (auto &itr : v) { \ itr = x; \ } #define ln length() const int mod = 998244353; #define sz size() const int inf = 1e18; int n, w; int warr[105], varr[105]; int tv; int dp[105][100005]; int f(int i, int currv) { if (currv >= tv) { return 0; } if (i == n) { return inf; } if (dp[i][currv] != -1) { return dp[i][currv]; } int lol; int ans = inf; lol = f(i + 1, currv + varr[i]); if (lol != inf) { ans = min(ans, lol + warr[i]); } lol = f(i + 1, currv); if (lol != inf) { ans = min(ans, lol); } if (ans != inf) { dp[i][currv] = ans; } return ans; } void solve() { cin >> n >> w; int totv = 0; rep(i, 0, n) { cin >> warr[i] >> varr[i]; totv += varr[i]; } int hi, lo, mid; hi = totv; lo = 0; while (lo <= hi) { mid = (hi + lo) / 2; tv = mid; clr(dp, -1); if (f(0, 0) <= w) { lo = mid + 1; } else { hi = mid - 1; } } cout << lo - 1 << endl; } int32_t main() { fastIO #ifndef ONLINE_JUDGE freopen(R"(C:\Users\swast\CLionProjects\untitled\input.txt)", "r", stdin); #endif int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define mkp make_pair #define pi pair<int, int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define repd(i, l, r) for (int i = (int)(l); i >= (int)(r); i--) int power(int x, unsigned int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } int powermod(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } #define print2d(mat, n, m) \ { \ for (int i = 0; i < (int)(n); i++) { \ for (int j = 0; j < (m); j++) { \ cout << mat[i][j] << " "; \ } \ cout << endl; \ } \ } #define print1d(mat, n) \ { \ for (int i = 0; i < (int)(n); i++) \ cout << mat[i] << " "; \ cout << endl; \ } #define clr(a, x) memset(a, x, sizeof(a)) #define rr(v) for (auto &val : v) #define printpair(v) \ for (auto val : v) { \ cout << val.fi << ":" << val.se << ", "; \ } \ cout << endl; #define print(v) \ for (const auto itr : v) { \ cout << itr << ' '; \ } \ cout << endl; #define init(v, x) \ for (auto &itr : v) { \ itr = x; \ } #define ln length() const int mod = 998244353; #define sz size() const int inf = 1e18; int n, w; int warr[105], varr[105]; int tv; int dp[105][100005]; int f(int i, int currv) { if (currv >= tv) { return 0; } if (i == n) { return inf; } if (dp[i][currv] != -1) { return dp[i][currv]; } int lol; int ans = inf; lol = f(i + 1, currv + varr[i]); if (lol != inf) { ans = min(ans, lol + warr[i]); } lol = f(i + 1, currv); if (lol != inf) { ans = min(ans, lol); } dp[i][currv] = ans; return ans; } void solve() { cin >> n >> w; int totv = 0; rep(i, 0, n) { cin >> warr[i] >> varr[i]; totv += varr[i]; } int hi, lo, mid; hi = totv; lo = 0; while (lo <= hi) { mid = (hi + lo) / 2; tv = mid; clr(dp, -1); if (f(0, 0) <= w) { lo = mid + 1; } else { hi = mid - 1; } } cout << lo - 1 << endl; } int32_t main() { fastIO #ifndef ONLINE_JUDGE freopen(R"(C:\Users\swast\CLionProjects\untitled\input.txt)", "r", stdin); #endif int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
97
100
97
100
TLE
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n, m; long long w[110], v[110]; long long f[1010]; long long value; int main() { memset(f, 0x3f, sizeof(f)); scanf("%lld%lld", &n, &m); for (long long i = 1; i <= n; i++) { scanf("%lld%lld", &w[i], &v[i]); value += v[i]; } f[0] = 0; for (long long i = 1; i <= n; i++) { for (long long j = value; j >= v[i]; j--) { f[j] = min(f[j], f[j - v[i]] + w[i]); } } for (long long i = value; i >= 1; i--) { if (f[i] <= m) { printf("%lld", i); return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, m; long long w[110], v[110]; long long f[100010]; long long value; int main() { memset(f, 0x3f, sizeof(f)); scanf("%lld%lld", &n, &m); for (long long i = 1; i <= n; i++) { scanf("%lld%lld", &w[i], &v[i]); value += v[i]; } f[0] = 0; for (long long i = 1; i <= n; i++) { for (long long j = value; j >= v[i]; j--) { f[j] = min(f[j], f[j - v[i]] + w[i]); } } for (long long i = value; i >= 1; i--) { if (f[i] <= m) { printf("%lld", i); return 0; } } return 0; }
replace
4
5
4
5
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long ll dp[10000]; long long N = 0, W = 0, V = 0, wi[10000], vi[10000]; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> wi[i] >> vi[i]; V += vi[i]; } for (int i = 1; i <= V; i++) { dp[i] = INT_MAX; } dp[0] = 0; for (int item = 1; item <= N; item++) { int w = wi[item], v = vi[item]; for (int i = V; i >= v; i--) { dp[i] = min(dp[i], dp[i - v] + w); } } for (int i = V; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long ll dp[1000000]; long long N = 0, W = 0, V = 0, wi[1000000], vi[1000000]; int main() { cin >> N >> W; for (int i = 1; i <= N; i++) { cin >> wi[i] >> vi[i]; V += vi[i]; } for (int i = 1; i <= V; i++) { dp[i] = INT_MAX; } dp[0] = 0; for (int item = 1; item <= N; item++) { int w = wi[item], v = vi[item]; for (int i = V; i >= v; i--) { dp[i] = min(dp[i], dp[i - v] + w); } } for (int i = V; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; break; } } return 0; }
replace
4
6
4
6
0
p03164
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; ////////////// Prewritten code follows. Look down for solution. //////////////// #define fs first #define sc second #define pb push_back #define len(x) ((int)(x).size()) #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; const ll LINF = 1e18; const int INF = 1e9; const int MOD = 1e9 + 7; /// command for char arrays with spaces -> scanf(" %[^\n]", text); ////////////////////////// Solution starts below. ////////////////////////////// int main() { fastio; int n; ll p; cin >> n >> p; int max_value = 0; vector<int> valor(n); vector<ll> peso(n); for (int i = 1; i <= n; i++) { cin >> peso[i] >> valor[i]; max_value += valor[i]; } vector<ll> dp(max_value + 1, LINF); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = max_value - valor[i]; j >= 0; j--) { dp[j + valor[i]] = min(dp[j + valor[i]], dp[j] + peso[i]); } } int ans = 0; for (int i = max_value; i >= 0; i--) { if (dp[i] <= p) { ans = i; break; } } cout << ans << '\n'; return 0; }
#include "bits/stdc++.h" using namespace std; ////////////// Prewritten code follows. Look down for solution. //////////////// #define fs first #define sc second #define pb push_back #define len(x) ((int)(x).size()) #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); typedef pair<int, int> pii; typedef vector<int> vi; typedef long long ll; const ll LINF = 1e18; const int INF = 1e9; const int MOD = 1e9 + 7; /// command for char arrays with spaces -> scanf(" %[^\n]", text); ////////////////////////// Solution starts below. ////////////////////////////// int main() { fastio; int n; ll p; cin >> n >> p; int max_value = 0; vector<int> valor(n + 1); vector<ll> peso(n + 1); for (int i = 1; i <= n; i++) { cin >> peso[i] >> valor[i]; max_value += valor[i]; } vector<ll> dp(max_value + 1, LINF); dp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = max_value - valor[i]; j >= 0; j--) { dp[j + valor[i]] = min(dp[j + valor[i]], dp[j] + peso[i]); } } int ans = 0; for (int i = max_value; i >= 0; i--) { if (dp[i] <= p) { ans = i; break; } } cout << ans << '\n'; return 0; }
replace
30
32
30
32
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for (int i = (l); i < (r); i++) #define incII(i, l, r) for (int i = (l); i <= (r); i++) #define decID(i, l, r) for (int i = (r)-1; i >= (l); i--) #define decII(i, l, r) for (int i = (r); i >= (l); i--) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define PQ priority_queue #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define FOR(it, v) for (auto it = v.begin(); it != v.end(); ++it) #define RFOR(it, v) for (auto it = v.rbegin(); it != v.rend(); ++it) template <typename T> bool setmin(T &a, T b) { if (b < a) { a = b; return true; } else { return false; } } template <typename T> bool setmax(T &a, T b) { if (b > a) { a = b; return true; } else { return false; } } template <typename T> bool setmineq(T &a, T b) { if (b <= a) { a = b; return true; } else { return false; } } template <typename T> bool setmaxeq(T &a, T b) { if (b >= a) { a = b; return true; } else { return false; } } template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } // ---- ---- const int V = 100000; LL n, W, w[100], v[100], dp[V + 1], INF = 1e12; int main() { cin >> n >> W; inc(i, n) { cin >> w[i] >> v[i]; } incII(j, 0, V) { dp[j] = INF; } dp[0] = 0; inc(i, n) { decII(j, 0, V) { setmin(dp[j + v[i]], dp[j] + w[i]); } } LL ans = 0; incII(j, 0, V) { if (dp[j] <= W) { ans = j; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long signed int LL; typedef long long unsigned int LU; #define incID(i, l, r) for (int i = (l); i < (r); i++) #define incII(i, l, r) for (int i = (l); i <= (r); i++) #define decID(i, l, r) for (int i = (r)-1; i >= (l); i--) #define decII(i, l, r) for (int i = (r); i >= (l); i--) #define inc(i, n) incID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec(i, n) decID(i, 0, n) #define dec1(i, n) decII(i, 1, n) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define PQ priority_queue #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define FOR(it, v) for (auto it = v.begin(); it != v.end(); ++it) #define RFOR(it, v) for (auto it = v.rbegin(); it != v.rend(); ++it) template <typename T> bool setmin(T &a, T b) { if (b < a) { a = b; return true; } else { return false; } } template <typename T> bool setmax(T &a, T b) { if (b > a) { a = b; return true; } else { return false; } } template <typename T> bool setmineq(T &a, T b) { if (b <= a) { a = b; return true; } else { return false; } } template <typename T> bool setmaxeq(T &a, T b) { if (b >= a) { a = b; return true; } else { return false; } } template <typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } // ---- ---- const int V = 100000; LL n, W, w[100], v[100], dp[V + 1001], INF = 1e12; int main() { cin >> n >> W; inc(i, n) { cin >> w[i] >> v[i]; } incII(j, 0, V) { dp[j] = INF; } dp[0] = 0; inc(i, n) { decII(j, 0, V) { setmin(dp[j + v[i]], dp[j] + w[i]); } } LL ans = 0; incII(j, 0, V) { if (dp[j] <= W) { ans = j; } } cout << ans << endl; return 0; }
replace
68
69
68
69
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define test() \ ll t; \ cin >> t; \ while (t--) #define MOD 1000000007 #define SPEED \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) int main() { SPEED; // CODE ll n, W; cin >> n >> W; ll w[n], v[n]; ll ans = 0; for (ll i = 0; i < n; i++) cin >> w[i] >> v[i]; ll dp[2][100001]; for (ll i = 0; i < 2; i++) { for (ll j = 0; j < 100001; j++) { dp[i][j] = 1e9; } } dp[0][0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j < 100001; j++) { if (dp[0][j] != 10e9) { dp[1][j] = min(dp[1][j], dp[0][j]); dp[1][j + v[i - 1]] = min(dp[1][j + v[i - 1]], dp[0][j] + w[i - 1]); } } for (ll j = 0; j < 100001; j++) { dp[0][j] = dp[1][j]; } } for (ll i = 0; i < 100001; i++) { if (dp[1][i] <= W) { ans = i; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define test() \ ll t; \ cin >> t; \ while (t--) #define MOD 1000000007 #define SPEED \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) int main() { SPEED; // CODE ll n, W; cin >> n >> W; ll w[n], v[n]; ll ans = 0; for (ll i = 0; i < n; i++) cin >> w[i] >> v[i]; ll dp[2][100001]; for (ll i = 0; i < 2; i++) { for (ll j = 0; j < 100001; j++) { dp[i][j] = 10e9; } } dp[0][0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = 0; j < 100001; j++) { if (dp[0][j] != 10e9) { dp[1][j] = min(dp[1][j], dp[0][j]); dp[1][j + v[i - 1]] = min(dp[1][j + v[i - 1]], dp[0][j] + w[i - 1]); } } for (ll j = 0; j < 100001; j++) { dp[0][j] = dp[1][j]; } } for (ll i = 0; i < 100001; i++) { if (dp[1][i] <= W) { ans = i; } } cout << ans; return 0; }
replace
25
26
25
26
-11
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int using namespace std; const ll INF = 1e18L + 5; int main() { ll n, W, sum = 0; cin >> n >> W; vector<ll> wt(n), v(n); for (ll i = 1; i <= n; i++) { cin >> wt[i] >> v[i]; sum += v[i]; } vector<ll> dp(sum + 1, INF); dp[0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = sum; j >= v[i]; j--) { dp[j] = min(dp[j], wt[i] + dp[j - v[i]]); } } ll ans = 0; ll i; for (i = sum; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; break; } } }
#include <bits/stdc++.h> #define ll long long int using namespace std; const ll INF = 1e18L + 5; int main() { ll n, W, sum = 0; cin >> n >> W; vector<ll> wt(n + 1), v(n + 1); for (ll i = 1; i <= n; i++) { cin >> wt[i] >> v[i]; sum += v[i]; } vector<ll> dp(sum + 1, INF); dp[0] = 0; for (ll i = 1; i <= n; i++) { for (ll j = sum; j >= v[i]; j--) { dp[j] = min(dp[j], wt[i] + dp[j - v[i]]); } } ll ans = 0; ll i; for (i = sum; i >= 0; i--) { if (dp[i] <= W) { cout << i << endl; break; } } }
replace
8
9
8
9
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p03164
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll INF = 1LL << 60; ll dp[100][100009]; int main() { int n; ll w; cin >> n >> w; vector<ll> wight(n); vector<ll> val(n); rep(i, n) { cin >> wight[i] >> val[i]; } rep(i, n + 1) rep(j, 100001) dp[i][j] = INF; dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= 100000; j++) { if (j - val[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - val[i]] + wight[i]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (int g = 0; g <= 100000; g++) { if (dp[n][g] <= w) ans = max(ll(g), ans); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) const ll INF = 1LL << 60; ll dp[105][100009]; int main() { int n; ll w; cin >> n >> w; vector<ll> wight(n); vector<ll> val(n); rep(i, n) { cin >> wight[i] >> val[i]; } rep(i, n + 1) rep(j, 100001) dp[i][j] = INF; dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= 100000; j++) { if (j - val[i] >= 0) dp[i + 1][j] = min(dp[i][j], dp[i][j - val[i]] + wight[i]); else dp[i + 1][j] = dp[i][j]; } } ll ans = 0; for (int g = 0; g <= 100000; g++) { if (dp[n][g] <= w) ans = max(ll(g), ans); } cout << ans << endl; return 0; }
replace
12
13
12
13
0
p03164
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1LL << 60; const int MAX_V = pow(10, 3) * 100 + 1; int main() { int N; long long W; cin >> N >> W; int MAX_N = N; vector<long long> weight(MAX_N), value(MAX_N); for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_V, INF)); dp[0][0] = 0; // DPループ for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i 番目の品物を選ぶ場合 if (sum_v - value[i] >= 0) chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]); // i 番目の品物を選ばない場合 chmin(dp[i + 1][sum_v], dp[i][sum_v]); } } // 最適値の出力 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 <cmath> #include <iostream> #include <vector> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1LL << 60; const int MAX_V = pow(10, 3) * 100 + 1; int main() { int N; long long W; cin >> N >> W; int MAX_N = N + 1; vector<long long> weight(MAX_N), value(MAX_N); for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i]; vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_V, INF)); dp[0][0] = 0; // DPループ for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i 番目の品物を選ぶ場合 if (sum_v - value[i] >= 0) chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]); // i 番目の品物を選ばない場合 chmin(dp[i + 1][sum_v], dp[i][sum_v]); } } // 最適値の出力 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
22
23
22
23
-11
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define intt long long const intt INF = 1e18L + 5; int n, W; int main() { cin >> n >> W; vector<int> v(n + 1), w(n + 1); for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } int V = 0; for (int i = 1; i <= n; i++) { V += v[i]; } vector<intt> dp(V + 1, INF); // dp[i] -> the minimum total weight of knapsack with value exactly i dp[0] = 0; for (int k = 1; k <= n; k++) { for (int x = V; x >= 0; x--) { dp[x] = min(dp[x], w[k] + dp[x - v[k]]); } } int ans = 0; for (int i = 0; i <= V; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define intt long long const intt INF = 1e18L + 5; int n, W; int main() { cin >> n >> W; vector<int> v(n + 1), w(n + 1); for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; } int V = 0; for (int i = 1; i <= n; i++) { V += v[i]; } vector<intt> dp(V + 1, INF); // dp[i] -> the minimum total weight of knapsack with value exactly i dp[0] = 0; for (int k = 1; k <= n; k++) { for (int x = V; x >= 0; x--) { if (x - v[k] >= 0) { dp[x] = min(dp[x], w[k] + dp[x - v[k]]); } } } int ans = 0; for (int i = 0; i <= V; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << '\n'; return 0; }
replace
29
30
29
32
0
p03164
C++
Runtime Error
#include <iostream> using namespace std; int w[110], v[110]; long long int dp[1100]; int INF = 1000000009; int N, W; int main() { for (int i = 0; i < 100001; i++) dp[i] = INF; cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 100000; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } int ans = 0; for (int i = 0; i < 100001; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int w[110], v[110]; long long int dp[110000]; int INF = 1000000009; int N, W; int main() { for (int i = 0; i < 100001; i++) dp[i] = INF; cin >> N >> W; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; } dp[0] = 0; for (int i = 0; i < N; i++) { for (int j = 100000; j >= v[i]; j--) { dp[j] = min(dp[j], dp[j - v[i]] + w[i]); } } int ans = 0; for (int i = 0; i < 100001; i++) { if (dp[i] <= W) { ans = max(ans, i); } } cout << ans << endl; return 0; }
replace
4
5
4
5
-11
p03164
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { static ll INF = 1000000000000; int N, W; cin >> N >> W; vector<int> w(N); vector<int> v(N); vector<vector<ll>> dp(N + 1, vector<ll>(100009, INF)); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < 100009; j++) if (dp[i][j] >= 0) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ll mv = 0; for (int i = 0; i < 100009; i++) { if (dp[N][i] <= W) mv = i; } cout << mv << endl; }
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { static ll INF = 1000000000000; int N, W; cin >> N >> W; vector<int> w(N); vector<int> v(N); vector<vector<ll>> dp(N + 1, vector<ll>(200009, INF)); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < 100009; j++) if (dp[i][j] >= 0) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } ll mv = 0; for (int i = 0; i < 100009; i++) { if (dp[N][i] <= W) mv = i; } cout << mv << endl; }
replace
12
13
12
13
0
p03164
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> using namespace std; typedef long long ll; const long long inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; ll n, k; struct node { ll w; ll v; } a[100005]; ll dp[100005]; int main() { cin >> n >> k; ll sumv = 0; for (ll i = 1; i <= n; i++) { cin >> a[i].w >> a[i].v; sumv += a[i].v; } for (int i = 1; i <= 1e5; i++) { dp[i] = INF; } for (int i = 1; i <= n; i++) { for (int j = 1e5; j >= 0; j--) { dp[j] = (dp[j] < (dp[j - a[i].v] + a[i].w) ? dp[j] : (dp[j - a[i].v] + a[i].w)); } } ll ans = 0; for (int i = 1e5; i >= 1; i--) { if (dp[i] <= k) { ans = i; break; } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> using namespace std; typedef long long ll; const long long inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; ll n, k; struct node { ll w; ll v; } a[100005]; ll dp[100005]; int main() { cin >> n >> k; ll sumv = 0; for (ll i = 1; i <= n; i++) { cin >> a[i].w >> a[i].v; sumv += a[i].v; } for (int i = 1; i <= 1e5; i++) { dp[i] = INF; } for (int i = 1; i <= n; i++) { for (int j = 1e5; j >= a[i].v; j--) { dp[j] = (dp[j] < (dp[j - a[i].v] + a[i].w) ? dp[j] : (dp[j - a[i].v] + a[i].w)); } } ll ans = 0; for (int i = 1e5; i >= 1; i--) { if (dp[i] <= k) { ans = i; break; } } cout << ans << endl; return 0; }
replace
35
36
35
36
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 #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 sa(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define scan() \ int n; \ cin >> n; \ int a[n]; \ for (int i = 0; i < n; i++) \ cin >> a[i] #define print(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << ' ' using namespace std; template <typename T, typename U> T max(T x, U y) { return x > y ? x : y; } template <typename T, typename U> T min(T x, U y) { return x < y ? x : y; } ll dp[101][1001]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, w; cin >> n >> w; ll a[n], b[n]; ll d = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; cin >> b[i]; d += b[i]; } for (int i = 0; i <= n; ++i) { for (int j = 0; j <= d; ++j) { dp[i][j] = 1e18; } } /*for (int i = 0; i <=n; ++i) { for (int j = 0; j <=w; ++j) { trace(dp[i][j]); } }*/ ll ans = -1; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= d; ++j) { if (i == 0 and j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = 1e18; else if (j == 0) dp[i][j] = 0; else if (b[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]); else dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } for (int j = 0; j <= d; ++j) { if (dp[n][j] <= w and ans < j) ans = j; } cout << ans; }
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 #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 sa(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i] #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define scan() \ int n; \ cin >> n; \ int a[n]; \ for (int i = 0; i < n; i++) \ cin >> a[i] #define print(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << ' ' using namespace std; template <typename T, typename U> T max(T x, U y) { return x > y ? x : y; } template <typename T, typename U> T min(T x, U y) { return x < y ? x : y; } ll dp[101][100001]; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, w; cin >> n >> w; ll a[n], b[n]; ll d = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; cin >> b[i]; d += b[i]; } for (int i = 0; i <= n; ++i) { for (int j = 0; j <= d; ++j) { dp[i][j] = 1e18; } } /*for (int i = 0; i <=n; ++i) { for (int j = 0; j <=w; ++j) { trace(dp[i][j]); } }*/ ll ans = -1; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= d; ++j) { if (i == 0 and j == 0) dp[i][j] = 0; else if (i == 0) dp[i][j] = 1e18; else if (j == 0) dp[i][j] = 0; else if (b[i - 1] <= j) dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - b[i - 1]] + a[i - 1]); else dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } for (int j = 0; j <= d; ++j) { if (dp[n][j] <= w and ans < j) ans = j; } cout << ans; }
replace
25
26
25
26
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int N = 1e5 + 10, OO = 0x3f3f3f3f; // const int mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); double startTime; double getCurrentTime() { return ((double)clock() - startTime) / CLOCKS_PER_SEC; } #define clr(arr, val) memset(arr, val, sizeof(arr)) #define loop(i, n) for (int i = 0; i < int(n); i++) #define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--) #define xloop(i, a, b) for (int i = int(a); i <= int(b); i++) #define range(vec) \ for (auto &x : vec) \ cin >> x; #define ALL(v) ((v).begin()), ((v).end()) #define SZ(v) ((int)((v).size())) // int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction // int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction // int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight // Direction int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal // Direction int n, weight; int w[105], v[105]; ll dp[105][1005]; ll solve(int idx, int remV) { if (idx >= n) { if (remV == 0) return 0; return 1LL * OO * OO; } ll &ret = dp[idx][remV]; if (~ret) return ret; ret = 1LL * OO * OO; ret = min(ret, solve(idx + 1, remV)); if (remV >= v[idx]) ret = min(ret, solve(idx + 1, remV - v[idx]) + w[idx]); return ret; } int main() { startTime = (double)clock(); #ifndef ONLINE_JUDGE // freopen("in.in", "r", stdin); // freopen("out.in", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> weight; int sum = 0; for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; sum += v[i]; } clr(dp, -1); for (int value = sum; value >= 0; --value) { ll leastW = solve(0, value); if (leastW <= weight) { cout << value << "\n"; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int N = 1e5 + 10, OO = 0x3f3f3f3f; // const int mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); double startTime; double getCurrentTime() { return ((double)clock() - startTime) / CLOCKS_PER_SEC; } #define clr(arr, val) memset(arr, val, sizeof(arr)) #define loop(i, n) for (int i = 0; i < int(n); i++) #define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--) #define xloop(i, a, b) for (int i = int(a); i <= int(b); i++) #define range(vec) \ for (auto &x : vec) \ cin >> x; #define ALL(v) ((v).begin()), ((v).end()) #define SZ(v) ((int)((v).size())) // int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction // int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction // int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight // Direction int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal // Direction int n, weight; int w[105], v[105]; ll dp[105][100005]; ll solve(int idx, int remV) { if (idx >= n) { if (remV == 0) return 0; return 1LL * OO * OO; } ll &ret = dp[idx][remV]; if (~ret) return ret; ret = 1LL * OO * OO; ret = min(ret, solve(idx + 1, remV)); if (remV >= v[idx]) ret = min(ret, solve(idx + 1, remV - v[idx]) + w[idx]); return ret; } int main() { startTime = (double)clock(); #ifndef ONLINE_JUDGE // freopen("in.in", "r", stdin); // freopen("out.in", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> weight; int sum = 0; for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; sum += v[i]; } clr(dp, -1); for (int value = sum; value >= 0; --value) { ll leastW = solve(0, value); if (leastW <= weight) { cout << value << "\n"; return 0; } } return 0; }
replace
29
30
29
30
0
p03164
C++
Runtime Error
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair typedef long long ll; // typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; // typedef unsigned int uint; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int dp[100010]; int N, W; int w[110], v[110]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> W; rep(i, 0, N) cin >> w[i] >> v[i]; rep(i, 0, 100010) dp[i] = INF; dp[0] = 0; rep(i, 0, N) { rrep(j, 0, 100001) { if (dp[j] >= 0) { chmin(dp[j + v[i]], dp[j] + w[i]); } } } int ans = -1; rep(i, 0, 100010) { if (dp[i] <= W) { chmax(ans, i); } } cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(c) begin(c), end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair typedef long long ll; // typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector<vector<int>> mat; // typedef unsigned int uint; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int dp[100010]; int N, W; int w[110], v[110]; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> W; rep(i, 0, N) cin >> w[i] >> v[i]; rep(i, 0, 100010) dp[i] = INF; dp[0] = 0; rep(i, 0, N) { rrep(j, 0, 100001) { if (dp[j] != INF) { chmin(dp[j + v[i]], dp[j] + w[i]); } } } int ans = -1; rep(i, 0, 100010) { if (dp[i] <= W) { chmax(ans, i); } } cout << ans << endl; return 0; }
replace
78
79
78
79
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() #define pi acos(-1) #define eps 1e-6 #define inf 1e14 typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vi> vvi; const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1}; const int maxn = 100; const int mod = 1e9 + 7; const int maxa = 1e4 + 1; int mul(int a, int b) { return a * 1LL * b % mod; } int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } int sub(int a, int b) { return a >= b ? a - b : a - b + mod; } int pow(int a, int k) { int res = 1; while (k) { if (k % 2) res = mul(res, a); a = mul(a, a); k /= 2; } return res; } int inv(int a) { return pow(a, mod - 2); } int W, n; ll dp[maxa], cost[maxn], val[maxn], sum; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> W; fill(dp, dp + maxa, 1e9); for (int i = 0; i < n; ++i) cin >> cost[i] >> val[i], sum += val[i]; dp[0] = 0; for (int i = 0; i < n; ++i) for (int v = sum - val[i]; v >= 0; --v) dp[v + val[i]] = min(dp[v + val[i]], dp[v] + cost[i]); for (int v = sum; v >= 0; --v) if (dp[v] <= W) return cout << v, 0; }
#include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() #define pi acos(-1) #define eps 1e-6 #define inf 1e14 typedef long long ll; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<vi> vvi; const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1}; const int maxn = 100; const int mod = 1e9 + 7; const int maxa = 1e5 + 1; int mul(int a, int b) { return a * 1LL * b % mod; } int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; } int sub(int a, int b) { return a >= b ? a - b : a - b + mod; } int pow(int a, int k) { int res = 1; while (k) { if (k % 2) res = mul(res, a); a = mul(a, a); k /= 2; } return res; } int inv(int a) { return pow(a, mod - 2); } int W, n; ll dp[maxa], cost[maxn], val[maxn], sum; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> W; fill(dp, dp + maxa, 1e9); for (int i = 0; i < n; ++i) cin >> cost[i] >> val[i], sum += val[i]; dp[0] = 0; for (int i = 0; i < n; ++i) for (int v = sum - val[i]; v >= 0; --v) dp[v + val[i]] = min(dp[v + val[i]], dp[v] + cost[i]); for (int v = sum; v >= 0; --v) if (dp[v] <= W) return cout << v, 0; }
replace
20
21
20
21
0
p03164
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define int long long #define endl '\n' int mod = 1e9 + 7; int mod2 = 998244353; const int INF = 1e9; 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(n + 1, vector<int>(1e5 + 1, 1e13)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 1e5 + 1; j++) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } int ans = 0; for (int i = 0; i < 1e5 + 1; i++) { if (dp[n][i] <= W) ans = max(ans, i); } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; #define int long long #define endl '\n' int mod = 1e9 + 7; int mod2 = 998244353; const int INF = 1e9; 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(n + 1, vector<int>(1e5 + 1001, 1e13)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 1e5 + 1; j++) { dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } int ans = 0; for (int i = 0; i < 1e5 + 1; i++) { if (dp[n][i] <= W) ans = max(ans, i); } cout << ans << endl; }
replace
15
16
15
16
0
p03164
C++
Runtime Error
#include <iostream> using namespace std; const int MAX_N = 100; const int MAX_V = 100100; long long dp[MAX_N][MAX_V] = { 0}; // N-1番目までで入れた容量の価値を最大にするもの long long weight[MAX_N], value[MAX_V]; const long long INF = 1LL << 60; int main() { long long N, W; cin >> N >> W; for (int i = 0; i < N; ++i) { cin >> weight[i] >> value[i]; } for (int i = 0; i < MAX_N; ++i) { for (int j = 0; j < MAX_V; ++j) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i番目の商品を選ぶ if (sum_v - value[i] >= 0) { if (dp[i + 1][sum_v] > dp[i][sum_v - value[i]] + weight[i]) { dp[i + 1][sum_v] = dp[i][sum_v - value[i]] + weight[i]; } } if (dp[i + 1][sum_v] > dp[i][sum_v]) { dp[i + 1][sum_v] = dp[i][sum_v]; } } } 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; return 0; }
#include <iostream> using namespace std; const int MAX_N = 110; const int MAX_V = 100100; long long dp[MAX_N][MAX_V] = { 0}; // N-1番目までで入れた容量の価値を最大にするもの long long weight[MAX_N], value[MAX_V]; const long long INF = 1LL << 60; int main() { long long N, W; cin >> N >> W; for (int i = 0; i < N; ++i) { cin >> weight[i] >> value[i]; } for (int i = 0; i < MAX_N; ++i) { for (int j = 0; j < MAX_V; ++j) { dp[i][j] = INF; } } dp[0][0] = 0; for (int i = 0; i < N; ++i) { for (int sum_v = 0; sum_v < MAX_V; ++sum_v) { // i番目の商品を選ぶ if (sum_v - value[i] >= 0) { if (dp[i + 1][sum_v] > dp[i][sum_v - value[i]] + weight[i]) { dp[i + 1][sum_v] = dp[i][sum_v - value[i]] + weight[i]; } } if (dp[i + 1][sum_v] > dp[i][sum_v]) { dp[i + 1][sum_v] = dp[i][sum_v]; } } } 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; return 0; }
replace
3
4
3
4
0
p03164
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> #define MAX_N 100 #define MAX_V 1000 #define INF pow(10, 12) using namespace std; int main() { int N, W; cin >> N >> W; vector<long> w(N); vector<long> v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; vector<vector<long>> dp(MAX_N + 1, vector<long>(MAX_N * MAX_V + 1)); dp[0] = vector<long>(MAX_N * MAX_V + 1, INF); dp[0][0] = 0; for (int i = 0; i <= N; i++) { for (int j = 0; j <= MAX_N * MAX_V; 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 res = 0; for (int i = 0; i < MAX_N * MAX_V; i++) if (dp[N][i] <= W) res = i; cout << res << endl; return 0; }
#include <cmath> #include <iostream> #include <vector> #define MAX_N 200 #define MAX_V 1000 #define INF pow(10, 12) using namespace std; int main() { int N, W; cin >> N >> W; vector<long> w(N); vector<long> v(N); for (int i = 0; i < N; i++) cin >> w[i] >> v[i]; vector<vector<long>> dp(MAX_N + 1, vector<long>(MAX_N * MAX_V + 1)); dp[0] = vector<long>(MAX_N * MAX_V + 1, INF); dp[0][0] = 0; for (int i = 0; i <= N; i++) { for (int j = 0; j <= MAX_N * MAX_V; 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 res = 0; for (int i = 0; i < MAX_N * MAX_V; i++) if (dp[N][i] <= W) res = i; cout << res << endl; return 0; }
replace
4
5
4
5
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; void solve() { int n, w_max; cin >> n >> w_max; vector<ll> v(n), w(n); for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; } // dp[i][k] -> menor peso possível utilizando até o item i atigindo valor // maior ou igual a k vector<vector<ll>> dp(n, vector<ll>(100013, -1ll)); function<ll(int, int)> calc_dp = [&](int i, int k) { if (i < 0) { if (k <= 0) return 0ll; else return 1000000123ll; } if (dp[i][k] != -1) return dp[i][k]; dp[i][k] = min(w[i] + calc_dp(i - 1, k - v[i]), calc_dp(i - 1, k)); return dp[i][k]; }; ll ans = 0ll; for (int i = 0; i < 100013; ++i) { int w = calc_dp(n - 1, i); if (w <= w_max) ans = i; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; for (int i = 0; i < t; ++i) { solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; void solve() { int n, w_max; cin >> n >> w_max; vector<ll> v(n), w(n); for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; } // dp[i][k] -> menor peso possível utilizando até o item i atigindo valor // maior ou igual a k vector<vector<ll>> dp(n, vector<ll>(100013, -1ll)); function<ll(int, int)> calc_dp = [&](int i, int k) { if (i < 0 || k < 0) { if (k <= 0) return 0ll; else return 1000000123ll; } if (dp[i][k] != -1) return dp[i][k]; dp[i][k] = min(w[i] + calc_dp(i - 1, k - v[i]), calc_dp(i - 1, k)); return dp[i][k]; }; ll ans = 0ll; for (int i = 0; i < 100013; ++i) { int w = calc_dp(n - 1, i); if (w <= w_max) ans = i; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; for (int i = 0; i < t; ++i) { solve(); } return 0; }
replace
20
21
20
21
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03164
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define MuhammedAly \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(x) (x).begin(), (x).end() #define allr(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back #define popc(x) __builtin_popcount(x) #define LLMX 1e18 #define NotinRange(n, m) i < 0 || i >= (n) || j < 0 || j >= (m) #define mem(x, y) memset((x), (y), sizeof(x)) #define sz(a) (int)(a).size() #define inFile(s) freopen((s), "r", stdin) #define outFile(s) freopen((s), "w", stdout) #define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a)) #define pi (2 * acos(0)) #define X real() #define Y imag() #define cross(a, b) ((conj(a) * (b)).Y) #define dot(a, b) ((conj(a) * (b)).X) #define vec(a, b) ((b) - (a)) #define ll long long typedef long double ld; typedef complex<double> point; typedef tuple<int, int, int> line; typedef pair<point, point> segment; typedef vector<point> polygon; const int N = 1e3 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353; const double EPS = 1e-9; ll n, w, memo[105][N], W[105], v[105], sum; ll solve(int i, int V) { if (V == 0) return 0; if (i == n) return LLMX; ll &ret = memo[i][V]; if (~ret) return ret; ret = solve(i + 1, V); if (V - v[i] >= 0) ret = min(ret, solve(i + 1, V - v[i]) + W[i]); return ret; } int main() { MuhammedAly mem(memo, -1); cin >> n >> w; for (int i = 0; i < n; i++) cin >> W[i] >> v[i], sum += v[i]; for (int i = sum; ~i; i--) if (solve(0, i) <= w) return cout << i, 0; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define MuhammedAly \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(x) (x).begin(), (x).end() #define allr(x) (x).rbegin(), (x).rend() #define pb push_back #define eb emplace_back #define popc(x) __builtin_popcount(x) #define LLMX 1e18 #define NotinRange(n, m) i < 0 || i >= (n) || j < 0 || j >= (m) #define mem(x, y) memset((x), (y), sizeof(x)) #define sz(a) (int)(a).size() #define inFile(s) freopen((s), "r", stdin) #define outFile(s) freopen((s), "w", stdout) #define biEdge(v, a, b) (v)[(a)].pb((b)), (v)[(b)].pb((a)) #define pi (2 * acos(0)) #define X real() #define Y imag() #define cross(a, b) ((conj(a) * (b)).Y) #define dot(a, b) ((conj(a) * (b)).X) #define vec(a, b) ((b) - (a)) #define ll long long typedef long double ld; typedef complex<double> point; typedef tuple<int, int, int> line; typedef pair<point, point> segment; typedef vector<point> polygon; const int N = 1e5 + 5, M = 20 + 5, OO = 0x3f3f3f3f, mod = 1e9 + 7, base = 131, mod2 = 1000136437, mod3 = 998244353; const double EPS = 1e-9; ll n, w, memo[105][N], W[105], v[105], sum; ll solve(int i, int V) { if (V == 0) return 0; if (i == n) return LLMX; ll &ret = memo[i][V]; if (~ret) return ret; ret = solve(i + 1, V); if (V - v[i] >= 0) ret = min(ret, solve(i + 1, V - v[i]) + W[i]); return ret; } int main() { MuhammedAly mem(memo, -1); cin >> n >> w; for (int i = 0; i < n; i++) cin >> W[i] >> v[i], sum += v[i]; for (int i = sum; ~i; i--) if (solve(0, i) <= w) return cout << i, 0; return 0; }
replace
31
32
31
32
0
p03164
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<LL, LL> PII; LL MOD = 1000000007; int main() { int N, W; cin >> N >> W; // vector<int> v(N, 0), w(N, 0); int M = 100100; vector<vector<LL>> dp(N + 1, vector<LL>(M, W + 1)); dp[0][0] = 0; for (int i = 1; i <= N; i++) { LL w, v; cin >> w >> v; for (int j = 0; j < M; j++) dp[i][j] = dp[i - 1][j]; for (int j = 0; j < M; j++) { dp[i][j + v] = min(dp[i - 1][j] + w, dp[i][j + v]); } } LL ans = 0; for (int j = 0; j < M; j++) if (dp[N][j] <= W) { ans = j; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<LL, LL> PII; LL MOD = 1000000007; int main() { int N, W; cin >> N >> W; // vector<int> v(N, 0), w(N, 0); int M = 100100; vector<vector<LL>> dp(N + 1, vector<LL>(M, W + 1)); dp[0][0] = 0; for (int i = 1; i <= N; i++) { LL w, v; cin >> w >> v; for (int j = 0; j < M; j++) dp[i][j] = dp[i - 1][j]; for (int j = 0; j < M - v; j++) { dp[i][j + v] = min(dp[i - 1][j] + w, dp[i][j + v]); } } LL ans = 0; for (int j = 0; j < M; j++) if (dp[N][j] <= W) { ans = j; } 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 ll INF = 1e15; ll n, W, dp[100001], c[101], w[101], ans; int main() { cin >> n >> W; for (int i = 0; i <= 100000; ++i) dp[i] = INF; for (int i = 0; i < n; ++i) cin >> w[i] >> c[i]; dp[0] = 0; for (int pos = 0; pos < n; ++pos) { if (w[pos] > W) continue; for (int cst = 100000; cst >= 0; --cst) dp[cst + c[pos]] = min(dp[cst + c[pos]], dp[cst] + w[pos]); } for (int i = 100000; i >= 0; --i) if (dp[i] <= W) { cout << i << endl; return 0; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1e15; ll n, W, dp[100001], c[101], w[101], ans; int main() { cin >> n >> W; for (int i = 0; i <= 100000; ++i) dp[i] = INF; for (int i = 0; i < n; ++i) cin >> w[i] >> c[i]; dp[0] = 0; for (int pos = 0; pos < n; ++pos) { if (w[pos] > W) continue; for (int cst = 100000; cst >= 0; --cst) if (cst + c[pos] <= 100000) dp[cst + c[pos]] = min(dp[cst + c[pos]], dp[cst] + w[pos]); } for (int i = 100000; i >= 0; --i) if (dp[i] <= W) { cout << i << endl; return 0; } }
replace
21
22
21
23
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, wlim; cin >> n >> wlim; vector<int64_t> ws(n), vs(n); for (int i = 0; i < n; i++) { cin >> ws[i] >> vs[i]; } vector<vector<int64_t>> dp(n, vector<int64_t>(100001, 1LL << 60)); dp[0][0] = 0; dp[0][vs[0]] = ws[0]; for (int i = 1; i < n; i++) { for (int j = 0; j <= 100000; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); dp[i][j + vs[i]] = min(dp[i][j + vs[i]], dp[i - 1][j] + ws[i]); } } int64_t ans = -1; for (int64_t j = 100000; 0 <= j; j--) { if (dp[n - 1][j] <= wlim) { ans = max(ans, j); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, wlim; cin >> n >> wlim; vector<int64_t> ws(n), vs(n); for (int i = 0; i < n; i++) { cin >> ws[i] >> vs[i]; } vector<vector<int64_t>> dp(n, vector<int64_t>(100001, 1LL << 60)); dp[0][0] = 0; dp[0][vs[0]] = ws[0]; for (int i = 1; i < n; i++) { for (int j = 0; j <= 100000; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j + vs[i] <= 100000) { dp[i][j + vs[i]] = min(dp[i][j + vs[i]], dp[i - 1][j] + ws[i]); } } } int64_t ans = -1; for (int64_t j = 100000; 0 <= j; j--) { if (dp[n - 1][j] <= wlim) { ans = max(ans, j); } } cout << ans << endl; return 0; }
replace
16
17
16
19
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 rrep(i, n) for (int i = 1; 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 rrng(a) a.rbegin(), a.rend() #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 eb emplace_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 print(x) cout << 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 tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll dp[200][200000]; const ll INF = 1LL << 60; int main() { int n; ll w; cin >> n >> w; vl W(n), V(n); Fill(dp, INF); rep(i, n) cin >> W[i] >> V[i]; dp[0][0] = 0LL; rep(i, n) { rep(j, 100100) { mins(dp[i + 1][j], dp[i][j]); if (dp[i][j - V[i]] + W[i] > w) continue; mins(dp[i + 1][j], dp[i][j - V[i]] + W[i]); } } ll ans = 0; rep(j, 100100) { if (dp[n][j] <= w) maxs(ans, (ll)j); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; 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 rrng(a) a.rbegin(), a.rend() #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 eb emplace_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 print(x) cout << 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 tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll dp[200][200000]; const ll INF = 1LL << 60; int main() { int n; ll w; cin >> n >> w; vl W(n), V(n); Fill(dp, INF); rep(i, n) cin >> W[i] >> V[i]; dp[0][0] = 0LL; rep(i, n) { rep(j, 100100) { mins(dp[i + 1][j], dp[i][j]); if (j - V[i] < 0) continue; if (dp[i][j - V[i]] + W[i] > w) continue; mins(dp[i + 1][j], dp[i][j - V[i]] + W[i]); } } ll ans = 0; rep(j, 100100) { if (dp[n][j] <= w) maxs(ans, (ll)j); } cout << ans << endl; return 0; }
insert
56
56
56
58
-11
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define POP pop_back() #define ll long long #define db double #define POP pop_back() #define endl '\n' const int maxn = 1e3 + 5; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const ll inF = 0x3f3f3f3f3f3f3f3f; struct node { int w, v; }; node a[maxn]; ll dp[maxn]; int main() { int n, c; cin >> n >> c; int w, v, tmp = 0; for (int i = 1; i <= n; i++) cin >> a[i].w >> a[i].v, tmp += a[i].v; for (int i = 1; i <= tmp; i++) dp[i] = inF; for (int i = 1; i <= n; i++) { for (int j = tmp; j >= a[i].v; j--) { dp[j] = min(dp[j], dp[j - a[i].v] + a[i].w); } } int ans = 0; for (int i = tmp; i >= 1; i--) { if (dp[i] <= c) { ans = i; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define POP pop_back() #define ll long long #define db double #define POP pop_back() #define endl '\n' const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const ll inF = 0x3f3f3f3f3f3f3f3f; struct node { int w, v; }; node a[maxn]; ll dp[maxn]; int main() { int n, c; cin >> n >> c; int w, v, tmp = 0; for (int i = 1; i <= n; i++) cin >> a[i].w >> a[i].v, tmp += a[i].v; for (int i = 1; i <= tmp; i++) dp[i] = inF; for (int i = 1; i <= n; i++) { for (int j = tmp; j >= a[i].v; j--) { dp[j] = min(dp[j], dp[j - a[i].v] + a[i].w); } } int ans = 0; for (int i = tmp; i >= 1; i--) { if (dp[i] <= c) { ans = i; break; } } cout << ans << endl; return 0; }
replace
8
9
8
9
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<LL>; using VVI = vector<VI>; using VB = vector<bool>; using VS = vector<string>; using PII = pair<LL, LL>; using VP = vector<PII>; #define PB push_back #define MP make_pair #define SZ(a) LL((a).size()) #define EACH(x, c) for (auto x : (c)) #define ALL(c) (c).begin(), (c).end() #define REVERSE(c) reverse(ALL(c)) #define SORT(c) stable_sort(ALL(c)) #define RSORT(c) stable_sort((c).rbegin(), (c).rend()) #define FSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first < y.first; }); #define FRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first > y.first; }); #define SSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second < y.second; }); #define SRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second > y.second; }); #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define $(x) \ { cout << #x << " = " << (x) << endl; } int main() { LL N, W; cin >> N >> W; VI w(N + 1), v(N + 1); LL V = 0; FOR(i, 1, N + 1) { cin >> w[i] >> v[i]; V += v[i]; } VVI dp(N + 1, VI(V + 1, W + 1)); dp[0][0] = 0; REP(i, N) { REP(j, V + 1) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); dp[i + 1][j + v[i + 1]] = min(dp[i + 1][j + v[i + 1]], dp[i][j] + w[i + 1]); } } /* REP(i, N + 1) { REP(j, V + 1) { if (dp[i][j] == LLONG_MAX) { cout << "- "; } else { cout << dp[i][j] << " "; } } cout << endl; } */ for (LL j = V; j >= 0; --j) { LL min_w = LLONG_MAX; REP(i, N + 1) min_w = min(min_w, dp[i][j]); if (min_w <= W) { cout << j << endl; break; } } return 0; }
#include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<LL>; using VVI = vector<VI>; using VB = vector<bool>; using VS = vector<string>; using PII = pair<LL, LL>; using VP = vector<PII>; #define PB push_back #define MP make_pair #define SZ(a) LL((a).size()) #define EACH(x, c) for (auto x : (c)) #define ALL(c) (c).begin(), (c).end() #define REVERSE(c) reverse(ALL(c)) #define SORT(c) stable_sort(ALL(c)) #define RSORT(c) stable_sort((c).rbegin(), (c).rend()) #define FSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first < y.first; }); #define FRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.first > y.first; }); #define SSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second < y.second; }); #define SRSORT(c) \ stable_sort(ALL(c), [](auto &x, auto &y) { return x.second > y.second; }); #define FOR(i, a, b) for (LL i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define $(x) \ { cout << #x << " = " << (x) << endl; } int main() { LL N, W; cin >> N >> W; VI w(N + 1), v(N + 1); LL V = 0; FOR(i, 1, N + 1) { cin >> w[i] >> v[i]; V += v[i]; } VVI dp(N + 1, VI(V + 1, W + 1)); dp[0][0] = 0; REP(i, N) { REP(j, V + 1) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); if (j + v[i + 1] <= V) { dp[i + 1][j + v[i + 1]] = min(dp[i + 1][j + v[i + 1]], dp[i][j] + w[i + 1]); } } } /* REP(i, N + 1) { REP(j, V + 1) { if (dp[i][j] == LLONG_MAX) { cout << "- "; } else { cout << dp[i][j] << " "; } } cout << endl; } */ for (LL j = V; j >= 0; --j) { LL min_w = LLONG_MAX; REP(i, N + 1) min_w = min(min_w, dp[i][j]); if (min_w <= W) { cout << j << endl; break; } } return 0; }
replace
45
47
45
49
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long int N, W; cin >> N >> W; long long int v[N], w[N]; for (long long int i = 0; i < N; i++) cin >> w[i] >> v[i]; long long int dp[N + 1][100001]; dp[0][0] = 0; for (long long int i = 1; i <= 100000; i++) dp[0][i] = W + 1; for (long long int i = 1; i <= N; i++) { for (long long int j = 0; j <= 100000; j++) { if (j < v[i - 1]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = min(w[i - 1] + dp[i - 1][j - v[i - 1]], dp[i - 1][j]); } } long long int x = 1000000; while (W < dp[N][x]) x--; cout << x << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N, W; cin >> N >> W; long long int v[N], w[N]; for (long long int i = 0; i < N; i++) cin >> w[i] >> v[i]; long long int dp[N + 1][100001]; dp[0][0] = 0; for (long long int i = 1; i <= 100000; i++) dp[0][i] = W + 1; for (long long int i = 1; i <= N; i++) { for (long long int j = 0; j <= 100000; j++) { if (j < v[i - 1]) dp[i][j] = dp[i - 1][j]; else dp[i][j] = min(w[i - 1] + dp[i - 1][j - v[i - 1]], dp[i - 1][j]); } } long long int x = 100000; while (W < dp[N][x]) x--; cout << x << endl; }
replace
20
21
20
21
-11
p03164
C++
Runtime Error
// In the name of God #include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define debug(x) cout << #x ": " << x << endl; int dp[105][(int)1e3 + 5]; int w[105]; int v[105]; int main() { IOS int n, W; cin >> n >> W; int mxv = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; mxv += v[i]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= mxv; j++) { dp[i][j] = W + 1; } } for (int i = 0; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= mxv; j++) { if (j >= v[i - 1]) dp[i][j] = min(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][j], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i <= mxv; i++) { if (dp[n][i] <= W) ans = max(ans, i); } cout << ans; return 0; }
// In the name of God #include <bits/stdc++.h> using namespace std; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define debug(x) cout << #x ": " << x << endl; int dp[105][(int)1e5 + 5]; int w[105]; int v[105]; int main() { IOS int n, W; cin >> n >> W; int mxv = 0; for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; mxv += v[i]; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= mxv; j++) { dp[i][j] = W + 1; } } for (int i = 0; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= mxv; j++) { if (j >= v[i - 1]) dp[i][j] = min(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][j], dp[i - 1][j]); } } int ans = 0; for (int i = 0; i <= mxv; i++) { if (dp[n][i] <= W) ans = max(ans, i); } cout << ans; return 0; }
replace
11
12
11
12
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define ii pair<int, int> #define OK (cerr << "OK" << endl) #define debug(x) cerr << #x " = " << (x) << endl #define ff first #define ss second #define int long long #define tt tuple<int, int, int> #define all(x) x.begin(), x.end() #define Matrix vector<vector<int>> #define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v)) #define endl '\n' constexpr int INF = 1e18; constexpr int MOD = 1e9 + 7; constexpr int MAXN = 1e5 + 3; int dp[101][MAXN]; int W; int w[101]; int v[101]; void solve() { int n; cin >> n; cin >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 1; i < MAXN; ++i) { dp[0][i] = INF; } for (int i = 1; i <= n; ++i) { dp[i][0] = 0; for (int j = 1; j < MAXN; ++j) { dp[i][j] = min(w[i] + dp[i - 1][j - v[i]], dp[i - 1][j]); } } int ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j < MAXN; ++j) { if (dp[i][j] <= W) ans = max(ans, j); } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; #ifdef MULTIPLE_TEST_CASES cin >> t; #endif while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define ii pair<int, int> #define OK (cerr << "OK" << endl) #define debug(x) cerr << #x " = " << (x) << endl #define ff first #define ss second #define int long long #define tt tuple<int, int, int> #define all(x) x.begin(), x.end() #define Matrix vector<vector<int>> #define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v)) #define endl '\n' constexpr int INF = 1e18; constexpr int MOD = 1e9 + 7; constexpr int MAXN = 1e5 + 3; int dp[101][MAXN]; int W; int w[101]; int v[101]; void solve() { int n; cin >> n; cin >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; dp[0][0] = 0; for (int i = 1; i < MAXN; ++i) { dp[0][i] = INF; } for (int i = 1; i <= n; ++i) { dp[i][0] = 0; for (int j = 1; j < MAXN; ++j) { if (j >= v[i]) dp[i][j] = min(w[i] + dp[i - 1][j - v[i]], dp[i - 1][j]); else dp[i][j] = dp[i - 1][j]; } } int ans = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j < MAXN; ++j) { if (dp[i][j] <= W) ans = max(ans, j); } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; #ifdef MULTIPLE_TEST_CASES cin >> t; #endif while (t--) solve(); }
replace
41
42
41
45
0
p03164
C++
Runtime Error
// #include <boost/multiprecision/cpp_int.hpp> // using boost::multiprecision::cpp_int; #include <bits/stdc++.h> using namespace std; // ¯\_(ツ)_/¯ #define f first #define s second #define p push #define mp make_pair #define pb push_back #define eb emplace_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define foi(i, a, n) for (i = (a); i < (n); ++i) #define foii(i, a, n) for (i = (a); i <= (n); ++i) #define fod(i, a, n) for (i = (a); i > (n); --i) #define fodd(i, a, n) for (i = (a); i >= (n); --i) #define debug(x) cout << '>' << #x << ':' << x << endl; #define all(v) v.begin(), v.end() #define sz(x) ((int)(x).size()) #define endl " \n" #define newl cout << "\n" #define MAXN 100005 #define MOD 1000000007LL #define EPS 1e-13 #define INFI 1000000000 // 10^9 #define INFLL 1000000000000000000ll // 10^18 // ¯\_(ツ)_/¯ // #define l long int // #define d double #define ll long long int #define ull unsigned long long int #define ld long double #define vi vector<int> #define vll vector<long long> #define vvi vector<vector<int>> #define vvll vector<vll> #define vvld vector<vector<ld>> // vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of // 10 rows and 20 columns, with value 500. #define mii map<int, int> #define mll map<long long, long long> #define pii pair<int, int> #define pll pair<long long, long long> #define fast_io() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll tc, n, m, k; // ll ans = 0, c = 0; // ll i, j; // ll a, b; // ll x, y; int main() { fast_io(); #ifndef ONLINE_JUDGE freopen("../input.txt", "r", stdin); freopen("../output.txt", "w", stdout); #endif // ll w; cin >> n >> w; vll weight(n, 0), price(n, 0); ll pricesum = 0; rep(i, 0, n) { cin >> weight[i]; cin >> price[i]; pricesum += price[i]; } // dp state = {first i elements, max_price} = min weight needed to make // max_price from 0 - i elements vvll dp(n + 1, vll(pricesum + 1, INFI)); dp[0][0] = 0; rep(i, 1, n + 1) { rep(j, 0, pricesum + 1) { if (j - price[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j], weight[i - 1] + dp[i - 1][j - price[i - 1]]); } else { dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } } // max price for which min weight is less or equal to capacity. ll ans = 0; rep(i, 0, pricesum + 1) { if (dp[n][i] <= w) ans = i; } cout << ans; return 0; } /* 2 4 0 1 0 1 5 0 0 1 0 0 */
// #include <boost/multiprecision/cpp_int.hpp> // using boost::multiprecision::cpp_int; #include <bits/stdc++.h> using namespace std; // ¯\_(ツ)_/¯ #define f first #define s second #define p push #define mp make_pair #define pb push_back #define eb emplace_back #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define foi(i, a, n) for (i = (a); i < (n); ++i) #define foii(i, a, n) for (i = (a); i <= (n); ++i) #define fod(i, a, n) for (i = (a); i > (n); --i) #define fodd(i, a, n) for (i = (a); i >= (n); --i) #define debug(x) cout << '>' << #x << ':' << x << endl; #define all(v) v.begin(), v.end() #define sz(x) ((int)(x).size()) #define endl " \n" #define newl cout << "\n" #define MAXN 100005 #define MOD 1000000007LL #define EPS 1e-13 #define INFI 1000000000 // 10^9 #define INFLL 1000000000000000000ll // 10^18 // ¯\_(ツ)_/¯ // #define l long int // #define d double #define ll long long int #define ull unsigned long long int #define ld long double #define vi vector<int> #define vll vector<long long> #define vvi vector<vector<int>> #define vvll vector<vll> #define vvld vector<vector<ld>> // vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of // 10 rows and 20 columns, with value 500. #define mii map<int, int> #define mll map<long long, long long> #define pii pair<int, int> #define pll pair<long long, long long> #define fast_io() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); ll tc, n, m, k; // ll ans = 0, c = 0; // ll i, j; // ll a, b; // ll x, y; int main() { fast_io(); #ifndef ONLINE_JUDGE // freopen("../input.txt", "r", stdin); // freopen("../output.txt", "w", stdout); #endif // ll w; cin >> n >> w; vll weight(n, 0), price(n, 0); ll pricesum = 0; rep(i, 0, n) { cin >> weight[i]; cin >> price[i]; pricesum += price[i]; } // dp state = {first i elements, max_price} = min weight needed to make // max_price from 0 - i elements vvll dp(n + 1, vll(pricesum + 1, INFI)); dp[0][0] = 0; rep(i, 1, n + 1) { rep(j, 0, pricesum + 1) { if (j - price[i - 1] >= 0) { dp[i][j] = min(dp[i - 1][j], weight[i - 1] + dp[i - 1][j - price[i - 1]]); } else { dp[i][j] = min(dp[i][j], dp[i - 1][j]); } } } // max price for which min weight is less or equal to capacity. ll ans = 0; rep(i, 0, pricesum + 1) { if (dp[n][i] <= w) ans = i; } cout << ans; return 0; } /* 2 4 0 1 0 1 5 0 0 1 0 0 */
replace
61
63
61
63
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 2, W = 1e9 + 5, V = 1e3 + 3; long long dp[2][V]; const long long INF = 1e13 + 13; int main() { int n, ww, vv = 0; cin >> n >> ww; vector<int> v(n), w(n); for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; vv += v[i]; } for (int i = n - 1; i >= 0; --i) { for (int j = 0; j <= vv; ++j) { if (i == n - 1 && j) { dp[i & 1][j] = INF; if (j - v[i] == 0) dp[i & 1][j] = min(dp[i & 1][j], dp[(i + 1) & 1][j - v[i]] + w[i]); } else { dp[i & 1][j] = dp[(i + 1) & 1][j]; if (j - v[i] >= 0) dp[i & 1][j] = min(dp[i & 1][j], dp[(i + 1) & 1][j - v[i]] + w[i]); } } } for (int i = vv; i >= 0; --i) if (dp[0][i] <= ww) { cout << i; return 0; } cout << 0; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 2, W = 1e9 + 5, V = 1e5 + 5; long long dp[2][V]; const long long INF = 1e13 + 13; int main() { int n, ww, vv = 0; cin >> n >> ww; vector<int> v(n), w(n); for (int i = 0; i < n; ++i) { cin >> w[i] >> v[i]; vv += v[i]; } for (int i = n - 1; i >= 0; --i) { for (int j = 0; j <= vv; ++j) { if (i == n - 1 && j) { dp[i & 1][j] = INF; if (j - v[i] == 0) dp[i & 1][j] = min(dp[i & 1][j], dp[(i + 1) & 1][j - v[i]] + w[i]); } else { dp[i & 1][j] = dp[(i + 1) & 1][j]; if (j - v[i] >= 0) dp[i & 1][j] = min(dp[i & 1][j], dp[(i + 1) & 1][j - v[i]] + w[i]); } } } for (int i = vv; i >= 0; --i) if (dp[0][i] <= ww) { cout << i; return 0; } cout << 0; return 0; }
replace
2
3
2
3
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define pii pair<int, int> #define fi first #define se second #define forn(i, a, b) for (int i = a; i < b; i++) #define deb(x) cout << #x << ' ' << x << endl #define clock \ cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int n, w; pii p[105]; int cache[105][100005]; int dp(int idx, int val) { if (val == 0) return 0; if (val < 0 || idx == n) return 1e15; int &ans = cache[idx][val]; if (ans != -1) return ans; ans = min(dp(idx + 1, val), p[idx].fi + dp(idx + 1, val - p[idx].se)); return ans; } int32_t main() { IOS INPUT(); cin >> n >> w; forn(i, 0, n) cin >> p[i].fi >> p[i].se; memset(cache, -1, sizeof(cache)); int ans = 0; forn(i, 1, 1e5 + 1) { int mwt = dp(0, i); if (mwt <= w) ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define int long long #define all(v) v.begin(), v.end() #define sz(v) (int)v.size() #define pii pair<int, int> #define fi first #define se second #define forn(i, a, b) for (int i = a; i < b; i++) #define deb(x) cout << #x << ' ' << x << endl #define clock \ cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int n, w; pii p[105]; int cache[105][100005]; int dp(int idx, int val) { if (val == 0) return 0; if (val < 0 || idx == n) return 1e15; int &ans = cache[idx][val]; if (ans != -1) return ans; ans = min(dp(idx + 1, val), p[idx].fi + dp(idx + 1, val - p[idx].se)); return ans; } int32_t main() { IOS // INPUT(); cin >> n >> w; forn(i, 0, n) cin >> p[i].fi >> p[i].se; memset(cache, -1, sizeof(cache)); int ans = 0; forn(i, 1, 1e5 + 1) { int mwt = dp(0, i); if (mwt <= w) ans = i; } cout << ans << endl; return 0; }
replace
43
45
43
46
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define lli long long int #define REP(i, s, l) for (lli i = s; i < l; i++) #define DEBUG 0 #define INF (1LL << 50) #define MOD 1000000007 signed main() { lli n, w; vector<pair<lli, lli>> p; cin >> n >> w; REP(i, 0, n) { lli a, b; cin >> a >> b; p.push_back(make_pair(a, b)); } /*価値を引数にwを返す*/ lli dp[100100] = {INF}; REP(i, 0, 100100) dp[i] = INF; dp[0] = 0; REP(i, 0, n) { for (lli j = 100000; j >= 0; j--) { if (dp[j] == INF) continue; if (DEBUG) cout << "j=" << j << " dp[j]=" << dp[j] << endl; lli nextV = j + p[i].second; lli nextW = dp[j] + p[i].first; if (nextW > w) continue; if (dp[nextV] > nextW) { dp[nextV] = nextW; if (DEBUG) cout << "nextV=" << nextV << " nextW=" << nextW << endl; } } } lli ans = 0; REP(i, 0, 1000010) { if (dp[i] && dp[i] != INF) ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define REP(i, s, l) for (lli i = s; i < l; i++) #define DEBUG 0 #define INF (1LL << 50) #define MOD 1000000007 signed main() { lli n, w; vector<pair<lli, lli>> p; cin >> n >> w; REP(i, 0, n) { lli a, b; cin >> a >> b; p.push_back(make_pair(a, b)); } /*価値を引数にwを返す*/ lli dp[100100] = {INF}; REP(i, 0, 100100) dp[i] = INF; dp[0] = 0; REP(i, 0, n) { for (lli j = 100000; j >= 0; j--) { if (dp[j] == INF) continue; if (DEBUG) cout << "j=" << j << " dp[j]=" << dp[j] << endl; lli nextV = j + p[i].second; lli nextW = dp[j] + p[i].first; if (nextW > w) continue; if (dp[nextV] > nextW) { dp[nextV] = nextW; if (DEBUG) cout << "nextV=" << nextV << " nextW=" << nextW << endl; } } } lli ans = 0; REP(i, 0, 100010) { if (dp[i] && dp[i] != INF) ans = i; } cout << ans << endl; return 0; }
replace
46
47
46
47
-11
p03164
C++
Time Limit Exceeded
//*****************************believer******************************// #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef map<ll, ll> mi; #define f first #define ss second #define ins insert #define pb push_back #define lb lower_bound #define ub upper_bound #define pq priority_queue #define sqr(n) floor(sqrt(n)) #define sz(v) ((ll)(v.size())) #define trav(a, x) for (auto &a : x) #define all(v) (v).begin(), (v).end() #define arl(v) (v).rbegin(), (v).rend() #define mem(a) memset(a, -1, sizeof(a)) #define ssort(v) sort((v).begin(), (v).end()) #define rsort(v) sort((v).rbegin(), (v).rend()) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); #define vmn(a) (*min_element(a.begin(), a.end())) #define vmx(a) (*max_element(a.begin(), a.end())) #define foo(i, a, b) for (ll i = (a); i < (b); ++i) #define foor(i, a, b) for (ll i = (a); i >= (b); --i) const ll N = 2e5 + 100; ll wt[105], val[105]; ll n, w; ////this is the dp bw values and N which is different from the previous... ll dp[N][105]; ll solve(ll x, ll num) { /// base condition; if (num == 0) return (x == 0) ? 0 : 1e12; if (val[num] > x) return dp[x][num] = solve(x, num - 1); else return dp[x][num] = min(solve(x, num - 1), solve(x - val[num], num - 1) + wt[num]); } ll solve1(ll x) { foor(i, x, 0) if (solve(i, n) <= w) return i; } int main() { cin >> n >> w; ll maxx = 0; foo(i, 1, n + 1) { cin >> wt[i] >> val[i]; maxx += val[i]; } mem(dp); cout << solve1(maxx) << "\n"; return 0; }
//*****************************believer******************************// #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef map<ll, ll> mi; #define f first #define ss second #define ins insert #define pb push_back #define lb lower_bound #define ub upper_bound #define pq priority_queue #define sqr(n) floor(sqrt(n)) #define sz(v) ((ll)(v.size())) #define trav(a, x) for (auto &a : x) #define all(v) (v).begin(), (v).end() #define arl(v) (v).rbegin(), (v).rend() #define mem(a) memset(a, -1, sizeof(a)) #define ssort(v) sort((v).begin(), (v).end()) #define rsort(v) sort((v).rbegin(), (v).rend()) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); #define vmn(a) (*min_element(a.begin(), a.end())) #define vmx(a) (*max_element(a.begin(), a.end())) #define foo(i, a, b) for (ll i = (a); i < (b); ++i) #define foor(i, a, b) for (ll i = (a); i >= (b); --i) const ll N = 2e5 + 100; ll wt[105], val[105]; ll n, w; ////this is the dp bw values and N which is different from the previous... ll dp[N][105]; ll solve(ll x, ll num) { /// base condition; if (num == 0) return (x == 0) ? 0 : 1e12; if (dp[x][num] != -1) return dp[x][num]; if (val[num] > x) return dp[x][num] = solve(x, num - 1); else return dp[x][num] = min(solve(x, num - 1), solve(x - val[num], num - 1) + wt[num]); } ll solve1(ll x) { foor(i, x, 0) if (solve(i, n) <= w) return i; } int main() { cin >> n >> w; ll maxx = 0; foo(i, 1, n + 1) { cin >> wt[i] >> val[i]; maxx += val[i]; } mem(dp); cout << solve1(maxx) << "\n"; return 0; }
insert
45
45
45
48
TLE
p03164
C++
Time Limit Exceeded
/* -----KAUN_MEET--------*/ #include <bits/stdc++.h> using namespace std; #define int long long int int mod = 1000000007; // int maxi=100; int maxi = 1e18 + 5; #define P get<0> #define D get<1> #define T get<2> #define C get<3> #define PB push_back #define MP make_pair #define BS binary_search #define LB lower_bound #define UB upper_bound #define F first #define S second #define gcd __gcd #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); void __print(int x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename Th, typename V> void __print(const pair<Th, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename Th> void __print(const Th &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename Th, typename... V> void _print(Th t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif int n; int w; vector<pair<int, int>> p; int ans[105][100000 + 10]; int answer(int i, int val) { if (val <= 0) { ans[i][val] = 0; return 0; } int j, k, l; if (i >= n) return maxi; int costi = p[i].F; int valui = p[i].S; if (i == 0) { if (valui == val) { ans[i][val] = costi; } else { ans[i][val] = maxi; } return ans[i][val]; } int ans1 = answer(i - 1, val); int ans2; if (val < valui) { ans2 = maxi; } else { ans2 = answer(i - 1, val - valui) + costi; } ans[i][val] = min(ans1, ans2); return ans[i][val]; } void binary_rock() { cin >> n; cin >> w; int i, j, k, l; int sum = 0; for (i = 0; i < n; i++) { cin >> j >> k; p.PB({j, k}); sum += k; } sort(p.begin(), p.end()); for (i = 0; i < n; i++) { for (j = 0; j <= sum; j++) ans[i][j] = -1; } int yy = 0; for (i = 0; i <= sum; i++) { if (answer(n - 1, i) <= w) { yy = i; } } cout << yy << endl; // for(i=0;i<n;i++){ // for(j=0;j<=sum;j++) // { // cout<<ans[i][j]<<" "; // } // cout<<endl; // } } signed main() { fastio clock_t t1 = clock(); int t = 1; // cin >> t; while (t--) { binary_rock(); } clock_t t2 = clock(); // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl; // cout << CLOCKS_PER_SEC << endl; return 0; }
/* -----KAUN_MEET--------*/ #include <bits/stdc++.h> using namespace std; #define int long long int int mod = 1000000007; // int maxi=100; int maxi = 1e18 + 5; #define P get<0> #define D get<1> #define T get<2> #define C get<3> #define PB push_back #define MP make_pair #define BS binary_search #define LB lower_bound #define UB upper_bound #define F first #define S second #define gcd __gcd #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); void __print(int x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename Th, typename V> void __print(const pair<Th, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename Th> void __print(const Th &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename Th, typename... V> void _print(Th t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif int n; int w; vector<pair<int, int>> p; int ans[105][100000 + 10]; int answer(int i, int val) { if (val <= 0) { ans[i][val] = 0; return 0; } int j, k, l; if (i >= n) return maxi; if (ans[i][val] != -1) return ans[i][val]; int costi = p[i].F; int valui = p[i].S; if (i == 0) { if (valui == val) { ans[i][val] = costi; } else { ans[i][val] = maxi; } return ans[i][val]; } int ans1 = answer(i - 1, val); int ans2; if (val < valui) { ans2 = maxi; } else { ans2 = answer(i - 1, val - valui) + costi; } ans[i][val] = min(ans1, ans2); return ans[i][val]; } void binary_rock() { cin >> n; cin >> w; int i, j, k, l; int sum = 0; for (i = 0; i < n; i++) { cin >> j >> k; p.PB({j, k}); sum += k; } sort(p.begin(), p.end()); for (i = 0; i < n; i++) { for (j = 0; j <= sum; j++) ans[i][j] = -1; } int yy = 0; for (i = 0; i <= sum; i++) { if (answer(n - 1, i) <= w) { yy = i; } } cout << yy << endl; // for(i=0;i<n;i++){ // for(j=0;j<=sum;j++) // { // cout<<ans[i][j]<<" "; // } // cout<<endl; // } } signed main() { fastio clock_t t1 = clock(); int t = 1; // cin >> t; while (t--) { binary_rock(); } clock_t t2 = clock(); // cout << "Time-Taken: " << ((t2 - t1) / (double)CLOCKS_PER_SEC) << endl; // cout << CLOCKS_PER_SEC << endl; return 0; }
insert
79
79
79
81
TLE
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 10; const int MAX_V = 1e5 + 10; int main() { int n, max_w; scanf("%d%d", &n, &max_w); vector<long long> v(n), w(n); for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } vector<vector<long long>> dp(n + 1, vector<long long>(MAX_V, INF)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= MAX_V; j++) { if (dp[i][j] != INF) { 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]); } } } long long result = 0; for (int i = dp[n].size() - 1; i >= 0; i--) { if (dp[n][i] <= max_w) { result = i; break; } } cout << result; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18 + 10; const int MAX_V = 1e5 + 10; int main() { int n, max_w; scanf("%d%d", &n, &max_w); vector<long long> v(n), w(n); for (int i = 0; i < n; i++) { cin >> w[i] >> v[i]; } vector<vector<long long>> dp(n + 1, vector<long long>(MAX_V, INF)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < MAX_V; j++) { if (dp[i][j] != INF) { 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]); } } } long long result = 0; for (int i = dp[n].size() - 1; i >= 0; i--) { if (dp[n][i] <= max_w) { result = i; break; } } cout << result; return 0; }
replace
20
21
20
21
0
p03164
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define loop(i, x, n) for (int i = (x); i < (n); i++) #define all(v) (v).begin(), (v).end() #define int long long using namespace std; const int MOD = 1e9 + 7; const int INF = 1e10; template <typename T> void cmax(T &a, T b) { a = max(a, b); } template <typename T> void cmin(T &a, T b) { a = min(a, b); } signed main() { int N, W; cin >> N >> W; vector<int> w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<vector<int>> dp(101, vector<int>(100005, INF)); dp[0][0] = 0; rep(i, N) { rep(j, 100005) { cmin(dp[i + 1][j], dp[i][j]); cmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } int ans = 0; rep(i, 100005) if (dp[N][i] <= W) cmax(ans, i); cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stdlib.h> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define loop(i, x, n) for (int i = (x); i < (n); i++) #define all(v) (v).begin(), (v).end() #define int long long using namespace std; const int MOD = 1e9 + 7; const int INF = 1e10; template <typename T> void cmax(T &a, T b) { a = max(a, b); } template <typename T> void cmin(T &a, T b) { a = min(a, b); } signed main() { int N, W; cin >> N >> W; vector<int> w(N), v(N); rep(i, N) cin >> w[i] >> v[i]; vector<vector<int>> dp(101, vector<int>(100005, INF)); dp[0][0] = 0; rep(i, N) { rep(j, 100005) { cmin(dp[i + 1][j], dp[i][j]); if (100001 < j + v[i]) continue; cmin(dp[i + 1][j + v[i]], dp[i][j] + w[i]); } } int ans = 0; rep(i, 100005) if (dp[N][i] <= W) cmax(ans, i); cout << ans << endl; return 0; }
insert
35
35
35
37
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; int n, W; ll dp[105][100020]; int main(int argc, char const *argv[]) { cin >> n >> W; vector<ll> w(n); vector<ll> v(n); for (int i = 0; i < n; ++i) cin >> w[i] >> v[i]; REP(i, n + 10) REP(j, 100010) dp[i][j] = LINF; REP(i, n) dp[i][0] = 0; REP(i, n) REP(j, 100010) { dp[i + 1][j] = dp[i][j]; if (j - v[i] < 0) continue; else dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); } ll ans = 0; for (ll i = 0; i < 100010; ++i) { if (dp[n][i] > W) continue; else ans = max(ans, i); } cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> const int INF = 1e9; const int MOD = 1e9 + 7; const long long LINF = 1e18; #define dump(x) cout << 'x' << ' = ' << (x) << ` `; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOREACH(x, a) for (auto &(x) : (a)) typedef long long ll; using namespace std; int n, W; ll dp[105][100020]; int main(int argc, char const *argv[]) { cin >> n >> W; vector<ll> w(n); vector<ll> v(n); for (int i = 0; i < n; ++i) cin >> w[i] >> v[i]; REP(i, n) REP(j, 100010) dp[i][j] = LINF; REP(i, n) dp[i][0] = 0; REP(i, n) REP(j, 100010) { dp[i + 1][j] = dp[i][j]; if (j - v[i] < 0) continue; else dp[i + 1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]); } ll ans = 0; for (ll i = 0; i < 100010; ++i) { if (dp[n][i] > W) continue; else ans = max(ans, i); } cout << ans << std::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 int long long typedef unsigned long long ull; typedef long double ld; #define endl "\n" const int MAX = 300005; const long long mod = 1e9 + 7; int n, w; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int i, j, x = 0, y; cin >> n >> w; int v[n + 1], wt[n + 1]; for (i = 0; i < n; i++) { cin >> wt[i] >> v[i]; x += v[i]; } int dp[n + 1][x + 1]; for (i = 1; i <= x; i++) { dp[0][i] = INT_MAX; } dp[0][0] = 0; for (i = 1; i <= n; i++) { for (j = 0; j <= x; j++) { dp[i][j] = INT_MAX; } for (j = 0; j <= x; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i - 1]) { dp[i][j] = min(dp[i][j], wt[i - 1] + dp[i - 1][j - v[i - 1]]); } } } int ans = 0; for (i = 0; i <= x; i++) { if (dp[n][i] <= w) { ans = max(ans, i); } } /*for(i=1;i<=n;i++) { for(j=1;j<=x;j++) { cout<<dp[i][j]<<" "; } cout<<endl; }*/ cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int long long typedef unsigned long long ull; typedef long double ld; #define endl "\n" const int MAX = 300005; const long long mod = 1e9 + 7; int n, w; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int i, j, x = 0, y; cin >> n >> w; int v[n + 1], wt[n + 1]; for (i = 0; i < n; i++) { cin >> wt[i] >> v[i]; x += v[i]; } int dp[n + 1][x + 1]; for (i = 1; i <= x; i++) { dp[0][i] = INT_MAX; } dp[0][0] = 0; for (i = 1; i <= n; i++) { for (j = 0; j <= x; j++) { dp[i][j] = INT_MAX; } for (j = 0; j <= x; j++) { dp[i][j] = min(dp[i][j], dp[i - 1][j]); if (j >= v[i - 1]) { dp[i][j] = min(dp[i][j], wt[i - 1] + dp[i - 1][j - v[i - 1]]); } } } int ans = 0; for (i = 0; i <= x; i++) { if (dp[n][i] <= w) { ans = max(ans, i); } } /*for(i=1;i<=n;i++) { for(j=1;j<=x;j++) { cout<<dp[i][j]<<" "; } cout<<endl; }*/ cout << ans << endl; }
delete
14
18
14
14
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e3 + 10, M = 1e2 + 10; const int mod = 1e9 + 7; const int inf = 1e9; int w[M], v[M]; int dp[M][N]; int main() { int W, n; int val = 0; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; val += v[i]; } dp[0][0] = 0; for (int i = 1; i <= val; i++) dp[0][i] = inf; for (int j = 1; j <= n; j++) { for (int i = 0; i <= val; i++) { dp[j][i] = dp[j - 1][i]; if (i >= v[j]) { dp[j][i] = min(dp[j][i], dp[j - 1][i - v[j]] + w[j]); } } } int ans = 0; for (int i = 1; i <= val; i++) { if (dp[n][i] <= W) ans = i; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e5 + 10, M = 1e2 + 10; const int mod = 1e9 + 7; const int inf = 1e9; int w[M], v[M]; int dp[M][N]; int main() { int W, n; int val = 0; cin >> n >> W; for (int i = 1; i <= n; i++) { cin >> w[i] >> v[i]; val += v[i]; } dp[0][0] = 0; for (int i = 1; i <= val; i++) dp[0][i] = inf; for (int j = 1; j <= n; j++) { for (int i = 0; i <= val; i++) { dp[j][i] = dp[j - 1][i]; if (i >= v[j]) { dp[j][i] = min(dp[j][i], dp[j - 1][i - v[j]] + w[j]); } } } int ans = 0; for (int i = 1; i <= val; i++) { if (dp[n][i] <= W) ans = i; } cout << ans << '\n'; return 0; }
replace
3
4
3
4
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> #define DIM 100007 #define INF 1000000000000000007LL using namespace std; long long n, w[107], v[107], W, d[107][DIM], res; int main() { cin >> n >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; for (int i = 1; i < DIM; ++i) d[0][i] = INF; for (int i = 1; i <= n; ++i) for (int j = 1; j < DIM; ++j) { d[i][j] = min(d[i - 1][j], d[i - 1][j - v[i]] + w[i]); if (d[i][j] <= W) res = max(res, (long long)j); } cout << res; return 0; }
#include <bits/stdc++.h> #define DIM 100007 #define INF 1000000000000000007LL using namespace std; long long n, w[107], v[107], W, d[107][DIM], res; int main() { cin >> n >> W; for (int i = 1; i <= n; ++i) cin >> w[i] >> v[i]; for (int i = 1; i < DIM; ++i) d[0][i] = INF; for (int i = 1; i <= n; ++i) for (int j = 1; j < DIM; ++j) { d[i][j] = d[i - 1][j]; if (j >= v[i]) d[i][j] = min(d[i][j], d[i - 1][j - v[i]] + w[i]); if (d[i][j] <= W) res = max(res, (long long)j); } cout << res; return 0; }
replace
17
18
17
20
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 100000; const ll INF = 1e18 + 7107; int n, w[100005], v[100005], ans; ll f[100005], T; int main() { scanf("%d%lld", &n, &T); for (int i = 1; i <= n; i++) scanf("%d%d", &w[i], &v[i]); for (int i = 1; i <= MX; i++) f[i] = INF; f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = MX; j >= 1; j--) { if (f[j] >= v[i]) f[j] = min(f[j], f[j - v[i]] + w[i]); } } for (int i = 1; i <= MX; i++) if (f[i] <= T) ans = max(ans, i); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 100000; const ll INF = 1e18 + 7107; int n, w[100005], v[100005], ans; ll f[100005], T; int main() { scanf("%d%lld", &n, &T); for (int i = 1; i <= n; i++) scanf("%d%d", &w[i], &v[i]); for (int i = 1; i <= MX; i++) f[i] = INF; f[0] = 0; for (int i = 1; i <= n; i++) { for (int j = MX; j >= 1; j--) { if (j >= v[i]) f[j] = min(f[j], f[j - v[i]] + w[i]); } } for (int i = 1; i <= MX; i++) if (f[i] <= T) ans = max(ans, i); printf("%d\n", ans); return 0; }
replace
16
17
16
17
0
p03164
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef RED mt19937 rnd(228); #else mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); #endif const int N = (int)1e6 + 5; const ll inf = (ll)1e18; int n, W; ll w[N], v[N]; ll dp[N]; int main() { #ifdef RED freopen("a.in", "r", stdin); #endif ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n >> W; int sum = 0; for (int i = 1; i <= n; ++i) { cin >> w[i] >> v[i]; sum += v[i]; } for (int i = 0; i <= sum; ++i) { dp[i] = inf; } dp[0] = 0; for (int i = 1; i <= n; ++i) { vector<ll> mn(sum); for (int j = v[i]; j <= sum; ++j) { mn[j] = min(dp[j], dp[j - v[i]] + w[i]); } for (int j = v[i]; j <= sum; ++j) { dp[j] = mn[j]; } } for (int i = sum; i >= 0; i--) { if (dp[i] <= W) { cout << i; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #ifdef RED mt19937 rnd(228); #else mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); #endif const int N = (int)1e6 + 5; const ll inf = (ll)1e18; int n, W; ll w[N], v[N]; ll dp[N]; int main() { #ifdef RED freopen("a.in", "r", stdin); #endif ios_base ::sync_with_stdio(0); cin.tie(0); cin >> n >> W; int sum = 0; for (int i = 1; i <= n; ++i) { cin >> w[i] >> v[i]; sum += v[i]; } for (int i = 0; i <= sum; ++i) { dp[i] = inf; } dp[0] = 0; for (int i = 1; i <= n; ++i) { vector<ll> mn(sum + 10); for (int j = v[i]; j <= sum; ++j) { mn[j] = min(dp[j], dp[j - v[i]] + w[i]); } for (int j = v[i]; j <= sum; ++j) { dp[j] = mn[j]; } } for (int i = sum; i >= 0; i--) { if (dp[i] <= W) { cout << i; return 0; } } return 0; }
replace
36
37
36
37
0