Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d, cnt, day, price; int val[55]; int dp[500001]; int main() { cin >> n >> d; for (int i = 1; i <= n; i++) cin >> val[i]; sort(val + 1, val + n + 1); for (int i = 1; i <= n; i++) { if (price + d >= val[i]) price += val[i]; else break; } ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 510000; int f[maxn]; int n, d, up; int c[66]; int b[66]; int main() { cin >> n >> d; f[0] = 1; for (int i = 1; i <= n; i++) { int x; cin >> x; for (int j = (up += x); j >= x; j--) if (f[j - x]) f[j] = 1; } int num = 0, ans = 0; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const long long int inf = 1000000000; const long long int mod = 1000000000 + 7; inline void IO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); } template <class T> inline int CHECK(T M...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MALO = 64; const int DUZO = 10010 * MALO; int n, d; int price[MALO]; int backpack[DUZO]; void backpackize(int max_cost); int main() { scanf("%d %d", &n, &d); int summa = 0; for (int i = 0; i < n; i++) { scanf("%d", price + i); summa += price[i]; } ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int main() { ios::sync_with_stdio(false); int n, d; cin >> n >> d; int vetor[n]; for (int i = 0; i < n; i++) cin >> vetor[i]; long long combinacoes[600000]; memset(combinacoes, 0, sizeof combinacoes); for (int i = 0; i < n; i++...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } const int MAXN = 700010; int N, D; int dp[MAXN]; int main() { while (scanf("%d%d", &N, &D) != EOF) { memset(dp, 0, sizeof(dp)); dp[0] = 1; int sum = 0; for (int i = 1; i <= N; i++) { in...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d, mx = 0; int c[60], ok[500010] = {0}, dp[500010]; vector<int> v; int main() { scanf("%d%d", &n, &d); ok[0] = 1; for (int i = 1; i <= n; i++) { scanf("%d", &c[i]); mx += c[i]; } for (int i = 1; i <= n; i++) for (int j = mx; j >= c[i]; j--) ok[j...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 50 * 1e4 + 9; bool dp[N]; int main() { int n, d; scanf("%d%d", &n, &d); dp[0] = 1; int mx = 0; for (int i = 1; i <= n; ++i) { int x; scanf("%d", &x); for (int j = mx += x; j >= x; --j) dp[j] |= dp[j - x]; } int ans1 = 0, ans2 = 0; f...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXX = 500000; int dp[MAXX + 2]; int main() { int n, d, a; cin >> n >> d; dp[0] = 1; for (int i = 0; i < n; i++) { cin >> a; for (int j = MAXX; j >= 0; j--) if (dp[j] == 1 && j + a <= MAXX) dp[j + a] = 1; } int pos = 0, steps = 0; while...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool dp[1000005]; int main() { int n, d, x; scanf("%d%d", &n, &d); int sum = 0; dp[0] = true; for (int i = 0; i < n; i++) { scanf("%d", &x); sum += x; for (int j = sum; j >= x; j--) dp[j] |= dp[j - x]; } int day = 0, cost = 0; int i; while (1) ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int dp[500010]; int c[100]; int main() { int n, d; scanf("%d%d", &n, &d); memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) scanf("%d", &c[i]); dp[0] = 1; for (int i = 1; i <= n; i++) { for (int j = 500000 - c[i]; j >= 0; j--) { if (dp[j]) dp[j +...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool dp[51 * 10001]; int main() { int n, d, x, cnt = 0, sum = 0, w = 0; cin >> n >> d; dp[0] = 1; for (int i = 0; i < n; i++) { cin >> x; for (int j = (sum += x); j >= x; j--) { if (dp[j - x]) dp[j] = true; } } while (true) { int j = w + d;...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int mx = 50 + 5; const int mxv = 10000 + 5; const int mxs = mxv * mx; int data[mx]; bool possible[mxs]; int possibles[mxs], np; int main() { int n, d, i, j, k, l, v, tmp; cin >> n >> d; for (i = 0; i < n; i++) cin >> data[i]; fill(possible, possible + mxs, 0);...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 51; const int MAXVAL = MAXN * (1e4) + 123; int main(void) { static char bio[MAXVAL] = {0}; int n, d; scanf("%d %d", &n, &d); bio[0] = true; for (int i = 0; i < (n); ++i) { int x; scanf("%d", &x); for (int j = MAXVAL - 1; j >= 0; --j) {...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/stack:16777216") using namespace std; const double PI = acos(-1.0); const int INF = 1000000000; const int MAX = 2048; const int MAX2 = 1000007; const int MOD = 1000000007; bool dp[500007]; int main() { int n, d; cin >> n >> d; dp[0] = 1; for (int i = (0); i < (...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d; int a[60]; int dp[60][500000 + 10]; void solve() { int i, j, ans, days, temp; bool flag; memset(dp, 0, sizeof(dp)); dp[0][0] = 1; for (i = 0; i < n; i++) for (j = 0; j <= 500000; j++) if (dp[i][j]) { dp[i + 1][j] = 1; dp[i + 1][...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool pack[52 * 10005]; int items[52]; int sum; ; void Read(int n, int d) { sum = 0; for (int i = 0; i < n; ++i) { scanf("%d", &items[i]); sum += items[i]; } } void Solve(int n, int d) { memset(pack, 0, sizeof(pack)); pack[0] = true; for (int i = 0; i < n...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int N, D; int A[55]; bool dp[500005]; int kk[500005]; int main() { scanf("%d %d", &N, &D); for (int c = 1; c <= N; c++) scanf("%d", &A[c]); dp[0] = true; for (int c = 1; c <= N; c++) for (int d = 500000; d >= 0; d--) if (dp[d]) dp[d + A[c]] = true; int p...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAX = 5e5; int main() { int n, D; cin >> n >> D; vector<int> c(n); for (auto &ci : c) cin >> ci; vector<int> dp(MAX + 1); dp[0] = true; for (auto ci : c) { for (int j = MAX; j >= ci; j--) dp[j] |= dp[j - ci]; } int cur = 0, cnt = 0; bool up...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool dp[5 * 100000 + 100]; int c[55]; int main() { int n, d; int sum = 0; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> c[i]; sum += c[i]; } dp[0] = 1; for (int i = 0; i < n; ++i) for (int j = sum; j >= c[i]; --j) dp[j] |= dp[j - c[i]]; int...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool dp[500050]; int trace[500050]; int n, d; int a[55]; int main() { scanf("%ld%ld", &n, &d); for (int i = 1; i <= n; i++) scanf("%ld", &a[i]); memset(dp, false, sizeof(dp)); dp[0] = true; for (int i = 1; i <= n; i++) for (int j = 500000; j >= 0; j--) i...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> const int MAXN = 55, MAX = 6e5 + 10, littleMAX = 5e5 + 10; using namespace std; int n, d, last, ant, cnt; int c[MAXN]; bool dp[MAX]; int main() { scanf("%d%d", &n, &d); for (int i = 1; i < n + 1; i++) scanf("%d", &c[i]); dp[0] = true; for (int i = 1; i < n + 1; i++) for (int j = lit...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool dp[555556]; int main() { long long t, i, j, k, ans, n, d, sum; t = 1; while (t--) { cin >> n >> d; vector<long long> v(n); sum = 0; dp[0] = 1; for (long long p = 0; p < n; p++) { cin >> v[p]; for (long long q = 555555; q >= v[p]; q...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int f[5000010], d, n, w; int main() { cin >> n >> d; f[0] = 1; int sum = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; sum += x; for (int j = sum; j >= x; j--) if (f[j - x]) f[j] = 1; } int j = 0, ans = 0; while (1) { j = w + d; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MX = (1 << 20), INF = (1 << 31) - 1; int bit[MX], n, lim; bool dp[MX]; void update(int x, int V) { while (x > 0) { bit[x] = min(bit[x], V); x -= x & (-x); } } int get(int x) { if (x == 0) return 0; int res = INF; while (x <= lim) { res = min(...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int dp[20000006], n, d, c[55], sum, j, now, day = -1; int main() { cin >> n >> d; dp[0] = 1; for (int i = 1; i <= n; i++) { cin >> c[i]; sum += c[i]; for (j = sum; j >= c[i]; j--) if (dp[j - c[i]] == 1) dp[j] = dp[j - c[i]]; } while (1) { day...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> int n, d, x, max, i, j, ans; bool f[5100000]; int main() { scanf("%d%d", &n, &d); f[0] = true; for (i = 1; i <= n; i++) { scanf("%d", &x); for (j = (max += x); j >= x; j--) if (f[j - x]) f[j] = true; } x = 0; while (1) { j = ans + d; while (!f[j] && (j > ans)) ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const int MAXN = 510005; int dp[MAXN]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(20); int n, d; cin >> n >> d; memset(dp, 0, sizeof dp); dp[0] = 1; int items[n]; for (int i = 0; i < n; i++) ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const double INF = 1e20; const double eps = 1e-6; int n, m, d, sum, ma, co, x; int dp[500005]; int main() { int i, j, k; int T; scanf("%d%d", &n, &d); memset(dp, 0, sizeof(dp)); ma = co = sum = 0; for (i = 1; i <= n; i++) { scanf("%d", &x); for (j = sum;...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; import static java.lang.Integer.min; public class C365D { private static int n, d; private static int[] c; private static boolean[] dp; private static int maxSu...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n; int d; int a[57]; int pos[500007]; vector<int> v; void input(); void solve(); int main() { input(); solve(); return 0; } void input() { scanf("%d%d", &n, &d); int i, j; pos[0] = 1; for (i = 0; i < n; i++) { scanf("%d", &a[i]); for (j = 500000 - ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, sum; bool f[520000]; int main() { scanf("%d%d", &n, &m); f[0] = true; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); sum += x; for (int j = sum; j >= x; j--) { f[j] |= f[j - x]; } } int ans = 0, tot = 0; while (true) { ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 500010; bool f[MAXN]; int main() { int n, d; scanf("%d %d", &n, &d); f[0] = 1; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); for (int j = MAXN - 1 - x; j >= 0; --j) f[j + x] |= f[j]; } int r = 1, sum = 0, ans = 0; while (r ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool f[1000 * 1000]; int s, ans, j, c; int main() { int n, d; cin >> n >> d; f[0] = 1; for (int i = 0; i < n; i++) { int x; cin >> x; s += x; for (int j = s; j >= x; j--) if (f[j - x]) f[j] = 1; } while (1) { j = ans; ans += d; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int d[600050]; int a[100]; int main() { int x, n; scanf("%d%d", &n, &x); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); sort(a, a + n); int sum = 0; d[0] = 1; for (int i = 0; i < n; ++i) { if (sum + x < a[i]) break; for (int j = sum; j >= 0; --j) { ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(12); solve(); return 0; } template <typename T> void sc(T& x) { cin >> x; } template <typename Head, typename... Tail> void sc(Head& head, Tail&... tail) { cin ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int dp[550005]; int main() { int n, d, c, i, j, x, flog; scanf("%d %d", &n, &d); dp[0] = 1; for (i = 0; i < n; i++) { scanf("%d", &c); for (j = 500000; j >= c; j--) { dp[j] |= dp[j - c]; } } int day = 0; x = 0; while (1) { flog = 0; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXS = 50 * 10000; const int INF = 1000000000; int main() { ios_base::sync_with_stdio(0); int n, d; cin >> n >> d; vector<int> c(n); for (int i = 0; i < n; ++i) cin >> c[i]; vector<bool> sumy(MAXS + 1, false); sumy[0] = true; for (int i = 0; i < n;...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 500000; bool ok[N + 10]; int dist[N + 10]; int main() { int n, d; cin >> n >> d; vector<int> c(n); for (int i = 0; i < (n); i++) cin >> c[i]; ok[0] = 1; for (int i = 0; i < (n); i++) { for (int j = N; j >= c[i]; j--) { if (ok[j - c[i]]) o...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int main() { int n, d, sum = 0; cin >> n >> d; vector<int> dp(1000000, 0); dp[0] = 1; for (int i = 0; i < n; i++) { int a; cin >> a; sum += a; for (int j = sum; j >= a; j--) dp[j] |= dp[j - a]; } int i; int days = 0, cost = 0; while (1) { ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.io.*; import java.util.*; public class D implements Runnable { private void solve() throws IOException { int n = nextInt(), d = nextInt(), sum = 0; int[] c = new int[n]; for (int i = 0; i < n; i++) c[i] = nextInt(); for (int i = 0; i < n; i++) sum += c[i]; boolean[][] dp = new boolean[n + 1][su...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> int dp[500010]; int main() { int n, d; scanf("%d %d", &n, &d); dp[0] = 1; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); for (int i = 499999; i >= 0; i--) { if (i + x > 500000) continue; dp[i + x] |= dp[i]; } } int st = 0, nxt = -1; int ans = 0; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> int vis[5000005] = {0}; int main() { int n, d, i, j, a[55] = {0}; scanf("%d%d", &n, &d); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } vis[0] = 1; for (i = 0; i < n; i++) for (j = n * 10000; j >= 0; j--) { if (j - a[i] >= 0 && vis[j - a[i]] == 1) { vis[j] = 1...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int M = 10000 * 50 + 1; int v[50], valid[M], days[M]; int main() { int n, d; cin >> n >> d; for (int i = 0; i < n; i++) cin >> v[i]; sort(v, v + n); valid[0] = 1; for (int i = 0; i < n; i++) { int can = 0, d1 = M; for (int j = 0; j < M; j++) ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d, w, nex, cnt; int a[55], f[550005]; int inline read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, arr[55], d; bool can[520005]; int vis[55][500005]; void solve(int idx, int sum) { if (idx == n) { can[sum] = 1; return; } if (vis[idx][sum]) return; vis[idx][sum] = 1; solve(idx + 1, sum); solve(idx + 1, sum + arr[idx]); } int main() { cin >> n ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d; int a[51], dp[51 * 10000], sum; int main() { memset(dp, 0, sizeof(dp)); cin >> n >> d; sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } dp[0] = 1; for (int i = 1; i <= n; i++) { for (int j = sum; j >= a[i]; j--) i...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.io.BufferedInputStream; import java.io.IOException; import java.io.PrintWriter; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.InputMismatchEx...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import java.util.stream.IntStream; import static java.lang.Integer.min; public class C365D { private static int n, d; private static int[] c; private static boolean[] dp; private static int maxSu...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 10000 + 233; bool ok[maxn * 55]; int f[maxn * 55]; vector<int> a; int main() { int n, d; cin >> n >> d; memset(ok, 0, sizeof(ok)); ok[0] = 1; int sum = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; for (int i = sum; i >= 0; i--)...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, a[55], d, nb, b; bool p[800005]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; p[0] = true; for (int i = 0; i < n; i++) { for (int j = 500000; j >= 0; j--) { if (p[j]) { p[j + a[i]] = true; } } } while...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * @author Don Li */ public class FreeMarket2 { int V = (int) 5e5 + 10; void solve() { int n = in.nextInt(), d = in.nextInt(); ...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; long n, k, ar[200000]; long long reach[777777]; long long q; long long ans[777777]; multiset<long long> bst; multiset<long long>::iterator it; int main() { ios_base::sync_with_stdio(0); cin >> n >> k; for (int i = 1; i <= n; i++) cin >> ar[i]; reach[0] = 1; for (i...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, i, j, dp[555555], ans, sum, x; int main() { cin >> n >> m; for (i = 1; i <= n; i++) { cin >> x; for (j = 500000; j >= x; j--) { dp[j] |= dp[j - x] || j - x == 0; } } bool d = 1; while (d && ++ans) { d = 0; for (i = m + sum; i > ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int mod = 1000000007; int main() { int n, d, sum = 0; cin >> n >> d; vector<int> c(n); for (int i = 0; i < n; ++i) { cin >> c[i]; sum += c[i]; } vector<bool> can(sum + 1); can[0] = true; for (int i = 1; i <= sum; ++i) can[i] = false; for (int i = 0...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 51 * 10000 + 10; bitset<maxn> bs; int main() { int n, d; scanf("%d%d", &n, &d); bs.reset(); bs.set(0); int sum = 0; while (n--) { int c; scanf("%d", &c); sum += c; for (int i = sum; i >= c; i--) if (bs.test(i - c)) bs.set(i...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int dp[5000100]; int main() { int i, j, n, d; int cnt = 0, sum = 0, c = 0; dp[0] = 1; cin >> n >> d; int p; for (i = 0; i < n; i++) { cin >> p; for (j = (sum += p); j >= p; j--) if (dp[j - p] == 1) dp[j] = 1; } while (1 == 1) { j = d + c; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; const int MOD = 1e9 + 7; int dp[52][maxn]; int c[52]; void calc(int n, int maxW) { for (int i = 1; i <= n; ++i) { for (int w = 0; w < c[i - 1]; ++w) dp[i][w] = dp[i - 1][w]; for (int w = c[i - 1]; w <= maxW; ++w) dp[i][w] = max(dp[...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = 1000000000; const double eps = 1e-8; const int maxn = 511010; int a[maxn]; int dp[maxn]; int main() { int n, d; while (cin >> n >> d) { for (int i = (1); i <= (n); ++i) scanf("%d", &a[i]); memset(dp, 0, sizeof(dp)); dp[0] = 1; for (int i ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int n = in.nextInt(); int d = in.nextInt(); int[] c = new int[n]; for(int i = 0; i < n; ++i) c[i] = in.nextInt(); boolean[] feasible = new boole...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool flag[500005]; int main() { int n, k, i, j, in, ans = 0, now = 0; scanf("%d%d", &n, &k); vector<int> pos; pos.push_back(0); for (i = 0; i < n; i++) { scanf("%d", &in); for (j = pos.size(); j--;) { if (pos[j] + in < 500005 && flag[pos[j] + in] == ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d; int maxi; bool book[5000001]; int main() { std::ios::sync_with_stdio(false); int a; cin >> n >> d; book[0] = 1; for (register int i = 1; i <= n; i++) { cin >> a; for (register int j = 5000000; j >= a; j--) book[j] |= book[j - a]; } int ans = ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const long long INFL = LLONG_MAX; const int output_precision = 15; const bool debug = true; stringstream ss; int N, D, C[1000]; bool f[500100]; int main() { ios_base::sync_with_stdio(0); cout.precision(output_precision); cout << fixed; ss.pr...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d, all = 0, ans; bool f[900001]; int g[901001], c[100]; map<int, int> ma; int main() { srand(time(NULL)); ios_base::sync_with_stdio(0); f[0] = 1; cin >> n >> d; for (int i = 1; i <= n; ++i) { cin >> c[i]; all += c[i]; } for (int i = 1; i <= n; +...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int arr[50 + 5]; bool Sum[(int)1e4 * 50 + 5]; vector<int> vec; int main() { int N, D, ans = 0, maxi = 0, tot = 0; scanf("%d %d", &N, &D); for (int i = 0; i < N; i++) { scanf("%d", &arr[i]); tot += arr[i]; } Sum[0] = 1; for (int i = 0; i < N; i++) { f...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool dp[1000000]; int n, k, i, j, ans, d, res, x, calc = 0; int main() { ios::sync_with_stdio(false); scanf("%d %d", &n, &d); dp[0] = true; for (int i = 0; i < n; ++i) { scanf("%d", &x); for (int j = 500000; j >= x; --j) dp[j] |= dp[j - x]; } for (;;) { ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d, c[55]; int can[55 * 10000], sum = 0; int main() { cin >> n >> d; for (int i = 0; i < n; i++) { cin >> c[i]; sum += c[i]; } can[0] = 1; for (int i = 0; i < n; i++) for (int j = sum - c[i]; j >= 0; j--) if (can[j]) can[j + c[i]] = 1; in...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 50; int main() { int N, D; cin >> N >> D; int a[MAXN]; for (int i = 0; i < N; i++) cin >> a[i]; const int MAXSUM = accumulate(a, a + N, 0); vector<bool> dp(MAXSUM + 1, false); dp[0] = true; for (int i = 0; i < N; i++) for (int j = MAXSUM...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.util.*; public class D { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); int d = sc.nextInt(); int[] item = new int[n]; int[] daysToValue = new int[1000000]; int[] topDay = new int[1000000]; boolean[] values = new boolean[1000000]; valu...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d; int a[55]; int f[55][550010]; int dp(int l, int last) { for (int i = 1; i <= n; i++) for (int j = last; j <= l; j++) f[i][j] = max((j >= a[i] ? f[i - 1][j - a[i]] + a[i] : 0), f[i - 1][j]); return f[n][l]; } int main() { scanf("%d%d", &n, &d); fo...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(12); solve(); return 0; } template <typename T> void sc(T& x) { cin >> x; } template <typename Head, typename... Tail> void sc(Head& head, Tail&... tail) { cin ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.util.Scanner; public class D_213 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int d = in.nextInt(); int c[] = new int[n+1]; int total = 0; for(int i = 1; i <= n; i++){ c[i] = in.nextInt(); total += c[i]; } boolean t[][] = ne...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; long long LLMAX = 9223372036854775807LL; const int MOD = 1000000007; const int maxn = 4000 + 10; int n, d, c[55]; vector<int> s; int main() { scanf("%d %d", &(n), &(d)); for (int(i) = 0; (i) < (int)(n); ++(i)) scanf("%d", &(c[i])); bitset<500001> dp; dp.set(0); s....
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const long long maxN = 1e6 + 5; const long long inf = 1e10; const long long mod = 1e9 + 7; long long n, d; long long f[maxN]; long long x; long long used[maxN]; vector<long long> a; int main() { ios_base::sync_with_stdio(0); cin >> n >> d; used[0] = 1; a.push_back(0...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int N = 500010; const int M = 1e9 + 0.5; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const int pi = cos(-1.0); const long long oo = 0x3f3f3f3f3f3f3f3fll; int n, dp[N], d; int main() { scanf("%d%d", &n,...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(12); solve(); return 0; } template <typename T> void sc(T& x) { cin >> x; } template <typename Head, typename... Tail> void sc(Head& head, Tail&... tail) { cin ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; struct node { int a; int b; int c; int d; }; bool cmp(const node &first, const node &sec) { if (first.a != sec.a) return first.a < sec.a; return first.b < sec.b; } bool operator<(const node &left, const node &right) { return left.b > right.b; } int n, d, da, i, ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d; int v[50 + 5]; bool F[5000000 + 5]; int main() { scanf("%d%d", &n, &d); for (int i = 1; i <= n; i++) scanf("%d", &v[i]); F[0] = true; int sum = 0; for (int i = 1; i <= n; i++) { sum += v[i]; for (int j = sum; j >= v[i]; j--) F[j] |= F[j - v[i]]; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; bool sum[550000]; int main() { memset(sum, 0, sizeof sum); sum[0] = 1; int n, d, aux; cin >> n >> d; int max = 0; for (int i = 0; i < n; i++) { cin >> aux; for (int j = max; j >= 0; j--) { if (sum[j] == 1) { sum[j + aux] = 1; if (j ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(12); solve(); return 0; } template <typename T> void sc(T& x) { cin >> x; } template <typename Head, typename... Tail> void sc(Head& head, Tail&... tail) { cin ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; mt19937_64 random_num( chrono::high_resolution_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const int base = 26; int n, d; int a[55]; bool f[500001]; int res[500001]; multiset<int> s; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:268435456,268435456") using namespace std; bool dp[510001]; int main() { int n, d, t; scanf("%d %d", &n, &d), dp[0] = 1; for (int i = 0; i < n; i++) { scanf("%d", &t); for (int j = 510001; j - t >= 0; j--) dp[j] |= dp[j - t]; } int curr = 0, num...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int dp[550005]; int main() { int n, d, c, i, j, x, flog; scanf("%d %d", &n, &d); dp[0] = 1; for (i = 0; i < n; i++) { scanf("%d", &c); for (j = 500000; j >= c; j--) { dp[j] |= dp[j - c]; } } int day = 0; x = 0; while (1) { flog = 0; ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline string get() { char ch[1000000]; scanf("%s", ch); return ch; } template <class P, class Q> inline P smin(P &a, Q b) { if (b < a) a = b; return a; } template <class P, class Q> inline P smax(P &...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXINT = 1 << 31 - 1; const int MAXN = 55 * 1e4 + 5; int dp[MAXN]; int arr[60]; int n, d; int main() { while (cin >> n >> d) { int big = 0; for (int i = (0); i < (n); i += 1) { scanf("%d", &arr[i]); big += arr[i]; } fill(dp, dp + big ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int n, d; int c[51], dp[500001]; bool v[500001]; int main() { cin >> n >> d; for (int i = 1; i <= n; i++) cin >> c[i]; sort(c + 1, c + 1 + n); int sum = 0, cnt; for (int i = 1; i <= n; i++) { if (sum + d >= c[i]) { sum += c[i]; } else { cnt = i...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; long long n, k, s, sum = 0, ans = 0; int f[1000005]; int a[1000005]; long long p, q, x = 0; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); } f[0] = 1; for (int i = 1; i <= n; i++) { sum += a[i]; for (long long j = sum; j...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000") using namespace std; const int inf32 = 1e9 + 9; const long long inf64 = 1e18 + 18; const int N = 6e5 + 5; const long long mod = 1e9 + 7; bitset<N> bits; void solve() { int n, d, a, ans = 0; scanf("%d%d", &n, &d); bits[0] = true; while (n--) { ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 55 * 10007; vector<int> v; bool mark[10000000]; int main() { int n, d; cin >> n >> d; for (int i = 1; i <= n; i++) { int x; cin >> x; v.push_back(x); } sort(v.begin(), v.end()); mark[0] = 1; for (int i = 0; i <= n; i++) { for (...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int max_n = 50; const int max_d = 1e4 + 100; const int max_sum = max_n * max_d; int n, d; int sum[max_sum]; int main() { ios_base::sync_with_stdio(false); cin >> n >> d; sum[0] = 1; for (int i = 0; i < n; ++i) { int c; cin >> c; for (int i = max_su...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; int dp[MAXN]; int main() { int n, d, x; int cnt, sum, ans; cnt = sum = ans = 0; scanf("%d %d", &n, &d); dp[0] = 1; for (int i = 0; i < n; i++) { scanf("%d", &x); sum += x; for (int j = sum; j >= x; j--) { if (dp[j - x]...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int maxN = 51 * 52; const int INF = maxN * maxN; const int maxE = 51 * 10000; vector<int> G[maxN]; vector<int> G2; queue<pair<int, int> > Q; bool mark[maxN]; int sum[maxN], a[maxN], dist[maxN], dp[maxN][maxN], dp2[51][maxE], n, d, tul, ans1, ans2; long long getSum...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; /** * @author Don Li */ public class FreeMarket { int V = (int) 5e5 + 10; void solve() { int n = in.nextInt(), d = in.nextInt(); ...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int DEBUG = 0; int isatt[2][600000]; int ispurable[600000]; int steps[600000]; int main(int argc, char **argv) { DEBUG = (argc >= 2) ? atoi(argv[1]) : 0; int n, d; cin >> n >> d; int c[n]; for (int i = 0; i < n; i++) cin >> c[i]; for (int i = 0; i < 2; i++) { ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 500010; bool f[MAXN]; int a[MAXN]; vector<int> sta; int main() { int n, d; while (scanf("%d%d", &n, &d) != EOF) { memset(f, false, sizeof(f)); f[0] = true; int tot = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); tot +...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int a[55]; int dp[55][505005]; int main() { cin.sync_with_stdio(0); int n, d; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> a[i]; } dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 505005; j++) { if (dp[i][j]) { dp[i ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int dp[500001]; int main() { int n, d, x = 0, i, j; int a[50]; scanf("%d %d", &n, &d); for (i = 0; i < n; i++) scanf("%d", &a[i]); dp[0] = 1; for (i = 0; i < n; i++) { for (j = 500000; j >= 0; j--) { if (dp[j] == 1) dp[j + a[i]] = 1; } } for (i...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; using namespace std; int dp[5000005], d, n, cnt, ans; int main() { cin >> n >> d; dp[0] = 1; int sum = 0, x; for (int i = 0; i < n; i++) { cin >> x; sum += x; for (int j = sum; j - x >= 0; j--) { if (dp[j - x]) { dp[j] = 1; } } ...
CPP
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
import java.util.*; import java.io.*; public class Main { BufferedReader in; StringTokenizer str = null; PrintWriter out; private String next() throws Exception{ if (str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } private int nextInt() throws...
JAVA
365_D. Free Market
John Doe has recently found a "Free Market" in his city β€” that is the place where you can exchange some of your possessions for other things for free. John knows that his city has n items in total (each item is unique). You can bring any number of items to the market and exchange them for any other one. Note that eac...
2
10
#include <bits/stdc++.h> using namespace std; int sum[500001]; int main() { int n, d; scanf("%d%d", &n, &d); sum[0] = 1; for (int i = 0, c; i < n; ++i) { scanf("%d", &c); for (int s = 500000; s >= 0; --s) if (sum[s]) sum[s + c] = 1; } vector<int> var; for (int i = 1; i < 500001; ++i) if ...
CPP