solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
n,k=map(int,input().split()) t=[] a=[] b=[] an=k bn=k for i in range(n): t1,a1,b1=map(int,input().split()) t.append(t1) a.append(a1) b.append(b1) both_like=[] a_like=[] b_like=[] for i in range(n): if(a[i]==1 and b[i]==1): both_like.append(t[i]) elif(a[i]==1 and b[i]==0): a_like....
11
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename T = int> struct Fenwick { int n; vector<T> v; Fenwick(int size = 100005) : n(size), v(n + 1, 0) {} inline void add(int p, T val) { for (; p <= n; p += (p & -p)) { v[p] += val; } } inline T query(int p) { T tmp = 0; for (;...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long mxn = 100010; void solve(long long tc) { long long n, k, x, y, z; cin >> n >> k; deque<long long> d00, d01, d10, d11; for (long long i = 0; i < n; i++) { cin >> x >> y >> z; if (y == 0 && z == 0) d00.push_back(x); else if (y == 0 &&...
11
CPP
#include <bits/stdc++.h> const long long INF = 1000000000000000001; using namespace std; mt19937 random1(179); struct Node { Node* l; Node* r; long long x, y, sum1, num, len; Node(long long x1) : x(x1), y(random1()), l(nullptr), r(nullptr), sum1(x1), num(1), len(1) {} }; void update(Node* tree) { if (tr...
11
CPP
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element) #from bisect import bisect_right as br #c++ upperbound br(array,element) #from __future__ import print_function, division #while using python2 def modinv(n,p): return pow(n,p-2,p) def main(): #sys.stdin = ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") const long long MOD = 1e9 + 7; long long n_bits(long long n) { long long x = __builtin_popcount(n); return x; } int pow(int a, int b, int m) { int ans = 1; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; ...
11
CPP
#include <bits/stdc++.h> using namespace std; double const EPS = 1e-8, PI = acos(-1); const int N = 2e5 + 9, M = 30 + 7, OO = (int)1e6 + 1, MAXN = 4 * N; const long long MOD = 1e9 + 7, INF = 1e18 + 9; void INPUT() {} bool cmp(pair<int, pair<bool, bool>> a, pair<int, pair<bool, bool>> b) { if (a.first == b.first) { ...
11
CPP
n,k=map(int,input().split()) a=[] # 1 1 b=[] #0 1 c=[] # 1 0 for i in range(n): t,x,y=map(int,input().split()) if x: if y: a.append(t) else: c.append(t) else: if y:b.append(t) if len(a)+len(b) <k or len(a)+len(c)<k:print(-1) else: mn=10**10 a=sorted(a)...
11
PYTHON3
import sys, os from io import BytesIO, IOBase from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log from collections import defaultdict as dd, deque from heapq import merge, heapify, heappop, heappush, nsmallest from bisect import bisect_left as bl, bisect_right as br, bisect # region fastio BUFSIZE = 819...
11
PYTHON3
n,m,k = map(int,input().split()) ab = [] a = [] b = [] other = [] l = [list(map(int,input().split())) for i in range(n)] for i in range(n): t,c,d = l[i] if c and d == 0: a.append([t,i+1]) elif d and c == 0: b.append([t,i+1]) elif c*d: ab.append([t,i+1]) else: other.ap...
11
PYTHON3
from sys import stdin n,k = map(int,stdin.readline().split()) ba,bb,bc = [],[],[] for _ in range(n): t,a,b = map(int, stdin.readline().split()) if a and b: bc.append(t) elif a: ba.append(t) elif b: bb.append(t) ba.sort() bb.sort() bc.sort() a,b,c = 0,0,0 T = 0 while k: if ...
11
PYTHON3
import sys, math,os from io import BytesIO, IOBase #data = BytesIO(os.read(0,os.fstat(0).st_size)).readline # from bisect import bisect_left as bl, bisect_right as br, insort # from heapq import heapify, heappush, heappop from collections import defaultdict as dd, deque, Counter # from itertools import permutations,com...
11
PYTHON3
n, k = map(int, input().split()) ab, a, b = [], [], [] for _ in range(n): t, aa, bb = map(int, input().split()) if aa and bb:ab.append(t) elif aa:a.append(t) elif bb:b.append(t) a.sort() b.sort() zz = min(len(a), len(b)) for i in range(zz):ab.append(a[i]+b[i]) print(-1 if len(ab)<k else sum(sorted(ab)[:...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << "\n"; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(nam...
11
CPP
n, k = map(int, input().split()) a = [] b = [] ab = [] for i in range(n): t, a1, b1 = map(int, input().split()) if a1 == 1 and b1 == 1: ab.append(t) elif a1 == 1 and b1 == 0: a.append(t) elif a1 == 0 and b1 == 1: b.append(t) a.sort() a_i = 0 b.sort() ab.sort() ab_i = 0 sum_t = 0 ...
11
PYTHON3
def p(x): return x[0] n, k = map(int, input().split()) a = [] for i in range(n): a.append(list(map(int, input().split()))) a.sort(key=p) # print() # print() # for i in a: # print(i) alice, bob, common = [], [], [] al, bo = 0, 0 flag = 1 for i in a: if(i[1] and not i[2] and flag and al < k): al...
11
PYTHON3
lis = input().split() n,k = int(lis[0]),int(lis[1]) like1 = [] like2 = [] likeall = [] for i in range(n): lis = input().split() tval,l1,l2 = int(lis[0]),int(lis[1]),int(lis[2]) if(l1==1 and l2==1): likeall.append(tval) elif(l1==1): like1.append(tval) elif(l2==1): like2.append(tval) like1.sort() like2.sort() ...
11
PYTHON3
l=list(map(int,input().split())) n,y=l[0],l[1] fir=[] sec=[] bot=[] for _ in range(n): k=list(map(int,input().split())) if(k[1]==1 and k[2]==1): bot.append(k[0]) elif(k[1]==1 and k[2]==0): fir.append(k[0]) elif(k[1]==0 and k[2]==1): sec.append(k[0]) f=len(fir) s=len(sec) b=len(bo...
11
PYTHON3
from sys import stdin, stdout import math,sys from itertools import permutations, combinations from collections import defaultdict,deque,OrderedDict from os import path import bisect as bi import heapq def yes():print('YES') def no():print('NO') if (path.exists('input.txt')): #------------------Sublime-----------...
11
PYTHON3
import sys input = sys.stdin.readline INF = 10 ** 18 n, m, k = map(int, input().split()) B = [tuple(map(int, input().split())) for _ in range(n)] GB = [] AB = [] BB = [] RB = [] for i, (t, a, b) in enumerate(B): if a and b: GB.append((t, i)) elif a: AB.append((t, i)) elif b: BB.append((t, i)) else: RB.ap...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 1e5 + 5e4 + 2; const int inf = 2e9; const long long linf = 4e18; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cerr.tie(0); int n, k; cin >> n >> k; vector<int> alice, bob, common; for (int ...
11
CPP
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, k; cin >> n >> k; vector<long long int> a, b, c, d; a.emplace_back(0), b.emplace_back(0), c.emplace_back(0); for (int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; if (y + z == 2) { a.emplace_back(x); }...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; void solve() {} int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> times[4]; vector<long long> sums[4]; for (long long i = 0; i < n; ++i) { long long t, a, b; ...
11
CPP
#include <bits/stdc++.h> using namespace std; void fast() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { long long int n, i, j, w, x, y, k, cv1 = 0, cv2 = 0, cv3 = 0, c = 0, ans = 0; cin >> n >> k; vector<long long int> v2, v1, v3; for (i = 0; i < n; i++) { cin >> w >> x >> y;...
11
CPP
n,k = [int(i) for i in input().split()] a=[] b=[] t=[] for i in range (n): ti,ai,bi=[int(i) for i in input().split()] t.append([ti,i]) a.append(ai) b.append(bi) temp = 0 if a.count(1)<k or b.count(1)<k: temp = 1 print(-1) if temp == 0: alice=[] bob=[] both = [] for i in range (n)...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; using vl = vector<long long>; using vs = vector<string>; using vvl = vector<vector<long long>>; const long long INF = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, c...
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<int> a, b, ab; for (int i = 1; i <= n; ++i) { int x, l, r; cin >> x >> l >> r; if (l == 1 and r == 0) { a.push_back(x); } else if (l == 0 and r == 1) { ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } priority_queue<i...
11
CPP
n ,k = map(int, input().split(" ")) arr_both = [] arr_alice = [] arr_bob = [] for i in range(n): t1 ,t2, t3 = map(int, input().split(" ")) if(t2==0 and t3==0): continue elif(t2==1 and t3==1): arr_both.append(t1) elif(t2==1): arr_alice.append(t1) else: arr_bob.append(t1) i = 0 j = 0 arr_alice.sort() arr...
11
PYTHON3
from sys import stdin,stdout,setrecursionlimit # n = int(stdin.readline()) n,k = map(int,stdin.readline().split()) a = [] b = [] ab = [] for _ in range(n): x,y,z = map(int,stdin.readline().split()) if y == 1 and z == 1: ab.append(x) if y == 1 and z == 0: a.append(x) if y == 0 and z ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n, k; vector<int64_t> a; vector<int64_t> b; vector<int64_t> c; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { int64_t _t; bool _a, _b; cin >> _t >> _a >> ...
11
CPP
import sys from collections import Counter as CO input=sys.stdin.readline from collections import defaultdict as dd n,k=map(int,input().split()) arr=[] brr=[] both=[] for _ in range(n): t,a,b=map(int,input().split()) if(a==1 and b==1): both+=[t] elif(a==1): arr+=[t] elif(b==1): b...
11
PYTHON3
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::string; void __Check(bool condition, const char* expression, int line) { if (!condition) { fprintf(stderr, "Check failed at line %d: %s\n", line, expression); exit(-1); } } template <class Collection, class Key> bool Conta...
11
CPP
n,k=[int(j) for j in input().split()] al=bo=0 both=[] sial=[] sibob=[] for i in range(n): tim,alice,bob=[int(j) for j in input().split()] if(alice==1 and bob==1): both.append(tim); al+=1 bo+=1 elif(alice ==1): sial.append(tim) al+=1 elif(bob == 1): sibob.a...
11
PYTHON3
#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, m, k; vector<pair<long...
11
CPP
t=1 while t>0 : n,k=map(int,input().split()) a=[] b=[] c=[] ans=0 for i in range(n) : ti,al,bo=map(int,input().split()) if al==1 and bo==1 : c.append(ti) elif al==1 : a.append(ti) elif bo==1 : b.append(ti) a.sort() b.sor...
11
PYTHON3
import sys input=sys.stdin.readline from collections import defaultdict n,k=map(int,input().split()) c1,c2=k,k both,al,bob=[],[],[] co1,co2=0,0 for i in range(n): t,a,b=map(int,input().split()) if a==1 and b==1: both.append(t) co1+=1 co2+=1 elif a==1: al.append(t) ...
11
PYTHON3
import sys from collections import defaultdict as dd from collections import deque from fractions import Fraction as f from copy import * from bisect import * from heapq import * from math import * from itertools import permutations def eprint(*args): print(*args, file=sys.stderr) zz=1 #sys.setrecursionlimit(...
11
PYTHON3
#include <bits/stdc++.h> #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using std::cin; using std::cout; using std::lower_bound; using std::string; using std::upper_bound; using std::vector; using vi...
11
CPP
import sys tokens = input().split() n, nb_required = int(tokens[0]), int(tokens[1]) both_liked = [] alice_liked = [] bob_liked = [] for i in range(n): tokens = input().split() t, a, b = int(tokens[0]), int(tokens[1]), int(tokens[2]) if a == 1 and b == 1: both_liked.append(t) elif a == 1: ...
11
PYTHON3
#!/usr/bin/pypy3 n, k = map(int, input().split()) x, y, z = [], [], [] for _ in range(n): t, a, b = map(int, input().split()) if a & b: z.append(t) elif a: x.append(t) elif b: y.append(t) x.sort() y.sort() for i in range(min(len(x), len(y))): z.append(x[i] + y[i]) z.sort() ...
11
PYTHON3
n, k = map(int, input().split()) aa = [] bb = [] oo = [] for i in range(n): t, a, b = map(int, input().split()) if (a==1): if (b==1): oo.append(t) else: aa.append(t) else: if (b==1): bb.append(t) if (len(aa) + len(oo) < k) or (len(oo) + len(bb) < k...
11
PYTHON3
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writa...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10; const long long inf = 1e9; struct node { long long num, tim; } A[N], B[N], C[N], D[N]; bool cmp(node l1, node l2) { return l1.tim < l2.tim; } signed main() { ios::sync_with_stdio(false); cin.tie(0); long long n, m, k, x, y, z, a = 0, b ...
11
CPP
from heapq import * l=[] n,k=map(int,input().split()); a,b,c=[],[],[] for i in range(n): l.append(list(map(int,input().split()))) l.sort() for i in range(n): la,lb=len(a)+len(c),len(b)+len(c) if((l[i][1]==1 or l[i][2]==1) and (la<k or lb<k)): if(l[i][1]==1 and l[i][2]==0 and la<k): heappush(a,-l[i][0]) el...
11
PYTHON3
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.wr...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x, xa, xb, aa = 0, bb = 0, cc; vector<int> a, b, c; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> x >> xa >> xb; aa += xa; bb += xb; if (xa & xb) c.push_back(x); else if (xa) a.push_back(x); else if (x...
11
CPP
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { int n, k; scanf("%d%d", &n, &k); priority_queue<int, vector<int>, greater<int> > books, a, b; for (int i = 0; i < n; i++) { int ti, x, y; scanf("%d%d%d", &ti, &x, &y); if (x && y) books.push(ti); else if (x) ...
11
CPP
n,k=map(int,input().split()) a,b,tog=[],[],[] for i in range(n): t,x,y=map(int,input().split()) if x==1 and y==1: tog.append(t) elif x==1 and y==0: a.append(t) elif x==0 and y==1: b.append(t) ltog=len(tog) la=len(a) lb=len(b) if ltog+la<k or ltog+lb<k: print(-1) else: a.sort(reverse=True) b.sort(reverse=...
11
PYTHON3
N, K = [int(i) for i in input().split()] T, A, B = [], [], [] Tall = [] Talice = [] Tbob = [] for i in range(N): t, a, b = [int(j) for j in input().split()] T.append(t) A.append(a) B.append(b) if a and b: Tall.append(t) elif a: Talice.append(t) elif b: Tbob.append(t...
11
PYTHON3
n, k = map(int, input().split()) a = [] b = [] ab = [] for i in range(n): x, y, z = map(int, input().split()) if y == 1 and z == 1: ab.append(x) elif y == 1: a.append(x) elif z == 1: b.append(x) a = sorted(a) b = sorted(b) #ab = sorted(ab) for i in range(min(len(a), len(b))): ab.append(a[i] + b[i]) ab = sort...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int t[200005], a[200005], b[200005]; long long sum1[200005], sum2[200005], sum3[200005], sum4[200005]; int val[200005]; int pos[200005]; vector<pair<int, int> > v1, v2, v3, v4, v5; struct tree { long long ft[200005]; void update(int i, int v) { for (; i <= 200000; i...
11
CPP
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long inf_ll = 1e18; vector<pair<long long, int>> t[4]; array<long long, 3> eval(int x, int y) { int l = max(-(int)(t[2].size() - 1 - x - y), 0), r = min((int)t[1].size() - 1 - x, y); while (l < r - 2) { int mid = (l + r) / 2; ...
11
CPP
# -*- coding: utf-8 -*- """ Created on Thu Jul 9 09:18:37 2020 @author: Harshal """ n,k=map(int,input().split()); z=[] x=[] y=[] for _ in range(n): t,a,b=map(int,input().split()) if a&b: z.append(t) elif a: x.append(t) elif b: y.append(t) x.sort() y.sort() for i in ran...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-ffloat-store") #pragma GCC optimize("-fno-defer-pop") long long int power(long long int a, long long int b, long long int m) { if (b == 0) return 1; if (b == 1) return a % m; lon...
11
CPP
temparr = input() temparr = temparr.split() n = int(temparr[0]) minimum = int(temparr[1]) common = [] alice = [] bob = [] for i in range(n): temparr = input() temparr = temparr.split() t = int(temparr[0]) a = int(temparr[1]) b = int(temparr[2]) if a == 1 and b == 1: common.append(t) ...
11
PYTHON3
n, k = map(int, input().split()) group = [[], [], [], []] for i in range(n): t, a, b = map(int, input().split()) group[a * 2 + b].append(t) pref_sum = [[0], [0], [0], [0]] for g, ps in zip(group, pref_sum): g.sort() for i in g: ps.append(ps[-1] + i) # print(group) # print(pref_sum) ans = 10*...
11
PYTHON3
n, k = map(int, input().split()) cnta = [] cntb = [] cntab = [] for i in range(n): t, a, b = map(int, input().split()) if a: if b: cntab.append(t) else: cnta.append(t) elif b: cntb.append(t) T = 0 cnta = sorted(cnta) cntb = sorted(cntb) cntab = sorted(cntab) l...
11
PYTHON3
a,b = map(int,input().split()) m,n,o,ans=[],[],[],0 for _ in range(a): q,w,e= map(int,input().split()) if w==e==1:m.append(q) elif w!=e: if e==0:n.append(q) else:o.append(q) m.sort();n.sort();o.sort() v,t,u=[],min(len(n),len(o)),len(m) for i in range(t): v.append(n[i]+o[i]) if b>u+t: print(-1) else: i,j=0,0 ...
11
PYTHON3
import math from collections import Counter,deque L=lambda:list(map(int,input().split())) M=lambda:map(int,input().split()) I=lambda:int(input()) IN=lambda:input() mod=10**9+7 def s(a): print(" ".join(list(map(str,a)))) #______________________-------------------------------_____________________# def solve(): n,...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> inline void out(T t) { cout << t << "\n"; } template <class T, class... Ts> inline void out(T t, Ts... ts) { cout << t << " "; out(ts...); } template <class T> inline bool CHMIN(T &a, T b) { if (a > b) { a = b; return true; } return fa...
11
CPP
#include <bits/stdc++.h> using namespace std; const string YESNO[2] = {"NO", "YES"}; const string YesNo[2] = {"No", "Yes"}; const string yesno[2] = {"no", "yes"}; void YES(bool t = 1) { cout << YESNO[t] << "\n"; } void Yes(bool t = 1) { cout << YesNo[t] << "\n"; } void yes(bool t = 1) { cout << yesno[t] << "\n"; } cons...
11
CPP
n, k = tuple(map(int, input().split())) alice = [] bob = [] both = [] for _ in range(n): t, a, b = tuple(map(int, input().split())) if a == 1 and b == 1: both.append(t) elif a == 1: alice.append(t) elif b == 1: bob.append(t) both.sort() alice.sort() bob.sort() remain = 0 if k <...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int mod = 1e9 + 7; const long long int inf = 2e9 + 5; double PI = 3.14159265358979323846; void solve() { long long int n, k; cin >> n >> k; vector<long long int> books[2][2]; for (int i = 0; i < n; i++) { long long int t, a, b; cin >> t >> a ...
11
CPP
n,k = map(int,input().split()) a = [] b =[] c = [] c1 = [] for i in range(n): q,w,e = map(int,input().split()) if w== 1 and e == 1: c.append(q) if w == 1 and e == 0: a.append(q) if w == 0 and e == 1: b.append(q) a = sorted(a) b = sorted(b) for i in range(min(len(a),len(b))): ...
11
PYTHON3
n,k=map(int,input().split()) ans=[] c1=0 c2=0 for i in range(n): z=list(map(int,input().split())) if(z[1]==1): c1+=1 if(z[2]==1): c2+=1 ans.append(z) if(min(c1,c2)<k): print(-1) else: a0=[] a1=[] a2=[] for i in range(len(ans)): if(ans[i][1]==1 and ans[i...
11
PYTHON3
# input = raw_input # range = xrange import sys inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 seg = [0]*200000 def offset(x): return x + 100000 def encode(x, y): return x*200002 + y def decode(x): return x//200002, x%200002 def upd(node, L, R, pos, val): while L < R: seg[node] += val seg[offset(no...
11
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using ld = long double; using db = double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = ...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long int mod = 1000000007; const long long int inf = 0x3f3f3f3f3f3f3f3fLL; long long int i, j, k; void solve(void); int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int t = 1; while (t--) solve(); return 0;...
11
CPP
n,k=map(int,input().split()) p1=[] a1=[] b1=[] c1=0 c2=0 for _ in range(n): p,a,b=map(int,input().split()) if(a==1 and b==1): p1.append(p) c1+=1 c2+=1 elif(a==1): a1.append(p) c1+=1 elif( b==1): b1.append(p) c2+=1 if(c1<k or c2<k): print(-1) el...
11
PYTHON3
#################################################### import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in fil...
11
PYTHON3
l1 = input().split(' ') n = int(l1[0]) k = int(l1[1]) alike = 0 blike = 0 total = 0 tboth = [] ta = [] tb = [] for i in range(n): b = input().split(' ') time = int(b[0]) alice = int(b[1]) bob = int(b[2]) if alice: alike += 1 if bob: blike += 1 if alice and bob: tboth...
11
PYTHON3
n,k = map(int,input().split()) x= [] y= [] z = [] for _ in range(n): t,a,b = map(int,input().split()) if a==1 and b==1: x.append(t) elif a==1 and b==0: y.append(t) elif a==0 and b==1: z.append(t) if len(x)>=k or (k - len(x)<=len(y) and k - len(x)<= len(z)): x.sort() y.sor...
11
PYTHON3
def solve(): n, k = map(int,input().split()) a1 = [] b1 = [] ab1 = [] for i in range(n): t,a,b = map(int,input().split()) if a == 1 and b == 1: ab1.append(t) elif a == 1: a1.append(t) elif b == 1: b1.append(t) a1.sort() b1.s...
11
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct node { long long val = 0, num = 0; }; vector<node> s(1 << 15); long long dim = 1 << 14; void add(long long pos, long long l, long long r, long long p) { if (l > p || r...
11
CPP
#include <bits/stdc++.h> using namespace std; template <typename Number> Number gcd(Number u, Number v) { while (v != 0) { Number r = u % v; u = v; v = r; } return u; } long long int binSearch(vector<long long int> v, long long int l, long long int r, long long int x) { if (r...
11
CPP
import sys from collections import defaultdict input = lambda:sys.stdin.readline().strip() n,k = map(int,input().split()) a = [] b = [] c = [] for i in range(n): ti,ai,bi = map(int,input().split()) if ai==0 and bi==1: a.append(ti) elif ai==1 and bi==0: b.append(ti) elif ai==1 and bi==1: ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; struct Node { int son[2], val, pri, siz; int sum; } t[2000086]; int cnt; int root; inline int rand() { static int seed = 12345; return seed = (int)seed * 482711LL % 2147483647; } void up(int x) { t[x].siz = t[(t[x].son[0])].siz + t[(t[x].son[1])].siz + 1; t[x].s...
11
CPP
n,k=map(int,input().split()) alice=[] bob=[] both =[] for i in range(n): t,a,b = map(int,input().split()) if (a==1 and b==1): both.append(t) elif (a==1): alice.append(t) elif (b==1): bob.append(t) alice.sort() bob.sort() l = min(len(alice),len(bob)) for i in range(l): both.append(alice[i]+bob[i]) if (len(bot...
11
PYTHON3
import sys import random from math import * def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def finput(): return float(input()) def tinput(): return input().split() def linput(): return list(input()) def rinput(): return map(int, tinput()) def fiinput...
11
PYTHON3
n, k = [int(i) for i in input().split()] a1 = [] a2 = [] a3 = [] A1 = False A2 = False A3 = False amount = 0 summ = 0 for i in range(n): t, a, b = [int(z) for z in input().split()] if a == 1 and b == 1: a1.append(t) A1 = True elif a == 1: a2.append(t) A2 = True elif b == 1: a3.append(t) ...
11
PYTHON3
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::string; void __Check(bool condition, const char* expression, int line) { if (!condition) { fprintf(stderr, "Check failed at line %d: %s\n", line, expression); exit(-1); } } template <class Collection, class Key> bool Conta...
11
CPP
#include <bits/stdc++.h> using namespace std; const int md = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tt{}, T{}; tt = 1; while (tt--) { long long n{}, m{}, k{}, a{}, b{}, c{}, f{}, p = -1, sum = 0; long long ans{}; cin >> n >> k; std::vector<long long> alic...
11
CPP
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
## ********************************************* ## * * ## * | | \ / |- |\ --- |\ | * ## * | | \ / | \ | | | | | \ | * ## * |--| \ / | | |/ | | | \ | * ## * | | / | / | \ | | | \ | * ## * | | / ...
11
PYTHON3
#!/usr/bin/env pypy3 from sys import stdin, stdout import heapq def input(): return stdin.readline().strip() def ans(both, alice_only, bob_only, neither, M, K): both_fc = [b[0] for b in both] neither_fc = [b[0] for b in neither] alice_only_fc = [a[0] for a in alice_only] bob_only_fc = [b[0] for...
11
PYTHON3
from copy import copy, deepcopy def read_int(): return int(input()) def read_arr(): return [int(x) for x in input().split(' ')] def read_mx(n): return [[int(num) for num in input().split(' ')] for _ in range(0, n)] def work(p_case): n, k = read_arr() mx = read_mx(n) # split b_only =...
11
PYTHON3
import sys input = sys.stdin.readline INF = 10 ** 18 n, m, k = map(int, input().split()) B = [tuple(map(int, input().split())) for _ in range(n)] GB = [] AB = [] BB = [] RB = [] for i, (t, a, b) in enumerate(B): if a and b: GB.append((t, i)) elif a: AB.append((t, i)) elif b: BB.append((t, i)) else: RB.ap...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int i, n, k, alike, blike, t, total = 0; cin >> n >> k; vector<int> a, b, coll; for (i = 0; i < n; i++) { cin >> t >> alike >> blike; if (alike) { if (blike) coll.push_back(t); else a.push_back(t); } else if (blik...
11
CPP
def main(): n, k = map(int, input().split()) alice_counter = k bob_counter = k total_time = 0 both = [] alice = [] bob = [] for _ in range(n): t, a, b = map(int, input().split()) if a and b: both.append(t) elif a: alice.append(t) el...
11
PYTHON3
import sys input = lambda :sys.stdin.readline().rstrip() from heapq import heapify,heappop,heappush n,k = map(int,input().split()) a,b,c=[],[],[] for _ in range(n): t,e,d=map(int,input().split()) if e and d: a.append(t) elif e: b.append(t) elif d: c.append(t) fl=False if len(b)+len(a)>=k and len(c)+len(a)>=k:...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; struct BookInfo { int t; int a; int b; int i; }; struct CombinedBook { int t; BookInfo b1; BookInfo b2; bool isCombined; }; int main() { ios_base::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); cin.tie(0); ...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const long long PI = 3.14159265358979; const long long INF = 1000000000000000000; bool sortbysec(pair<long long, long long> a, pair<long long, long long> b) { return (a.second < b.second); } long long powerMod(long long a, long long b, lo...
11
CPP
#include <bits/stdc++.h> using namespace std; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long n, k; cin >> n >> k; vector<long long> a; vector<long long> b; vector<long long> same; for (long long i = 0; i < n; i++) { long long t, x, y; cin >> t >> x >> y; i...
11
CPP
l=input().split() n=int(l[0]) k=int(l[1]) l=[] arrboth=[] arralice=[] arrbob=[] for i in range(n): lo=input().split() x=int(lo[0]) u=int(lo[1]) v=int(lo[2]) if(u==1 and v==1): arrboth.append(x) elif(u==1): arralice.append(x) elif(v==1): arrbob.append(x) arrbob.sort() ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> void Output(const T& v, bool print_new_line = true) { bool first = true; for (auto element : v) { if (!first) cout << " "; else first = false; cout << element; } if (print_new_line) cout << endl; } template <class T> void I...
11
CPP
#include <bits/stdc++.h> using namespace std; deque<long long> v11, v10, v01; signed main() { ios::sync_with_stdio(0); cin.tie(0); long long n, k; cin >> n >> k; for (long long i = 0; i < n; i++) { long long a, b, c; cin >> a >> b >> c; if (b == 1 && c == 1) v11.emplace_back(a); else if ...
11
CPP
import sys import math import heapq import collections from collections import OrderedDict def inputnum(): return(int(input())) def inputnums(): return(map(int,input().split())) def inputlist(): return(list(map(int,input().split()))) def inputstring(): return([x for x in input()]) def inputmatrixchar(r...
11
PYTHON3
from collections import defaultdict n,k=list(map(int,input().split())) d=defaultdict(list) for i in range(n): t,a,b=list(map(int,input().split())) x=int(str(a)+str(b),2) d[x].append(t) if len(d[2])+len(d[3])<k or len(d[1])+len(d[3])<k: print(-1) else: d[1].sort() d[2].sort() d[3].sort() ...
11
PYTHON3
n,k=map(int,input().split()) v1,v2,v12=[],[],[] for _ in range(n): t,l1,l2=map(int,input().split()) if l1==1 and l2==1: v12.append(t) elif l1==1: v1.append(t) elif l2==1: v2.append(t) v1.sort() v2.sort() v12.sort() x,y,z=0,0,0 ans=0 sb=k-min(len(v1),len(v2)) sb = sb if sb>...
11
PYTHON3