text
stringlengths
49
983k
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") const long long INF = 0x3f3f3f3f3f3f3f3f; const long long llinf = (1LL << 62); const int inf = (1 << 30); const int nmax = 1e2 + 50; const long long mod = 1e9 + 7; using namespace std; long long ts, i, j, n, f[nmax][nmax][2], k, k1...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; int scan() { return getchar(); } void scan(int& a) { cin >> a; } void scan(long long& a) { cin >> a; } void scan(char& a) { c...
#include <bits/stdc++.h> using namespace std; struct edge { int toi, toj; long long cost; long long label; }; int main() { int T; cin >> T; for (int _ = 0; _ < T; _++) { int n, k; cin >> n >> k; vector<vector<long long>> a; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; ...
#include <bits/stdc++.h> using namespace std; int n, k; struct pairab { int a, b, idx; }; bool compare(pairab i1, pairab i2) { return (i1.b == i2.b) ? (i1.a < i2.a) : (i1.b < i2.b); } pairab in[80]; int inf = (int)1e9; int memo[80][80]; int dp(int i, int takenInFirstK) { if (takenInFirstK > k) return -inf; if (...
#include <bits/stdc++.h> using namespace std; int n, k; long long aa[100], bb[100], ww[100]; int tt; int dv[100][100][100]; long long dd[100][100][100]; int dt[100][100][100]; long long calc(int a, int b, int c) { if (a == 0 && b == 0) return 0; if (a == 0 || b < 0) return -999999999999999LL; if (dv[a][b][c] == t...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-12; const int inf = 2000000000; const long long int infLL = (long long int)1e18; long long int MOD = 1000000007; int MOD1 = 1000000007; int MOD2 = 1000000009; inline bool checkBit(long long int n, long long int i) { return...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFLL = 1e18; const int MOD = 1e9 + 7; const int MAXN = 2e5 + 5; tuple<int, int, int> minions[111]; bool picked[111]; long long dp[111][111]; int n, k; vector<int> ans; void mxze(long long &a, long long b) { a = max(a, b); } long ...
#include <bits/stdc++.h> using namespace std; const int inf = 1012345678; vector<int> transform(int n, vector<int> arr, vector<int> perm) { vector<int> res(n); for (int i = 0; i < n; ++i) { res[i] = arr[perm[i]]; } return res; } int main() { int Q; cin >> Q; while (Q--) { int N, K; cin >> N >>...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<ll>; const int maxn = 80; ll n, dp[maxn][maxn], p[maxn][maxn]; vector<pair<ll, ll>> a; vi used; map<pair<ll, ll>, vi> idx; vi ans; void track(int n, int k) { if (!n) return; if (p[n][k] == 2) { track(n - 1, k - 1); used[id...
#include <bits/stdc++.h> const int inf = 0x3f3f3f3f, Inf = 0x7fffffff; const long long INF = 0x7fffffffffffffff; __inline__ __attribute__((always_inline)) unsigned int rnd() { static unsigned int seed = 416; return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13; } template <typename _Tp> _Tp gcd(const _T...
#include <bits/stdc++.h> using namespace std; const int N_MAX = 77; int t; int n, k; struct Minion { int a, b; int index; }; bool operator<(const Minion &x, const Minion &y) { return x.b < y.b; } Minion v[N_MAX]; int dp[N_MAX][N_MAX]; bool step[N_MAX][N_MAX]; bool lastk[N_MAX]; int main() { ios_base::sync_with_st...
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long inf_ll = 1e18; const long long N = 100; array<long long, 3> a[N]; long long dp[N][N], res[2 * N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n, k; ...
#include <bits/stdc++.h> using namespace std; struct pt { int a, b, ind; pt() {} pt(int a, int b, int ind) : a(a), b(b), ind(ind) {} }; const int inf = 1e9; int n, k; void solve(int tc) { scanf("%d", &n); scanf("%d", &k); vector<pt> ar(n); for (int i = 0; i < n; ++i) { int a, b; scanf("%d", &a); ...
#include <bits/stdc++.h> using namespace std; const int maxn = 100 + 5; struct node { long long x, y; int id; bool operator<(const node &ope) const { return y < ope.y; } } a[maxn]; bool vis[maxn][maxn]; long long dp[maxn][maxn]; bool vis2[maxn]; inline void init() { memset(dp, -1, sizeof(dp)); memset(vis, fal...
#include <bits/stdc++.h> template <typename T> inline void chkmin(T &x, T y) { x = min(x, y); } template <typename T> inline void chkmax(T &x, T y) { x = max(x, y); } template <typename T> inline void read(T &x) { T f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -...
#include <bits/stdc++.h> using namespace std; constexpr long double m_pi = 3.1415926535897932L; constexpr long long MOD = 1000000007; constexpr long long INF = 1LL << 61; constexpr long double EPS = 1e-10; template <typename T> using vector2 = vector<vector<T>>; template <typename T> using vector3 = vector<vector2<T>>;...
#include <bits/stdc++.h> using namespace std; const int Maxn = 88, inf = 0x3f3f3f3f; struct node { int a, b, id; } g[Maxn]; int f[Maxn][Maxn], s[Maxn]; bool flag[Maxn][Maxn], vis[Maxn]; int a[Maxn], b[Maxn], id[Maxn]; int n, m, cnt; inline bool cmp(node x, node y) { return x.b < y.b; } void init() { for (int i = 0;...
#include <bits/stdc++.h> using namespace std; const int N = 100; inline int Read(int &r) { int b = 1, c = getchar(); r = 0; while (c < '0' || '9' < c) b = c == '-' ? -1 : b, c = getchar(); while ('0' <= c && c <= '9') r = (r << 1) + (r << 3) + (c ^ '0'), c = getchar(); return r *= b; } int n, m, ndel, cas...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int n, k, dp[76][76]; array<int, 3> a[75]; bool last[76][76]; void solve() { cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i][1] >> a[i][0], a[i][2] = i; sort(a, a + n); for (int i = 1; i <= n; ++i) { for (int j = 0; j <= i; ++j) { ...
#include <bits/stdc++.h> using namespace std; const int N = 77; int t, n, k, inv[N]; long long a[N], b[N], a2[N], b2[N], dp[N][N]; bool summon[N][N], s[N], ans[N][N]; long long solve() { dp[0][0] = 0; for (int i = (1); i < (n + 1); i++) { for (int j = (0); j < (min(k, i) + 1); j++) { dp[i][j] = -1; ...
#include <bits/stdc++.h> using namespace std; int T, N, K, a, b; int main(int argc, const char *argv[]) { cin >> T; for (int t = 0; t < T; t++) { cin >> N >> K; vector<pair<int, pair<int, int>>> minions; for (int i = 1; i <= N; i++) { cin >> a >> b; minions.push_back(make_pair(b, make_pair(a...
#include <bits/stdc++.h> using namespace std; namespace IO { const int buffer_size = 1e5 + 5; char buf[buffer_size], *S, *T; bool flag_EOF; inline char read_char() { if (S == T) T = (S = buf) + fread(buf, 1, buffer_size, stdin); return S != T ? *(S++) : EOF; } inline int read_int() { int flag = 1; char c = read...
#include <bits/stdc++.h> using namespace std; long long inf; const double eps = 1e-8; const double pi = acos(-1.0); template <class T, class T2> long long chkmin(T &a, T2 b) { return a > b ? a = b, 1 : 0; } template <class T, class T2> long long chkmax(T &a, T2 b) { return a < b ? a = b, 1 : 0; } template <class T>...
#include <bits/stdc++.h> using namespace std; long long n, k, dp[100][100], tak[100][100]; pair<long long, pair<long long, long long> > a[100]; void solve() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i].second.first >> a[i].first; a[i].second.second = i; } for (int i = 1; i <= 75; i++) ...
#include <bits/stdc++.h> using namespace std; bool cmp(pair<pair<long long, long long>, long long> a, pair<pair<long long, long long>, long long> b) { return a.first.second < b.first.second; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; ...
#include <bits/stdc++.h> using namespace std; int n, k; int dp[80][80]; bool included[80]; pair<pair<int, int>, int> A[80]; vector<int> ans; bool byfise(pair<pair<int, int>, int> i, pair<pair<int, int>, int> j) { return i.first.second < j.first.second; } void backtrack() { int x = n, y = k; while (x) { if (y ...
#include <bits/stdc++.h> using namespace std; const int INF = int(1e9) + 7; const int maxd = int(3e5) + 11; const int maxe = int(3e5) + 11; int tot = 0, topt = 0; int head[maxd]; int S, T, e[210][210]; struct Edge { int from, to, cap, cost, next; Edge() {} Edge(int x, int y, int a, int b, int c) : from(x), ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; const int inf = (1 << 30) - 1; const ll INF = (1LL << 60) - 1; template <typename T> bool chmax(T &x, const T &y) { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 5; int n, k; struct node { int id, a, b; node(int i = 0, int _a = 0, int _b = 0) { id = i, a = _a, b = _b; } bool operator<(const node& a) const { return b < a.b; } } p[N]; long long dp[N][N]; int pre[N][N]; int main() { int TTT; cin >> TTT; ...
#include <bits/stdc++.h> using namespace std; int f[80][80], g[80][80], n, m, is[80]; struct T { int a, b, id; } a[80]; void Solve() { cin >> n >> m, memset(f, 0xc0, sizeof(f)), f[0][0] = 0; for (int i = 1; i <= n; i++) cin >> a[i].a >> a[i].b, a[i].id = i, is[i] = 0; sort(a + 1, a + n + 1, [](T i, T j) { retur...
#include <bits/stdc++.h> using namespace std; template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; os << "]"; return os; } template <class T> ostream &operator<<(ostream &os, set<T> S) { os << "{ "; for (auto s : S) os << s << " "; return os << "}...
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e4 + 100, M = 81; int T, n, k, a[M], b[M], ans, p[M], in[M]; int s, t, d[N], pe[N], pn[N], flow[N], vi[N]; int tot, first[N], nxt[N * 2], point[N * 2], data[N * 2], cost[N * 2]; inline int read() { int f = 1, x = 0; char s = getchar(); while (s < '0...
#include <bits/stdc++.h> using namespace std; using lld = long long; const int INF = 1e9; const int MAXN = 75; struct Minion { int a, b; int nr; }; bool operator<(const Minion& a, const Minion& b) { if (a.b != b.b) return a.b < b.b; return a.nr < b.nr; } int dp[MAXN + 5][MAXN + 5]; void query(void) { int n, k...
#include <bits/stdc++.h> using namespace std; const int N = 0, M = 0; int read() { char c; int num, f = 1; while (c = getchar(), !isdigit(c)) if (c == '-') f = -1; num = c - '0'; while (c = getchar(), isdigit(c)) num = num * 10 + c - '0'; return num * f; } struct node { int a, b, id; } p[109]; int n, ...
#include <bits/stdc++.h> using namespace std; const double pi = 2 * acos(0.0); const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; const int dx8[] = {-1, 0, 1, 0, 1, 1, -1, -1}; const int dy8[] = {0, -1, 0, 1, 1, -1, 1, -1}; long long min(long long a, long long b) { if (a < b) return a; return b; } long...
#include <bits/stdc++.h> using namespace std; const int Maxn = 88; struct node { int a, b, id; } g[Maxn]; int f[Maxn][Maxn], s[Maxn]; bool flag[Maxn][Maxn], vis[Maxn]; int a[Maxn], b[Maxn], id[Maxn]; int n, m, cnt; inline bool cmp(node x, node y) { return x.b < y.b; } void init() { for (int i = 1; i <= n; ++i) ...
#include <bits/stdc++.h> using namespace std; using vi = vector<long long>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vvvvi = vector<vvvi>; using vp = vector<pair<long long, long long> >; using vvp = vector<vp>; using vb = vector<bool>; using vvb = vector<vb>; const long long inf = 1001001001001001001; co...
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int n, k, tab[75][75], d, linkx[75], linky[75], tx[75], ty[75]; bool visx[75], visy[75]; bool dfs(int x) { visx[x] = true; for (int i = 0; i < n; i++) { if (!visy[i] && tx[x] + ty[i] == tab[x]...
#include <bits/stdc++.h> using namespace std; int a[75]; int b[75]; int order[75]; int main() { cin.tie(0); ios_base::sync_with_stdio(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; for (int i = 0; i < n; ++i) cin >> a[i] >> b[i], order[i] = i; sort(order, order + n, [&](int x, int...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { cout << x; } void __print(unsigned x) { cout << x; } void __print(unsigned long x) { cout << x; } void __print(unsigned long long x) { cout << x; } void __print(float x) { cou...
#include <bits/stdc++.h> using namespace std; const int maxn = 80; int n, m; int a[maxn], b[maxn], id[maxn]; int f[maxn][maxn], g[maxn][maxn]; bool used[maxn]; inline int read() { char c = getchar(); int res = 0, f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0...
#include <bits/stdc++.h> const int MAXN = 105; const long long INF = (long long)1e18 + 5; using namespace std; struct Mon { long long a, b, id; bool operator<(const Mon &m) const { return b < m.b; } }; long long n; Mon mon[MAXN]; long long dp[MAXN][MAXN], from[MAXN][MAXN]; vector<int> ans; long long solve(int take)...
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool cmax(T &x, T y) { return x < y ? x = y, 1 : 0; } template <typename T> inline bool cmin(T &x, T y) { return y < x ? x = y, 1 : 0; } const int _ = 105; struct node { int a, b, i; bool operator<(const node &t) const { return b < t.b; ...
#include <bits/stdc++.h> using namespace std; struct pii { int first, second, id; }; const int N = 76, INF = (int)1e9; int n, k; pii p[N]; int dp[N][N], tk[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while (T--) { cin >> n >> k; for (int i = 1; i < (n + 1); ++i) ...
#include <bits/stdc++.h> using namespace std; struct min_cost_flow { static const int64_t INF = numeric_limits<int64_t>::max() >> 1; int64_t n, s, t; struct edge { int64_t u, v, c, f, cost; }; vector<edge> E; vector<vector<int64_t>> graph; vector<int64_t> dist, head; vector<bool> inq; min_cost_flo...
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e2 + 100; const long long mod = 1e9 + 7; const long long base = 1e18; pair<pair<long long, long long>, long long> a[maxn]; long long dp[maxn][maxn]; bool par[maxn][maxn]; bool lf(pair<pair<long long, long long>, long long> a, pair<pair<long l...
#include <bits/stdc++.h> #pragma GCC optimize(3, "Ofast", "inline") #pragma GCC target("avx") using namespace std; inline char gc() { static char buf[1 << 16], *p1 = buf, *p2 = buf; if (p1 == p2) { p2 = (p1 = buf) + fread(buf, 1, 1 << 16, stdin); if (p2 == p1) return EOF; } return *p1++; } template <cla...
#include <bits/stdc++.h> using namespace std; const int N = 75 + 10; struct re { int a, b, id; } a[N]; long long f[N][N]; bool plan[N][N]; bool choose[N]; vector<int> actions; void get_plan(int x, int y) { if (x == 0) return; if (plan[x][y]) choose[x] = true; get_plan(x - 1, y - plan[x][y]); } int main() { in...
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int>> v; long long dp[80][80]; pair<int, int> from[80][80]; set<int> s; int main() { int t; cin >> t; while (t) { t--; int i, j, n, k; cin >> n >> k; v.clear(); s.clear(); for (i = 1; i <= n; i++) { int a, b; ...
#include <bits/stdc++.h> using namespace std; template <class T> struct rge { T b, e; }; template <class T> rge<T> range(T i, T j) { return rge<T>{i, j}; } struct debug { template <class T> debug& operator<<(const T&) { return *this; } }; using ll = long long; template <typename T> void min_self(T& a, T b...
#include <bits/stdc++.h> using namespace std; const long double PI = acos(-1.0); array<long long, 3> a[80]; long long dp[80][80]; long long par[80][80]; void solve() { long long n, k; cin >> n >> k; for (long long i = 0; i < n; ++i) { cin >> a[i][1] >> a[i][0]; a[i][2] = i + 1; } memset(dp, 0, sizeof ...
#include <bits/stdc++.h> using namespace std; long long t, n, k, dp[80][80]; pair<pair<long long, long long>, long long> v[100]; long long f(int pos, long long num) { if (dp[pos][num] != -1) return dp[pos][num]; if (pos == n) { if (num != k) return dp[pos][num] = -1000000000000000; else return d...
#include <bits/stdc++.h> using namespace std; const long long inff = 0x3f3f3f3f3f3f3f3f; const int N = 1e2 + 8; int w[N][N], x[N], y[N], pop, n, k, lx, ly, a[N]; int px[N], py[N], sy[N], slack[N], par[N]; void adjust(int v) { sy[v] = py[v]; if (px[sy[v]] != -2) adjust(px[sy[v]]); } bool fid(int v) { for (int i(0)...
#include <bits/stdc++.h> struct E { int a, b, rt; } s[76]; int dp[76][76], ch[76][76], v[76]; int st[76]; bool mk[76]; void work() { memset(dp, 0xAC, sizeof(dp)); memset(v, 0, sizeof(v)); memset(mk, 0, sizeof(mk)); int n, k; scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { s[i].rt = i; scanf(...
#include <bits/stdc++.h> using namespace std; vector<pair<pair<int, int>, int>> v; long long dp[80][80]; pair<int, int> from[80][80]; set<int> s; int main() { int t; cin >> t; while (t) { t--; int i, j, n, k; cin >> n >> k; v.clear(); s.clear(); for (i = 1; i <= n; i++) { int a, b; ...
#include <bits/stdc++.h> using namespace std; int f[505][505], g[505][505], a[505], b[505], id[505], xinyue, n, m, vis[505], ed; int cmp(int x, int y) { return b[x] < b[y]; } void dfs(int n, int m) { if (!n) return; if (g[n][m] == 1) vis[n] = 1, m--; dfs(n - 1, m); } int main() { scanf("%d", &xinyue); whi...
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int inf = 0x3f3f3f3f; const long long int infl = 1e18; long long int din[109][109]; int prv[109][109], t; struct st { int x, y, id; }; st p[100]; int main() { cin >> t; while (t--) { int n, k; cin >> n >> k; memset(din, -1...
#include <bits/stdc++.h> using namespace std; const int maxn = 75; struct node { int a, b, num; } p[maxn + 11]; int f[maxn + 11][maxn + 11][2]; vector<int> v1, v2; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t; cin >> t; for (int kase = 1; kase <= t; kase++) { int n, k; cin...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) { if (x < y) x = y; ...
#include <bits/stdc++.h> using namespace std; inline long long mod(long long n, long long m) { long long ret = n % m; if (ret < 0) ret += m; return ret; } long long gcd(long long a, long long b) { return (b == 0LL ? a : gcd(b, a % b)); } long long exp(long long a, long long b, long long m) { if (b == 0LL) ret...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const int N = 100; array<long long, 3> a[N]; long long dp[N][N]; int anc[N][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; for (int i = 0; i < n; i++...
#include <bits/stdc++.h> using namespace std; using ll = long long; using cd = complex<double>; int main() { ll t; cin >> t; while (t--) { ll n, k; cin >> n >> k; pair<pair<ll, ll>, ll> ar[n]; for (ll i = 0; i < n; i++) { cin >> ar[i].first.second >> ar[i].first.first; ar[i].second = i...
#include <bits/stdc++.h> using namespace std; template <typename T> void r1(T &x) { x = 0; char c(getchar()); int f(1); for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1; for (; '0' <= c && c <= '9'; c = getchar()) x = (x * 10) + (c ^ 48); x *= f; } template <typename T, typename... Args> i...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long inf = 1LL << 50; const int N = 75; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin.exceptions(cin.failbit); int T; cin >> T; for (int z = 0; z < T; z++) { int n, k; cin >> n >> k; vector...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) { if (x > y) x = y; } template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) { if (x < y) x = y; ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; const int NINF = -1 * 1e9; void print2d(vector<vector<int>> &v) { for (int i = 0; i < (int)v.size(); i++) { for (int j = 0; j < (int)v[i].size(); j++) { cout << v[i][j] << " "; } cout << endl; } } int wa...
#include <bits/stdc++.h> using namespace std; clock_t start; mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); template <typename T> void _F(const char *name, T arg1) { cerr << name << " = " << arg1 << '\n'; } template <typename T, typename... Args> void _F(const char *names, T arg1, Args... arg...
#include <bits/stdc++.h> using namespace std; struct Minion { int ind; long long a, b; Minion(int ii = 0, long long ia = 0, long long ib = 0) { ind = ii; a = ia; b = ib; } }; bool cmp(Minion a, Minion b) { return a.b < b.b; } Minion a[100]; long long dp[100][100]; void solve() { int n, k; cin >>...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 10; vector<int> del, add; int n, k, dp[maxn][maxn], pre[maxn][maxn]; struct minion { int a, b, id; bool operator<(const minion &A) const { return b == A.b ? a < A.a : b < A.b; } void read(int i) { id = i; scanf("%d%d", &a, &b); } } da[...
#include <bits/stdc++.h> using namespace std; int me[76][76]; int de[76][76]; int n, k; int res[200]; const int INF = 1000000000; vector<pair<int, pair<int, int> > > mv; int dp(int ac, int ll) { if (me[ac][ll] >= 0) return me[ac][ll]; if (ac == n) return me[ac][ll] = 0; if (ll < k) { me[ac][ll] = mv[ac].first...
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; long long a1[n], b1[n]; for (int i = 0; i < n; i++) cin >> a1[i] >> b1[i]; long long dp[n][k]; vector<long long> a, b; vector<pair<pair<long long, long long>, long long> > e; vector<long long> ans; long long mx = 0; ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; void *wmem; char memarr[96000000]; template <class T> inline void walloc1d(T **arr, int x, void **mem = &wmem) { static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void *)(((char *)(*mem)) + skip[((unsig...
#include <bits/stdc++.h> using namespace std; const int N = 200; const int M = 20000; const int oo = 0X10101010; int mym; int S, T; struct adj { int ano, cap, wei, nex; } adj[M]; int nod[N]; void insert(int x, int y, int c, int w) { adj[mym].ano = y; adj[mym].cap = c; adj[mym].wei = w; adj[mym].nex = nod[x]; ...
#include <bits/stdc++.h> using namespace std; const int MX = 80; int n, k; array<int, 3> m[MX]; long long dp[MX][MX]; int dpb[MX][MX]; void solve() { cin >> n >> k; for (int i = (0); i < (n); ++i) { cin >> m[i][1] >> m[i][0]; m[i][2] = i + 1; } sort(m, m + n); for (int i = (0); i < (n + 1); ++i) { ...
#include <bits/stdc++.h> using namespace std; const int MX = 80; const long long inf = 1e15; struct info { long long a, b, indx; bool operator<(const info& s) const { return b < s.b; } }; long long n, c; info ara[MX]; vector<long long> add, rem; long long dp[MX][MX], choose[MX][MX]; long long func(long long pos, lo...
#include <bits/stdc++.h> using namespace std; constexpr static int MAXN = 80; int n, k; int a[MAXN], b[MAXN]; int dp[MAXN][MAXN]; bool added[MAXN][MAXN]; bool used[MAXN]; void solve() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i] >> b[i]; vector<pair<int, int>> bval(n); for (int i = 0; i < n; i++) bv...
#include <bits/stdc++.h> using namespace std; const int MAX = 80; int f[MAX][MAX]; bool take[MAX][MAX]; void run_case() { for (int i = 0; i < MAX; i++) { for (int j = 0; j < MAX; j++) { f[i][j] = -1000000000; take[i][j] = false; } } int n, k; cin >> n >> k; struct item { int first, sec...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; struct Edge { int to, val, next, cost; } edge[25086]; int s, t; int cnt = -1; int head[25086]; queue<int> q; int d[25086]; int cur[25086]; int inq[25086]; int vis[25086]; int costsum; void addEdge(int u, int v, int w, int f) { cnt++; edge[c...
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") using namespace std; template <typename T> void DBG(const char* name, T&& H) { cerr << name << " = " << H << ')' << '\n'; } template <typename T, typename... Args> void DBG(const char* names, T&...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 1e8; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int tcase; cin >> tcase; while (tcase--) { int n, k; cin >> n >> k; vector<int> a(n + 1), b(n + 1), id(n + 1); for (int i = 1; i <= n; i++) cin >> a[i] >> b[i...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long INF = (long long)1000000007 * 1000000007; const long double eps = 1e-8; const long double pi = acos(-1.0); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; template <class T> bool chmax(T &a, const T &b) { if (a < b) ...
#include <bits/stdc++.h> using namespace std; struct ANS { long long sss, i; ANS *to; } dp[80][80]; ANS max_get(ANS a, ANS b, ANS *aa, ANS *bb, long long i) { ANS s; if (a.sss > b.sss) { s.sss = a.sss; s.i = 0; s.to = aa; } else { s.sss = b.sss; s.i = i; s.to = bb; } return s; } st...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; template <typename first, typename second> ostream& operator<<(ostream& os, const pair<first, second>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template...
#include <bits/stdc++.h> using namespace std; const int N = (1e2) + 10; const int M = (1e5) + 10; const int INF = (1e9) + 10; const int maxn = 5e6 + 100; int dp[N][N]; int p[N][N]; struct trr { int first; int second; int poz; }; bool comp(trr a, trr b) { return a.first < b.first; } void solve() { int n, k; ci...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { re...
#include <bits/stdc++.h> using namespace std; const long long NMAX = 200001; const long long INF = (1 << 30); const long long MOD = 1000000007; const long long BLOCK = 101; const long long nr_of_bits = 18; int dp[76][76]; struct ura { ; int first, second, third; } v[76]; bool cmp(ura a, ura b) { return a.second < b...
#include <bits/stdc++.h> using namespace std; struct Edge { long long to, dis, next, cost; } edge[240050]; long long num = -1; bool vis[100010]; long long mincost; long long pre[100010], head[100010], cost[100010], last[100010], flow[100010], n, k, a[110], b[110], s, t, maxflow; long long to[110]; void add(long l...
#include <bits/stdc++.h> const int N = 77; int e, n, k, a[N], b[N], id[N], s[N], p[N][N], f[N][N]; int cmp(int x, int y) { return b[x] < b[y]; } int main() { for (scanf("%d", &e); e; e--) { memset(f, -1, sizeof f); memset(p, 0, sizeof p); memset(s, 0, sizeof s); scanf("%d%d", &n, &k); f[0][0] = 0;...
#include <bits/stdc++.h> using namespace std; const int Maxn = 88; struct node { int a, b, id; } g[Maxn]; int f[Maxn][Maxn], s[Maxn]; bool flag[Maxn][Maxn], vis[Maxn]; int a[Maxn], b[Maxn], id[Maxn]; int n, m, cnt; inline bool cmp(node x, node y) { return x.b < y.b; } void init() { for (int i = 1; i <= n; ++i) ...
#include <bits/stdc++.h> using namespace std; struct flow { static const int N = 200005, INF = 1e9; int n, s, t; struct edge { int v, w, f, c, nxt; } e[N]; int head[N], cur[N], cnt; void addedge(int u, int v, int w, int f, int c) { cnt++; e[cnt].v = v, e[cnt].w = w, e[cnt].f = f, e[cnt].c = c; ...
#include <bits/stdc++.h> using namespace std; long long t, n, k; long long a[80][80], x[80], y[80]; void hungarian() { vector<long long> u(n + 1), v(n + 1), p(n + 1), way(n + 1); for (long long i = 1; i <= n; i++) { p[0] = i; long long j0 = 0; vector<long long> minv(n + 1, 1000000000000000000); vect...
#include <bits/stdc++.h> using namespace std; struct minion { int a, b, id; }; bool sortb(minion x, minion y) { return x.b < y.b; } int n, k; minion ar[100]; int dp[100][100]; void calc() { sort(ar, ar + n, sortb); for (int i = 0; i <= n; ++i) for (int j = 0; j <= k; ++j) dp[i][j] = -1e9; dp[0][0] = ar[0].b...
#include <bits/stdc++.h> using namespace std; template <typename flow_type, typename cost_type> struct min_cost_max_flow { struct edge { size_t src, dst, rev; flow_type flow, cap; cost_type cost; }; int n; vector<vector<edge>> adj; min_cost_max_flow(int n) : n(n), adj(n), potential(n), dist(n), ba...
#include <bits/stdc++.h> using namespace std; const int MX = 100, inf = 1e9; struct FlowGraph { struct Edge { int to; int flow, cap, cost; Edge *res; Edge() : to(0), flow(0), cap(0), cost(0), res(0) {} Edge(int to, int flow, int cap, int cost) : to(to), flow(flow), cap(cap), cost(cost), re...
#include <bits/stdc++.h> using namespace std; template <class T> void splitstr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } static void redirec...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> string print_iterable(T1 begin_iter, T2 end_iter, int counter) { bool done_something = false; stringstream res; res << "["; for (; begin_iter != end_iter and counter; ++begin_iter) { done_something = true; counter--; r...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { re...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; struct Edge { int to, val, next, cost; } edge[25086]; int s, t; int cnt = -1; int head[25086]; queue<int> q; int d[25086]; int cur[25086]; int inq[25086]; int vis[25086]; int costsum; void addEdge(int u, int v, int w, int f) { cnt++; edge[c...
#include <bits/stdc++.h> using namespace std; struct Edge { int from, to, capacity, cost; Edge(int from, int to, int capacity, int cost) : from(from), to(to), capacity(capacity), cost(cost){}; }; vector<vector<int>> adj, cost, capacity; const int INF = 2e9; void shortest_paths(int n, int v0, vector<int>& d, v...
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; const int mod = 1e9 + 7; const double pi = acos(-1.0); const int inf = INT_MAX; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, k; ...