solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#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]; ...
12
CPP
#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) { ...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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&...
12
CPP
#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...
12
CPP
#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) ...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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;...
12
CPP
#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) ...
12
CPP
#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; ...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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; ...
12
CPP
#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...
12
CPP
#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]; ...
12
CPP
#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--) { ...
12
CPP
#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) ...
12
CPP
#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(...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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) + (_...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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) { ...
12
CPP
#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; ...
12
CPP
#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; ...
11
CPP
import sys input=sys.stdin.readline f=lambda :list(map(int, input().strip('\n').split())) n, k=f() _11=[] _01=[] _10=[] for _ in range(n): t, a, b=f() if a and b: _11.append(t) elif a: _10.append(t) elif b: _01.append(t) _01.sort(); _10.sort(); _11.sort() for i in range(1, len(_01)): _01[i]+=_01[i-1] for i ...
11
PYTHON3
#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;...
11
CPP
#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) { ...
11
CPP
from collections import deque n, k = map(int, input().split()) onla = [] onlb = [] both = [] for i in range(n): a, b, c = map(int, input().split()) if b == 1 and c == 1: both.append(a) elif c == 1: onlb.append(a) elif b == 1: onla.append(a) if len(both) + len(onla) < k or len(bot...
11
PYTHON3
class Book: def __init__(self, time, for_alice, for_bob): self.time = time self.for_alice = bool(for_alice) self.for_bob = bool(for_bob) self.status = ('A' if self.for_alice else '') + ('B' if self.for_bob else '') def get(li, i): try: return li[i].time except Index...
11
PYTHON3
from sys import stdin input=stdin.readline def answer(): if(n3+n1 < k or n3+n2 < k):return -1 i,j=0,0 ans=0 for take in range(k): if(i >= n1 or i >= n2): ans+=common[j] j+=1 elif(j >= n3): ans+=a[i]+b[i] i+=1 else: ...
11
PYTHON3
nb_books, mins = [int(x) for x in input().split()] x, y, z = [],[],[] for i in range(nb_books): n, a, b = [int(x) for x in input().split()] if a & b:z.append(n) elif a:x.append(n) elif b:y.append(n) x.sort() y.sort() for i in range(min(len(x), len(y))) : z.append(x[i] + y[i]) answer = sum(sorted...
11
PYTHON3
n, k = map(int, input().split()) books = [] alice = [] bob = [] for _ in range(n): book = tuple(map(int, input().split())) if book[1] == book[2] == 1: books.append(book[0]) elif book[1] == 1: alice.append(book[0]) elif book[2] == 1: bob.append(book[0]) for a, b in zip(so...
11
PYTHON3
#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...
11
CPP
from sys import stdin,stdout # stdin = open("input.txt","r") # stdout = open("output.txt","w") n,k = stdin.readline().strip().split(' ') n,k = int(n),int(k) books=[] for i in range(n): t,a,b=stdin.readline().strip().split(' ') t,a,b=int(t),int(a),int(b) books.append((t,a,b)) pairs_a=[] pairs_b=[] single=[] ...
11
PYTHON3
n, k = map(int, input().split()) alice=[];bob=[];both=[] for _ in range(n): x,y,z=map(int,input().split()) if y==1 and z==1: both.append(x) elif y==1: alice.append(x) elif z==1: bob.append(x) alice.sort();bob.sort() # print(alice) for i in range(min(len(alice),len(bob))): bot...
11
PYTHON3
#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) { ...
11
CPP
def main(): n,k=list(map(int,input().split())) l=[] c1=0 c2=0 for j in range(0,n): l1=list(map(int,input().split())) if l1[1]==1: c1+=1 if l1[2]==1: c2+=1 l.append(l1) if c1<k or c2<k: print(-1) return c=0 ...
11
PYTHON3
import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush, nsmallest from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from b...
11
PYTHON3
#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 ...
11
CPP
n, k = list(map(int, input().split())) a = [] b = [] ab = [] for _ in range(0, n): t, x, y = list(map(int, input().split())) if (x == 1 and y == 1): ab.append(t) elif (x == 1): a.append(t) elif (y == 1): b.append(t) # print(a, b, ab) ab.sort(reverse=True) b.sort(reverse=True...
11
PYTHON3
import sys input = sys.stdin.readline n, k = map(int, input().split()) o, a, b = [], [], [] for i in range(n): q, w, e = map(int, input().split()) if w == e and w: o.append(q) elif w and not e: a.append(q) elif w or e: b.append(q) i = j = l = 0 d...
11
PYTHON3
n,k = list(map(int,input().split())) ca,cb=0,0 x,y,z = [],[],[] for i in range(n): t,a,b, = list(map(int,input().split())) ca+=a cb+=b if(a==1 and b==0): x.append(t) elif(a==0 and b==1): y.append(t) elif(a==1 and b==1): z.append(t) x.sort() y.sort() z.sort() if(ca<k or cb...
11
PYTHON3
#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...
11
CPP
#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; ...
11
CPP
## necessary imports import sys input = sys.stdin.readline #from math import ceil, floor, factorial; # swap_array function def swaparr(arr, a,b): temp = arr[a]; arr[a] = arr[b]; arr[b] = temp ## gcd function def gcd(a,b): if b == 0: return a return gcd(b, a % b); ## nCr function efficient...
11
PYTHON3
###################################################### ############Created by Devesh Kumar################### #############devesh1102@gmail.com#################### ##########For CodeForces(Devesh1102)################# #####################2020############################# ###############################################...
11
PYTHON3
n, k = map(int, input().split()) A, B, both = [0], [0], [0] for i in range(n): t, a, b = map(int, input().split()) if a == 1 and b == 1: both.append(t) if a == 1 and b == 0: A.append(t) if a == 0 and b == 1: B.append(t) A.sort() B.sort() both.sort() if len(A)-1 + len(both)-1 < k or len(B)-1 + len(both)-1 < k:...
11
PYTHON3
line = input().split() n,k = int(line[0]), int(line[1]) a,b,c = [],[],[] for i in range(n): line = input().split() t,ai,bi = int(line[0]), int(line[1]), int(line[2]) if (ai == 1 and bi == 1): c.append(t) elif (ai == 1): a.append(t) elif (bi == 1): b.append(t) a.sort() b.sort() c.sort() i,j,cnt = 0,0,0 an...
11
PYTHON3
n,k=map(int,input().split(" ")) db=[] a=[] b=[] for i in range(n): t,A,B= map(int, input().split(" ")) if A==B==1: db.append(t) elif A==1: a.append(t) elif B==1: b.append(t) a.sort() b.sort() for i in range(min(len(a),len(b))): db.append((a[i]+b[i])) if len(db)<k: print(...
11
PYTHON3
import os, sys from io import IOBase, BytesIO py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writa...
11
PYTHON3
n,k=map(int,input().split()) a =[] b =[] c = [] for i in range(n): m = [*map(int,input().split())] if(m[1]==1 and m[2]==1): c.append(m[0]) elif(m[1]==1): a.append(m) elif(m[2]==1): b.append(m) a.sort(key=lambda x:(x[0])) b.sort(key=lambda x:(x[0])) for...
11
PYTHON3
import sys input=sys.stdin.readline def main(): n,k=map(int,input().split()) A,B,C=[],[],[] for i in range(n): n,a,b=map(int,input().split()) if(a==1 and b==1): A.append(n) elif(a==1 and b==0): B.append(n) elif(a==0 and b==1): C.append(n) ...
11
PYTHON3
#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...
11
CPP
from collections import defaultdict as dd import sys input=sys.stdin.readline #n=int(input()) n,kk=map(int,input().split()) l=[] ans=0 for i in range(n): time,a,b=map(int,input().split()) l.append((time,a,b)) l.sort() la=[] lb=[] do=[] for i in l: time,a,b=i if(a and b): do.append(time) elif...
11
PYTHON3
#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 (...
11
CPP
import sys from collections import deque, defaultdict input = sys.stdin.buffer.readline n, k = map(int, input().split()) al, bl, cc = [], [], [] for _ in range(n): t, a, b = map(int, input().split()) if a and not b: al.append(t) elif not a and b: bl.append(t) elif a and b: cc.append(t) al.sort(); bl.so...
11
PYTHON3
n,k=map(int, input().split()) tab=[tuple(map(int,input().split())) for _ in range(n)] both=[tabi[0] for tabi in tab if tabi[1:]==(1,1)] both.sort() alice=[tabi[0] for tabi in tab if tabi[1:]==(1,0)]# tabi[1]==1 and tabi[2]==0] bob=[tabi[0] for tabi in tab if tabi[1:]==(0,1)] alice.sort() bob.sort() ab=[alice[i]+bob[i...
11
PYTHON3
n,k = [int(x) for x in input().strip().split()] vec = [] for _ in range(n): vec.append([int(x) for x in input().split()]) vec.sort() f1 = f2 = f3 = 0 minsum = 0 count = 0 min_12 = min_3 = 0 flag12 = flag3 = True while ((f3 <= n-1 or (f1 <= n-1 and f2 <= n-1)) and count < k): while f3 <= n-1: if vec[f3]...
11
PYTHON3
n,k=map(int,input().split()) l1=[] l2=[] l3=[] ac,bc=0,0 for i in range(n): t,a,b=map(int,input().split()) if(a==1 and b==1): l1.append(t) ac+=1 bc+=1 elif(a==1 and b==0): l2.append(t) ac+=1 elif(a==0 and b==1): l3.append(t) bc+=1 if(ac<k or bc<k):...
11
PYTHON3
#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...
11
CPP
from sys import stdin from collections import deque # https://codeforces.com/contest/1354/status/D mod = 10**9 + 7 import sys import random # sys.setrecursionlimit(10**6) from queue import PriorityQueue from collections import Counter as cc # def rl(): # return [int(w) for w in stdin.readline().split()] from bisect...
11
PYTHON3
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time # sys.setrecursionlimit(5*10**5) inf = 10**20 mod = 10**9 + 7 def LI(): return list(map(int, input().split())) def II(): return int(input()) def LS(): return list(input().split()) def S(): return input() def main(): n, k = LI...
11
PYTHON3
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase from bisect import bisect_left,bisect_right import threading from collections import Counter,defaultdict arr=[] def main(): for _ in range(1): n,k=map(int,input().split()) ar3=[] ar1=[] ar2=[] ...
11
PYTHON3
def binary(a,start,end,e): mid=(start+end)//2 if a[mid]==e: return mid elif a[mid]>e: end=mid-1 else: start=mid+1 if start<=end: return binary(a,start,end,e) else: return start n,k=map(int,input().split()) p=[] al=[] bo=[] for j in range(n): a,b,c=map(...
11
PYTHON3
#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, &...
11
CPP
# from bisect import bisect_left # TC = int(input()) # for tc in range(TC): N, K = map(int, input().split()) T = [] A = [] B = [] O = [] for b in range(N): v, a, b = map(int, input().split()) if a == 1 and b == 1: T.append(v) elif a == 1: A.append(v) elif b == 1: B.append(v) ...
11
PYTHON3
n, k = [int(i) for i in input().split()] doub = []; a = []; b = [] for i in range(n): ti, ai, bi = [int(i) for i in input().split()] if ai and bi: doub.append(ti) elif ai: a.append(ti) elif bi: b.append(ti) doub.sort(); a.sort(); b.sort() # print(doub, a, b, sep="\n"...
11
PYTHON3
import sys n, k = [int(e) for e in input().split(' ')] books = list() books_map = dict() for i in range(n): t, a, b = [int(e) for e in input().split(' ')] books.append((t, a, b, i)) books_map[i] = (t, a, b) books = sorted(books, key = lambda x : x[0] * (1 if x[1] == 1 else 1e7)) alice_pay_time = 0 alice...
11
PYTHON3
n,k=map(int,input().split()) l,l1,l2=[],[],[] for i in range(n): t,a,b=map(int,input().split()) if a==1 and b==1: l.append(t) if a==1 and b==0: l1.append(t) if a==0 and b==1: l2.append(t) l1.sort() l2.sort() for i in range(min(len(l1),len(l2))): l.append(l1[i]+l2[i]) l.sort()...
11
PYTHON3
import sys def swap(x, y, a): temp = a[x] a[x] = a[y] a[y] = temp return a def solve(): return None def main(): q = [] for line in sys.stdin.readlines(): q.append(line) for i in range(len(q)): q[i] = q[i].rstrip().split(' ') q[i] = [int(x) for x in q[i]] k = q[0][1] # combining the ones that we ca...
11
PYTHON3
line = input() n, m, k = [int(i) for i in line.split(' ')] books, allL, aliceL, bobL, other =list(range(1, n + 1)), [], [], [], [] ts = [[] for _ in range(n + 1)] for i in range(n): line = input() t, a, b = [int(j) for j in line.split(' ')] ts[i + 1] = [t, a, b] if a == 1 and b == 1: allL.appen...
11
PYTHON3
n,k = map(int,input().split()) a=[] b=[] c=[] d=[] for i in range(n): x,y,z = map(int,input().split()) if y==0 and z==0: d.append(x) elif y==1 and z==1: a.append(x) elif y==0 and z==1: c.append(x) else: b.append(x) b.sort() c.sort() m=min(len(b),len(c)) for i in range...
11
PYTHON3
#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...
11
CPP
# cook your dish here # input = open('file.txt').readline n , k = list(map(int , input().split())) ali = [] bob = [] both = [] ac , bc = 0 , 0 for __ in range(n): t , ai , bi = list(map(int , input().split())) if ai == bi and ai == 1: both.append(t) ac += 1 bc += 1 elif ai == 1: ali.append(t) ...
11
PYTHON3
n, k = map(int, input().split()) al=[];bob=[];both=[] for i in range(n): a,b,c= map(int, input().split()) if(b==1 and c==1): both.append(a) elif(b==1): al.append(a) elif(c==1): bob.append(a) tp=len(both) la=len(al) ob=len(bob) a=la+tp b=ob+tp if(a<k or b<k): print("-1") else:...
11
PYTHON3
#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; ...
11
CPP
#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; ...
11
CPP
s=input() s1=s.split() n=int(s1[0]) k=int(s1[1]) import heapq heap1=[] heap2=[] heap3=[] heapq.heapify(heap1) heapq.heapify(heap2) heapq.heapify(heap3) for i in range(n): s=input() s1=s.split() if int(s1[1])==0 and int(s1[2])==1: heapq.heappush(heap1,int(s1[0])) if int(s1[1])==1 and i...
11
PYTHON3
def compute(n, k, arr): add = 0 both = [] alice = [] bob = [] for i in range(n): if arr[i][1] and arr[i][2]: both.append(arr[i][0]) elif arr[i][1]: alice.append(arr[i][0]) elif arr[i][2]: bob.append(arr[i][0]) both.sort()...
11
PYTHON3
n,k = map(int,input().split()) aa=[] bb=[] l=[] for _ in range(n): t,a,b=map(int,input().split()) sum1=0 sum2=0 if a&b: l.append(t) elif a==1: aa.append(t) elif b==1: bb.append(t) bb.sort() aa.sort() nn=min(len(aa),len(bb)) for i in range(nn): l.append(bb[i]+aa[i]) if...
11
PYTHON3
#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>...
11
CPP
from sys import stdin from collections import defaultdict as dd from collections import deque as dq import itertools as it from math import sqrt, log, log2 from fractions import Fraction n, k = map(int, input().split()) alike, blike = 0, 0 zero_one, one_zero, one_one, zero_zero = [], [], [], [] for i in range(n): ...
11
PYTHON3
production = True import sys, math, collections def input(input_format = 0, multi = 0): if multi > 0: return [input(input_format) for i in range(multi)] else: next_line = sys.stdin.readline()[:-1] if input_format >= 10: use_list = False input_format = int(str(input_fo...
11
PYTHON3