text
stringlengths
49
983k
#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 N = 80; struct minion { int a, b, ind; bool operator<(const minion &other) const { return b < other.b; } } minions[N]; int n, k; int memo[N][N], vis[N][N], vid; int solve(int i, int cnt) { if (i == n) return cnt == k ? 0 : -1e9; int &ret = memo[i][cnt]; ...
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int inf = 1e9; const int N = 5005; const int mf[] = {0, 0, 1, -1}, mc[] = {1, -1, 0, 0}; const double eps = 1e-9; const double pi = acos(-1); int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { ...
#include <bits/stdc++.h> using namespace std; const pair<long long, long long> IMPOSSIBLE = make_pair(-999999999999999999, -1); class Minion { public: long long a, b; int minionId; bool operator<(const Minion& that) const { return b < that.b; } Minion(int ma, int mb, int mid) : a(ma), b(mb), minionId(mid) ...
#include <bits/stdc++.h> using namespace std; template <typename T> T &read(T &x) { x = 0; bool f = 0; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') { f = 1; } ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(...
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") using namespace std; const double PI = acos(-1.0); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long MinCostMatching(const vector<vector<long long>> &cost, vector<long long> &Lmate, vect...
#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; template <typename T> inline void read(T &x) { static char _c; static bool _f; x = 0; _f = 0; _c = getchar(); while (_c < '0' || '9' < _c) { if (_c == '-') _f = true; _c = getchar(); } while ('0' <= _c && _c <= '9') { x = (x << 1) + (x << 3) + (_...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer", "inline") #pragma GCC option("arch=native", "tune=native", "no-zero-upper") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2") using namespace std; using ll = long long; using ull = unsigned...
#include <bits/stdc++.h> using namespace std; template <typename T> void __read(T &a) { cin >> a; } template <typename T, typename... Args> void __read(T &a, Args &...args) { cin >> a; __read(args...); } constexpr long long M7 = 1000000007ll; constexpr long long M9 = 1000000009ll; constexpr long long MFFT = 99824...
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ld = long double; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; int g[80][80]; int n, k, a[80], b[80]; int job[80]; int u[80], v[80]; bool used[80]; int dist[80]; int par[80]; void hungarian() { for (int i = 1; i <= n; i++) { job[0] = i; int j0 = 0; for (int l = 0; l < 80; l++) { used[l] = 0; ...
#include <bits/stdc++.h> using namespace std; template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; int n, k, a, b; long long t; vector<long long> ve[2][2]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = (0); i < (n); i++) { cin >> t >> a >> b; ...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long INFLL = 0x3f3f3f3f3f3f3f3f; const int MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<int> alice, bobo, osdois; for (int i = 0; i < n; i++) { bool a, b;...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, res = 0; cin >> n >> k; vector<int> arrAB; vector<int> arrA; vector<int> arrB; for (int i = 0; i < n; i++) { int time, a, b; cin >> time >> a >> b; if (a == 1 && b == 1) { arrAB.push_back(time); } else if (a == 1) { ...
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; const long long maxn = 15e5 + 10; const long long inf = 1e14; long long n, m, k, t; long long cur1, cur2; long long C[maxn]; vector<long long> ANS; vector<pair<long long, long long...
#include <bits/stdc++.h> using namespace std; int solve() { int n, k; cin >> n >> k; int a, b, ans; ans = a = b = 0; priority_queue<int> x, y, z; while (n--) { int t, u, v; cin >> t >> u >> v; t *= -1; if (u && v) { z.push(t); } else if (u) { x.push(t); } else if (v) { ...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long r = 0, f = 0; char c; while (!isdigit(c = getchar())) f |= (c == '-'); while (isdigit(c)) r = (r << 1) + (r << 3) + (c ^ 48), c = getchar(); return f ? -r : r; } inline long long min(long long a, long long b) { return a < b ? a ...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; namespace BF { long long solve(int N, int M, int K, const vector<int>& T, const vector<int>& A, const vector<int>& B) { long long res = INF; for (int mask = 0, _n = (1 << N); mask < _n; ++mask) { if ((__builtin_popcount((m...
#include <bits/stdc++.h> using namespace std; class Solve { public: void updateSt(set<pair<int, int>> &st, set<pair<int, int>> &fr, int &sum, int need) { need = max(need, 0); while (true) { bool useful = false; while (st.size() > need) { sum -= st.rbegin()->first; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { int n, m, k; ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; vector<pair<int, int> > ab; vector<pair<int, int> > a; vector<pair<int, int> > b; vector<pair<int, int> > non; for (int i = 0; i < n; i++) { int t, a1, b...
#include <bits/stdc++.h> using namespace std; int mpow(int base, int exp); void ipgraph(int n, int m); void dfs(int u, int par); const int mod = 1e9 + 7; struct cmp { bool operator()(const int& lhs, const int& rhs) const { return lhs < rhs; } }; int mpow(int base, int exp) { base %= mod; int result = 1; while (...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<pair<int, pair<int, int>>> v; for (int i = 0; i < n; i++) { int t, a, b; cin >> t >> a >> b; v.push_back({t, {a, b}}); } vector<int> f; vector<pair<int, pair<int, int>>> l; vector<pair<int, pair<int, i...
#include <bits/stdc++.h> #pragma GCC optimize("02") #pragma G++ optimize("03") using namespace std; const int N = 2e5 + 5; int n, k, type1[N], type2[N], type3[N]; int main() { scanf("%d%d", &n, &k); int cnt1 = 0, cnt2 = 0, cnt3 = 0; for (int i = 1; i <= n; i++) { int val, a, b; scanf("%d%d%d", &val, &a, &...
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; struct fast_ios { fast_ios() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <typename T> istream &operator>>(istr...
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { while (b != 0) { long long c = a % b; a = b; b = c; } return a < 0 ? -a : a; } inline long long lowbit(long long x) { return x & (-x); } const double PI = 3.14159265358979323846; const int inf = 0x3f3f3f3f; ...
#include <bits/stdc++.h> using namespace std; struct books { int t, i; }; bool cmp(books a, books b) { if (a.t != b.t) return (a.t < b.t); return (a.i < b.i); } int main() { int n, m, o, x, y, i, j, t, s, k, l, p = 0, q, e[200001], f[200001]; books a[200001], b[200001], c[200001], d[200001]; long long ans; ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; long long poww(long long a, long long b, long long mod) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % mod; a = (a * a) % mod; b >>= 1; } return ans % mod; } int main() { int n, k; cin >> n >> k; vector<int>...
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const long long MAX = 1e5 + 10; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<long long> a, b, ab; ab.push_back(0); a.push_back(0); b.push_back(0); for (int i = 0; i < n; i++) { long ...
#include <bits/stdc++.h> using namespace std; const int MAX = 200005; long long INF = 1e10; vector<long long> books[3]; int type(int a, int b) { if (a && b) return 0; if (a) return 1; return 2; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k, t, x, y; cin >> n >> k; for (int i = 0; i < n; i...
#include <bits/stdc++.h> const int maxn = 2e6 + 1; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; multiset<long long int> va, vb, vall; int main() { int n, m; ...
#include <bits/stdc++.h> using namespace std; int32_t main() { long long int n, k; cin >> n >> k; vector<long long int> v1; vector<long long int> v2; vector<long long int> v; for (long long int i = 0; i < n; i++) { long long int t, a, b; cin >> t >> a >> b; if (a == 1 && b == 1) { v.push_b...
#include <bits/stdc++.h> using namespace std; const int m_x[] = {-1, 0, 0, 1}; const int m_y[] = {0, -1, 1, 0}; template <typename T, typename S> ostream& operator<<(ostream& output, const pair<T, S>& to_print) { output << to_print.first << ":" << to_print.second; return output; } template <typename T, typename S> ...
#include <bits/stdc++.h> using namespace std; long long n, k, t, a, b, boths, alices, bobs, cnt[2], ans; vector<int> both, alice, bob; int main() { ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); cin >> n >> k; for (int i = 0; i < n; i++) { cin >> t >> a >> b; if (a && b) both.push_back(...
#include <bits/stdc++.h> using namespace std; using ll = long long int; using dl = double; const int N = 2e5 + 10; ll aarray[200000 + 10]; ll magic[101][101]; vector<ll> primes; bool prime[1000001]; int main() { ios_base::sync_with_stdio(false); string str; ll c, d, e, f, x, y, k, a, b, t, A = 0, mod, B = 0, L, j...
#include <bits/stdc++.h> using namespace std; long long dif(long long a, long long b) { if (a > b) return a - b; else return b - a; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NUL...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long inf = 922337203685477; const long long mininf = -922337203685477; const long long nax = 2e5 + 5; long long n, k, t, x, y; priority_queue<long long, vector<long long>, greater<long long>> pq[5]; long long val(long long x) { if...
#include <bits/stdc++.h> using namespace std; const long long int INF = (long long int)1e18; const long long int MOD = 1000 * 1000 * 1000 + 7; const long long int maxn = (long long int)1e5 + 10, L = 23; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int T = 1; while (T--) { long ...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> first, second, z; while (n--) { long long t, a, b; cin >> t >> a >> b; if (a) if (b) first.push_back(t); els...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; const int N = 2e5 + 5; long long t[N], a[N], b[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; int cnta = 0, cntb = 0; set<pair<long long, long long> > ab, aa, bb; for (int i...
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const long long mod = 1e9 + 7; const long long linf = 1LL << 62; const double EPS = 1e-7; template <class T> void chmin(T& x, T y) { if (x > y) x = y; } template <class T> void chmax(T& x, T y) { if (x < y) x = y; } int n, k; priority_queue<long...
#include <bits/stdc++.h> using namespace std; int month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; string lowerCase = "abcdefghijklmnopqrstuvwxyz"; string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int fx8[] = {+1, +1, +0, -1, -1, -1, +0, +1}; const int fy8[] = {+0, +1, +1, +1, +0, -1, -1, -1}; const in...
#include <bits/stdc++.h> using namespace std; vector<int> both, alice, bob; int both_size = 0, alice_size = 0, bob_size = 0; int main(int argc, char const *argv[]) { cin.sync_with_stdio(false); int N, k; cin >> N >> k; int min_, a, b; for (int i = 0; i < N; i++) { cin >> min_ >> a >> b; if (a == 1 and...
#include <bits/stdc++.h> using namespace std; void scan() {} template <class T, class... A> void scan(T& t, A&... a) { cin >> t, scan(a...); } void print() {} template <class T, class... A> void print(T t, A... a) { cout << t, print(a...); } const int MV = 2e5; int n, m, k, ans = INT_MAX, idx, posTake, posRem; vect...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; long long i, j; vector<long long> a, b, c; for (i = 1; i <= n; i++) { long long x, y, z; cin >> x >> y >> z; if (y == 1 && z == 1) { c.push_back(x); } else if (y == 1) { a.push_back(x); ...
#include <bits/stdc++.h> using namespace std; using lint = long long int; struct fast_io { fast_io() { cout << fixed << setprecision(20); ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); } } _fast_io; void run_case() { int n, k; cin >> n >> k; int ret = INT_MAX; vector<int>...
#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 T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> cnt(5, 0), mark(4, 0), as; vector<pair<long long, long long> > v[4]; long long ret = 1e18, ans = 0; for (int i = 0; i < n;...
#include <bits/stdc++.h> using namespace std; void takeFrom(vector<long long> &x, long long &cnt, long long &ans) { ans += x.back(); x.pop_back(); cnt++; } void takeFrom(vector<long long> &x, long long &cntA, long long &cntB, long long &ans) { ans += x.back(); x.pop_back(); cntA++; cntB++; }...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> v0, v1, v2; for (int i = 0; i < n; i += 1) { int x, y, z; cin >> x >> y >> z; if (y == 1 && z == 1) v0.push_back(x); else if (y != 1 && z == 1) ...
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long N = 2e5 + 5; long long n, m, k; vector<pair<long long, long long>> type[2][2]; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for (long long i = 1; i <= n; ++i) { long long a...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; scanf("%d%d%d", &n, &m, &k); vector<pair<int, int>> a, b, c, z; a.reserve(n); b.reserve(n); c.reserve(n); z.reserve(n); for (int i = 0; i < n; ++i) { int t, xa, xb; scanf("%d%d%d", &t, &xa, &xb); if (xa == 1 && xb == 1) ...
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int64_t n, k, ac = 0, bc = 0; cin >> n >> k; vector<int64_t> main; vector<int64_t> a_array; vector<int64_t> b_array; while (n--) { int64_t t, a, b; cin >> t >> a >> b; if (a == 1) ...
#include <bits/stdc++.h> using namespace std; void solution() { int n, k; cin >> n >> k; vector<int> zero, one, two; for (int i = 0; i < n; i++) { int t1, t2, t3; cin >> t1 >> t2 >> t3; if (t2 == 0 && t3 == 1) { one.push_back(t1); } else if (t2 == 1 && t3 == 0) { zero.push_back(t1); ...
#include <bits/stdc++.h> using namespace std; using Int = int64_t; vector<Int> csum(vector<Int>& v) { vector<Int> r(v.size()); copy(v.begin(), v.end(), r.begin()); for (int i = 1; i < r.size(); ++i) r[i] += r[i - 1]; return r; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nul...
#include <bits/stdc++.h> using namespace std; int n, m, k; struct Node { int id, t, a, b; bool friend operator<(Node a, Node b) { return a.t < b.t; } }; vector<Node> v[5]; int sz[5]; int pos[5], anspos[5]; int ans; int main() { cin >> n >> m >> k; for (int i = 1; i <= n; i++) { int t, a, b; cin >> t >> ...
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } void solve() { int n, k; cin >> n >> k; vector<int> a, b, c; for ...
#include <bits/stdc++.h> using namespace std; const int M = 1e2 + 100; const int N = 2e3 + 100; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; long long n, m, t, k, x, y; vector<long long> ab, bb, abb; void slove() { scanf("%lld%lld", &n, &k); ab.clear(), bb.clear(), abb.clear(); for (int i = 0; i < n; i++)...
#include <bits/stdc++.h> using namespace std; int t[200005], a[200005], b[200005]; pair<int, int> aa[200005], bb[200005], ab[200005]; int sumaa[200005], sumbb[200005], sumab[200005]; int BITcnt[10005], BITsum[10005]; int anss[200005], ccc; vector<int> v[10005]; bool f[200005]; int lowbit(int x) { return x & (-x); } voi...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long mod2 = 998244353; const long long INF = 1000000001; const long long N = 100001; const long double PI = 3.141593; long double powm(long long base, long long exp) { long long ans = 1; while (exp) { if (exp & 1) ans = (ans...
#include <bits/stdc++.h> using namespace std; const long long MAX = 3e5; long long fen[MAX], cnt[MAX], sum[MAX]; deque<pair<long long, long long> > a, b, s, d, v; multiset<pair<long long, long long> > sol; void add(long long t, long long cur, long long val) { if (cur > 2e4) return; if (t == cur) cnt[t] += val; if...
#include <bits/stdc++.h> using namespace std; namespace IO { const int BUFFER_SIZE = 1 << 15; char input_buffer[BUFFER_SIZE]; size_t input_pos = 0, input_len = 0; char output_buffer[BUFFER_SIZE]; int output_pos = 0; char number_buffer[100]; uint8_t lookup[100]; void _update_input_buffer() { input_len = fread(input_bu...
#include <bits/stdc++.h> using namespace std; int lim[4]; vector<pair<int, int> > t[4]; int get() { vector<pair<int, int> > tmp; for (int i = 0; i <= 2; i++) { if (lim[i] != t[i].size()) { tmp.push_back({t[i][lim[i]].first, i}); } } if (tmp.empty()) return 0; sort(tmp.begin(), tmp.end()); lim[...
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long long INF = 1e11; vector<long long...
#include <bits/stdc++.h> using namespace std; int const MAXN = 2e5 + 10; int n, m, T, k; vector<pair<int, int>> a, b, ab, other; vector<int> ans; int check(int mid) { if ((int)a.size() < k - mid) return 2e9 + 1; if ((int)b.size() < k - mid) return 2e9 + 1; if (mid + max(0, k - mid) * 2 > m) return 2e9 + 1; int ...
#include <bits/stdc++.h> using namespace std; long long n, k, t, a, b, it1, it2, score, tim, f, s; vector<long long> vec[4]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> t >> a >> b; if (a == 1) f++; if (b == 1) s++; if (a == 0 && b == 0) continue; if (a == 1 && b == 1) { ...
#include <bits/stdc++.h> using namespace std; const int INF = 2147483640; const int MAXN = 2e5 + 5; const int R = 1e4 + 5; int n, m, k; int tot[10]; struct node { int t, i; } A[MAXN], B[MAXN], C[MAXN], D[MAXN], E[MAXN << 2]; bool cmp(node x, node y) { return x.t < y.t; } struct tree { int sum, w; } tr[R << 2]; void...
#include <bits/stdc++.h> using namespace std; template <typename T> void print1d(vector<T> &a) { for (long long int i = 0; i < a.size(); i++) { cout << a[i] << " "; } cout << endl; } vector<long long int> divisor(long long int n) { vector<long long int> a; for (long long int i = 1; i * i <= n; i++) { ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, k; struct Book { int t, a, b; bool operator<(const Book &w) const { return t < w.t; } } books[N]; vector<int> a, b; bool st[N]; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> books[i].t >> books[i].a >> books[i].b...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m; cin >> n >> m; vector<long long int> aa, bb, cc; vector<long long int> a(n + 5); vector<long long int> b(n + 5); vector<long long int> c(n + 5); for (long long int i = 1; i <= n; i++) { cin >> a[i] >> b[i] >> c[i]; if (...
#include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; } template <typename ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } void print(vector<long long> a) { for (int i = 0; i < a.size(); i++) { cout << a[i] << ' '; } cout <...
#include <bits/stdc++.h> using namespace std; void test_case() { long long int n, k; cin >> n >> k; vector<long long int> as, bs, cs; for (long long int i = 0; i < n; i++) { long long int t, a, b; cin >> t >> a >> b; if (a + b == 2) cs.push_back(t); else if (a == 1) as.push_back(t); ...
#include <bits/stdc++.h> using namespace std; long long inf = 1e9; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; vector<long long> l; vector<long long> m; vector<long long> r; for (long long i = 0; i < n; ++i) { long long a, b, c; cin >> a >> b >...
#include <bits/stdc++.h> using namespace std; long long mod = 1000000007; long long dx[] = {1, -1, 0, 0}; long long dy[] = {0, 0, 1, -1}; void solve() { long long n, k; cin >> n >> k; vector<long long> arr1, arr2, v; for (long long i = 0; i < n; i++) { long long x, a, b; cin >> x >> a >> b; if (a &&...
#include <bits/stdc++.h> using namespace std; const int MAX_INT = numeric_limits<int>::max(); const int MAX_UINT = numeric_limits<unsigned int>::max(); void get_acum(const vector<int>& v, vector<int>& acum) { int sum = 0; for (unsigned int i = 0; i < v.size(); ++i) { acum.push_back(sum); sum += v[i]; } ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); vector<int> va; vector<int> vb; vector<int> vab; int n, k, a, b, t; cin >> n >> k; for (int p = 0; p < n; p++) { cin >> t >> a >> b; if (a == 1 && b == 1) vab.push_back(t); else ...
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &r) { static char c; r = 0; for (c = getchar(); c > '9' || c < '0'; c = getchar()) ; for (; c >= '0' && c <= '9'; r = (r << 1) + (r << 3) + (c ^ 48), c = getchar()) ; } const int maxn = 2e5 + 100; int n, m, k; struct ...
#include <bits/stdc++.h> using namespace std; const long long N = 1e9 + 5; bool col2(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.first == p2.first) return p2.second < p1.second; else return p1.first < p2.first; } struct comp { bool operator()(long long const &x, long long const ...
#include <bits/stdc++.h> using namespace std; int n, k, ans; multiset<int> alice, bob, both; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { int t, a, b; cin >> t >> a >> b; if (a + b == 2) both.insert(t); else if (a) alice.insert(t); else if (b) bob.insert(t); } ...
#include <bits/stdc++.h> using namespace std; using pi = pair<long long, long long>; const long long inf = (long long)2e9 + 5; signed main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m, k; cin >> n >> m >> k; vector<pi> w[2][2]; for (long long i = 0; i < n; i++) { long long t, a, b; ci...
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long t, n, m, k, q, a, b, x, y, ans, arr[N]; long long mod = 998244353; string s; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); ; t = 1; while (t--) { cin >> n >> k; ans = 0, x = 0, y = 0; priority_queue<i...
#include <bits/stdc++.h> using namespace std; vector<long long int> v, a1, b1; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k; cin >> n >> k; pair<long long int, pair<long long int, long long int> > p[n]; for (long long int i = 0; i < n; i++) { long lo...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k; cin >> n >> k; vector<long long> v1, v2; vector<long long> v; for (long long i = 0; i < n; i++) { long long t1, a, b; cin >> t1 >> a >> b; if (a == 1) { if (b == 1) v.push_back(t1); else v1.pus...
#include <bits/stdc++.h> using namespace std; bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) { return a.first < b.first; } int main() { int n, k; cin >> n >> k; vector<pair<int, pair<int, int> > > book; for (int i = 0; i < n; i++) { pair<int, pair<int, int> > temp; cin >> temp.f...
#include <bits/stdc++.h> using namespace std; long long n, m, d, nn = 0, ttl = 0, fq[4], sm = 0, dd, sq[200069], zs = 0, inf = 1e18; pair<long long, long long> a[4][200069]; multiset<pair<long long, long long>> ms[2]; multiset<pair<long long, long long>>::iterator it; void blc() { for (; nn < dd &&...
#include <bits/stdc++.h> const int INF = 2e9 + 1; int main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); int n, k; std::cin >> n >> k; std::vector<int> t(n), a(n), b(n); std::vector<int> v[2][2]; for (int i = 0; i < n; i++) { std::cin >> t[i] >> a[i] >> b[i]; v[a[i]][b[i]].push_back(t[...
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, MAXN = 2e6 + 50; const long long LINF = 2e9 + 1000, MOD = 998244353; const double Pi = acos(-1), EPS = 1e-6; void test() { cerr << "\n"; } template <typename T, typename... Args> void test(T x, Args... args) { cerr << x << " "; test(args...);...
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const double PI = acos(-1.0); void __print(long long x) { cerr << x; } void __print(int32_t x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x ...
#include <bits/stdc++.h> using namespace std; static bool comp(long long int a, long long int b) { return (a > b); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; vector<long long int> A, B, BB; for (long long int i = 0; i < n; i++) { long long int ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; long long a[N], a1 = 0, b[N], b1 = 0, c[N], c1 = 0, d, dis; char o; pair<int, int> p; bool mark = true; int main() { ios::sync_with_stdio(false); cin.tie(0); long long t, n, m, mx, k, ans = 0, sum = 0, x, y, l, r; stri...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t, a, b, sum = 0, cnt = 0; vector<int> A, B, C; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> t >> a >> b; if (a != b) { if (a == 1) { A.push_back(t); } else { B.push_back(t); } } else { ...
#include <bits/stdc++.h> using namespace std; using Int = int64_t; vector<Int> csum(vector<Int> v) { vector<Int> r; r = v; for (int i = 1; i < r.size(); ++i) r[i] += r[i - 1]; return r; } int main() { Int N, K; cin >> N >> K; vector<Int> v, u, cmn; while (N--) { Int a, b, c; cin >> c >> a >> b; ...
#include <bits/stdc++.h> using namespace std; long long int solve() { long long int n, k; cin >> n >> k; vector<long long int> first, second, both; int av = 0, bv = 0; while (n--) { long long int t, a, b; cin >> t >> a >> b; if (a && b) both.push_back(t), av++, bv++; else if (a) fi...
#include <bits/stdc++.h> using namespace std; struct edge { long long int t; long long int a; long long int b; }; vector<edge> grp1; vector<edge> grp2; vector<edge> grp3; bool cmp(edge A, edge B) { return A.t < B.t; } int main() { edge get; long long int n, k, i, j, temp, aa, bb, tt, cnt1, cnt2, len1, len2, l...
#include <bits/stdc++.h> using namespace std; #pragma GCC target("sse4.2") int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, k; cin >> n >> k; vector<long long int> v[4]; vector<long long int> pref[4]; for (long long int i = 0; i < (long long int)n; i++) { long long int t,...
#include <bits/stdc++.h> using namespace std; int main() { long long n, K; cin >> n >> K; long long a, b, c; long long x[n], x2[n], x3[n]; long long k = 0, k2 = 0, k3 = 0, ans = 0; for (long long i = 0; i < n; i++) { cin >> a >> b >> c; if (b == c && b == 1) { x[k] = a; k++; } else i...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k, ans = 1e10; cin >> n >> k; vector<long long> alice, bob, both, prb, pra, prboth; for (long long i = 1; i <= n; i++) { long long t, a, b; cin >> t >> a >> b; if (a && b) both.push_back(t); else if (a) alice.p...
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; while (cin >> n >> k) { vector<int> both, alice, bob; for (int i = 0; i < n; ++i) { int t, a, b; cin >> t >> a >> b; if (a && b) both.push_bac...
#include <bits/stdc++.h> using namespace std; int A[1000000], B[1000000], C[1000000]; int main() { int n, k, t, a, b; cin >> n >> k; int num1 = 0, num2 = 0, num3 = 0; for (int i = 1; i <= n; i++) { cin >> t >> a >> b; if (a == 1 && b != 1) A[++num1] = t; if (a == 0 && b == 1) B[++num2] = t; if (...