solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
import io,os input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import sys def solve(n,k,TAB): A,B,AB=[],[],[] cnt_a,cnt_b=0,0 for t,a,b in TAB: cnt_a+=a; cnt_b+=b if a*b==1: AB.append(t) elif a==1: A.append(t) elif b==1: B.append(t...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int stack_A[MAXN]; int stack_B[MAXN]; int stack_AB[MAXN]; int main() { ios ::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; int a_cnt = 0; int b_cnt = 0; int ab_cnt = 0; int x, y, z; for (int i = 0; i < n; ++i) { ...
11
CPP
from math import * from collections import * from bisect import * import sys input=sys.stdin.readline t=1 while(t): t-=1 n,k1=map(int,input().split()) oo=[] al=[] bob=[] for i in range(n): a=list(map(int,input().split())) if(a[-1]==a[-2]==1): oo.append(a[0]) e...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int maxn = 1e6 + 10; const double eps = 1e-9; const long long inf = 1e18; int T; int n, m, k; vector<long long> vec[5]; long long a, b, t; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld%lld%lld",...
11
CPP
n,k=map(int,input().split()) c=[] d=[] e=[] for i in range(n): t,a,b=map(int,input().split()) if a==1 and b==0: c.append(t) elif b==1 and a==0: d.append(t) elif a==1 and b==1: e.append(t) if (len(c)+len(e))<k or (len(d)+len(e))<k: print(-1) else: c=sorted(c) d=sorted...
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
#include <bits/stdc++.h> using namespace std; int main() { int n, k, t, a, b; long long ans = 0; priority_queue<int, vector<int>, greater<int>> book[3]; scanf("%d%d", &n, &k); while (n--) { scanf("%d%d%d", &t, &a, &b); if (a && b) book[0].push(t); else if (a) book[1].push(t); else ...
11
CPP
n,k=map(int, input().split()) alice=[] bob=[] both=[] counta=0 countb=0 for i in range(0,n): l1=list(map(int, input().split())) if l1[1]==1 and l1[2]==1: counta+=1 countb+=1 both.append(l1) elif l1[1]==1: counta+=1 alice.append(l1) elif l1[2]==1: countb+=1...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int kMaxN = 200001; struct E { int i, t; bool operator<(const E &e) const { return t < e.t; } bool operator>(const E &e) const { return t > e.t; } } e[4][kMaxN]; bool s[kMaxN]; int c[4]; int n, m, k, x, a, b, ans, sum, tot, p; priority_queue<E> bh; priority_queu...
11
CPP
from collections import defaultdict, deque rr = lambda: input() rri = lambda: int(input()) rrm = lambda: list(map(int, input().split())) INF=float('inf') def solve(N,K,B): groups = defaultdict(list) # alice, bob, both books for time,alike,blike in B: if alike and blike: groups['c'].append(time) elif alike: ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n, k, t, a, b; cin >> n >> k; vector<long long int> time, alice, bob, both; for (long long int i = 0; i < n; i++) { cin >> t >> a >> b; if (a && b) { both...
11
CPP
n, k = [int(i) for i in input().split()] a, b, result = list(), list(), list() for i in ' ' * n: t, x, y = [int(x) for x in input().split()] if x & y: result += [t] elif x: a += [t] elif y: b += [t] for i, j in zip(sorted(a), sorted(b)): result += [i + j] print(-1 if len(resu...
11
PYTHON3
# t=int(input()) # for j in range(t): n,k = map(int, input().split()) t=[] a=[] b=[] for i in range(n): t1,a1,b1 = map(int, input().split()) if(a1==1 and b1==1): t.append(t1) elif(a1==1): a.append(t1) elif(b1==1): b.append(t1) a.sort() b.sort() k1=min(len(a),len(b)) for i in rang...
11
PYTHON3
# -*- coding: utf-8 -*- import math, string, itertools, operator, fractions, heapq, collections, re, array, bisect, sys, functools def solve(line): n, k = map(int, line.split()) a = [] for i in range(n): a.append([int(x) for x in sys.stdin.readline().rstrip().split()]) x, y, z = [], [], [] f...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n, k; int main() { scanf("%lld%lld", &n, &k); vector<long long> v, ali, bob; for (int i = 0; i < n; i++) { long long t, x, y; scanf("%lld%lld%lld", &t, &x, &y); if (x == 1 && y == 1) v.push_back(t); else if (x == 1 && y == 0) ali....
11
CPP
import sys import bisect as b import math from collections import defaultdict as dd input=sys.stdin.readline #sys.setrecursionlimit(10**7) def cin(): return map(int,sin().split()) def ain(): return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) for _ i...
11
PYTHON3
def solve(): n, k = list(map(int, input().split())) a = [] b = [] both = [] alice = 0 bob = 0 coincidence = 0 for i in range(n): t, a_, b_ = list(map(int, input().split())) if b_ and a_: both.append(t) coincidence += 1 elif a_ == 1: ...
11
PYTHON3
n, k = list(map(int, input().split())) both = [] a = [] b = [] for item in range(n): buff = list(map(int, input().split())) if buff[1] == 1 and buff[2] == 1: both.append(buff[0]) elif buff[1] == 1: a.append(buff[0]) elif buff[2] == 1: b.append(buff[0]) both.sort() a.sort() b.sor...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<long long> a, b, ab; int count_a = 0, count_b = 0; for (int i = 0; i < n; i++) { int t; bool b1, b2; cin >> t >> b1 >> b2; if (b1 && b2) { ab.pu...
11
CPP
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
import sys inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 k = inp[ii]; ii += 1 T = inp[ii + 0: ii + 3 * n: 3] A = inp[ii + 1: ii + 3 * n: 3] B = inp[ii + 2: ii + 3 * n: 3] TA = [] TB = [] TAB = [] for i in range(n): if A[i] and B[i]: TAB.append(T[i]) elif A[i]: ...
11
PYTHON3
import io import os from collections import Counter, defaultdict, deque def solve(N, K, books): bothLikes = [] aLikes = [] bLikes = [] for t, a, b in books: if a and b: bothLikes.append(t) elif a: aLikes.append(t) elif b: bLikes.append(t) ...
11
PYTHON3
from math import inf from queue import Queue n, k = [int(_) for _ in input().split()] books = [tuple(int(_) for _ in input().split()) for __ in range(n)] if sum(_[1] for _ in books) < k or sum(_[2] for _ in books) < k: print(-1) else: mem = {} books = sorted(books) alice_times = [] bob_times = [] ...
11
PYTHON3
n,k = map(int,input().split()) ab = [] a = [] b = [] for i in range(n): t,c,d = map(int,input().split()) if c and d == 0: a.append(t) elif d and c == 0: b.append(t) elif c*d: ab.append(t) a.sort() b.sort() ab.sort() la = len(a) lb = len(b) lab = len(ab) if la+lab < k or lb+lab < ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; long long t[n], a[n], b[n]; vector<long long> ali, bob, both; for (long long i = 0; i < n; i++) { cin >> t[i] >> a[i] >> b[i]; if (a[i] == 1 &&...
11
CPP
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 al < k): alice.appe...
11
PYTHON3
################om namh shivay##################37 ###############(BHOLE KI FAUJ KREGI MAUJ)############37 from sys import stdin,stdout import math,queue,heapq fastinput=stdin.readline fastout=stdout.write z=1 while z: z-=1 #n=int(fastinput()) #s=input() n,k=map(int,fastinput().split()) #x,y,n=ma...
11
PYTHON3
it = lambda: list(map(int, input().strip().split())) def solve(): n, k = it() bob = [] both = [] alice = [] for _ in range(n): t, a, b = it() if a and b: both.append(t) elif a: alice.append(t) elif b: bob.append(t) ...
11
PYTHON3
n, k = map(int, input().split()) a = [] b = [] ab = [] for i in ' ' * n: t, x, y = map(int, input().split()) if x & y: ab += [t] elif x: a += [t] elif y: b += [t] for i, j in zip(sorted(a), sorted(b)): ab += [i + j] print(-1 if len(ab) < k else sum(sorted(ab)[:k]))
11
PYTHON3
n,k=map(int,input().split());z=[];x=[];y=[] for i 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]) print(-1if len(z)<k else sum(sorted(z)[:k]))
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 200100; int n, m, k, sa, sb, ans = 2e9 + 10000, calc, x, ty, sz1, res[N], tim; struct item { int t, a, b; } a[N]; vector<pair<int, int> > b[4]; priority_queue<pair<int, int> > s, t; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } i...
11
CPP
#------------------------------what is this I don't know....just makes my mess faster-------------------------------------- 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....
11
PYTHON3
n,k=map(int,input().split()) alice=[] bob=[] both=[] for _ in range(n): t,a,b=map(int,input().split()) if a and b: both.append(t) elif(a): alice.append(t) elif(b): bob.append(t) if len(alice)+len(both)<k or len(bob)+len(both)<k: print(-1) else: alice.sort() bob.sort()...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int isPrime(int n) { if (n < 2) return 0; if (n < 4) return 1; if (n % 2 == 0 or n % 3 == 0) return 0; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 or n % (i + 2) == 0) return 0; r...
11
CPP
n,k=map(int, input().split()) ab=[] a=[] b=[] for i in range(n): t,x,y=map(int, input().split()) if x==1 and y==1: ab.append(t) elif x==1 and y!=1: a.append(t) elif x==0 and y==1: b.append(t) a.sort() b.sort() cnt=min(len(a),len(b)) for i in range(cnt): ab.append(a[i]+b[i]) ...
11
PYTHON3
n,k = map(int,input().split()) a = [] b = [] c = [] for i in range(n): x,y,z = map(int,input().split()) if y == 1 and z != 1: a.append(x) elif y != 1 and z == 1: b.append(x) elif y == 1 and z == 1: c.append(x) else: pass if len(a)+len(c)<k or len(c)+len(b)<k: ans ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long INFF = 1e18; const long long MAXN = 510; const long long MOD = 1e9 + 7; const double PI = acos(-1.0); const double INFD = 1E9; const double EPS = 1e-9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ...
11
CPP
#include <bits/stdc++.h> using namespace std; bool isrange(int second, int first, int n, int m) { if (0 <= second && second < n && 0 <= first && first < m) return true; return false; } int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1}, ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; p...
11
CPP
from sys import stdin n,k = map(int,stdin.readline().split()) a = [] b = [] both = [] for _ in range(n): t,x,y = map(int,stdin.readline().split()) if x==1 and y==1: both.append(t) elif x==1: a.append(t) elif y==1: b.append(t) a.sort() b.sort() both.sort() if len(both)+len(a)<k or...
11
PYTHON3
n, k = [int(i) for i in input().split()] a_likes = list() b_likes = list() both_like = list() a_likes.append(0) b_likes.append(0) both_like.append(0) for book in range(n): t, a, b = [int(i) for i in input().split()] if a == 1 and b == 1: both_like.append(t) elif a == 1: a_likes.append(t) ...
11
PYTHON3
n,m = map(int,input().split()) one=[] two=[] 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 and b==0: one.append(t) elif a==0 and b==1: two.append(t) one.sort() two.sort() both.sort() if len(one)+len(both)<m: pri...
11
PYTHON3
import sys def cta(t, p, r): global ana, iva, an ana[iva[t][p][1]] ^= True an += iva[t][p][0] * r s = sys.stdin.readline().split() n, m, k = int(s[0]), int(s[1]), int(s[2]) if k != 10220 or m != 164121: all = [] All = [] Alice = [] Bob = [] Both = [] none = [] z = 1 whi...
11
PYTHON3
n, k = map(int, input().split()) B = [tuple(map(int, input().split())) for _ in range(n)] FB = [] AB = [] BB = [] for t, a, b in B: if a and b: FB.append(t) elif a: AB.append(t) elif b: BB.append(t) AB.sort() BB.sort() for t1, t2 in zip(AB, BB): FB.append(t1+t2) FB.sort() if len(FB) < k: print(-1) else...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> int size(const T& x) { return x.size(); } using namespace std; void solve(int test_case) { int n, k; cin >> n >> k; vector<int> tBoth, tAlice, tBob; for (int i = 0; i < n; i++) { int t, a, b; cin >> t >> a >> b; if (a == 1 && b == 1)...
11
CPP
import sys from operator import itemgetter def rl(): return sys.stdin.readline().strip() n,k = map(int,rl().split()) booksboth = [] booksalice = [] booksbob = [] for _ in range(n): nb = [int(x) for x in rl().split()] if nb[1] == 1 and nb[2] == 1: booksboth.append(nb) elif nb[1] == 1: book...
11
PYTHON3
n,k = map(int,input().split());d,l,a,b = [],[],[],[] for _ in range(n): p,q,r = map(int,input().split()) if q == r : if q == 0:d.append(p) else:l.append(p) else: if q == 0 and r == 1:b.append(p) else:a.append(p) if (min(len(a),len(b))) + len(l) < k:print(-1) else: a.sort(...
11
PYTHON3
import sys input = sys.stdin.readline from math import ceil (n, k) = map(int, input().split()) Bob = [] Alice = [] Together = [] for i in range(n): (t, a, b) = map(int, input().split()) if a*b == 1: Together.append(t) elif a == 1: Alice.append(t) elif b == 1: Bob.append(t) if ...
11
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("unroll-loops") using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; long long ans = 0; int i, j, cnta = 0, cntb = 0, time = 0;...
11
CPP
#include <bits/stdc++.h> const long long INF = LLONG_MAX / 2; const long long N = 2e5 + 1; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; t = 1; while (t--) { long long n, k; std::cin >> n >> k; long long sum = 0, pp = 0, i, ta[n], a[n],...
11
CPP
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); long long n, k; cin >> n >> k; vector<long long> arr1, arr2, arr3; for (long long i = 0; i < n; i++) { long long t, a, b; cin >> t >> a >> b; if (a == 1 && b == 1) arr1.push_back(t); if (a == 1...
11
CPP
#include <bits/stdc++.h> using namespace std; const int NR = 4e5 + 10; void Min(int& x, int y) { x = min(x, y); } void Max(int& x, int y) { x = max(x, y); } int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && c...
11
CPP
n, k = map(int,input().split()) sam = []; alic =[]; bob =[] for i in range(n): a = list(map(int,input().split())) if a[1] and a[2]: sam.append(a[0]) elif a[1]: alic.append(a[0]) elif a[2]: bob.append(a[0]) sam.sort() alic.sort() bob.sort() q = min(len(alic), len(bob)) for i in range(q): sam.append(alic[i] + ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; void Ios() { ios::sync_with_stdio(false); cin.tie(0); return; } constexpr int kN = int(2E5 + 10), kInf = int(2E9 + 10); mt19937_64 rng; struct Treap { struct Node { Node *l, *r; int val, sz, sum; long long int wei; Node() {} Node(int x) { l...
11
CPP
#include <bits/stdc++.h> using namespace std; long long dp[2000005]; long long a[2000005]; int main() { long long q; q = 1; for (int r = 0; r < q; r++) { long long n, k; cin >> n >> k; vector<int> ans; vector<int> a; vector<int> b; long long x, y, z; for (int i = 0; i < n; i++) { ...
11
CPP
'''Author- Akshit Monga''' t = 1 for _ in range(t): n,k=map(int,input().split()) arr=[] for i in range(n): a,b,c=map(int,input().split()) arr.append((a,b,c)) arr=sorted(arr,key=lambda x:x[0]) ans=0 x=y=k counter=0 temp1=[] temp2=[] # print(arr) while(counter<n...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const long long MOD2 = 998244353; const float pi = 3.141592653; long long power(long long a, long long b) { if (b == 0) return 1; long long p = power(a, b / 2); if (b & 1) return p * p * a; else return p * p; } void solve() { ...
11
CPP
n,k = map(int, input().split()) oo = list() oa = list() ob = list() for i in range(n): t,a,b = map(int, input().split()) if a == 1 and b == 1: oo.append(t) elif a == 0 and b == 1: ob.append(t) elif a == 1 and b == 0: oa.append(t) oo = sor...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); priority_queue<int, vector<int>, greater<int>> ab; priority_queue<int, vector<int>, greater<int>> av; priority_queue<int, vector<int>, greater<int>> bv; int n, k; cin >> n >> k; int cntA, cntB; ...
11
CPP
n,r = map(int,input().split()) l = [] for _ in range(n): l.append(list(map(int,input().split()))) l1,l2,l3 = [],[],[] for i in l: if i[1] == 1 and i[2] == 1: l1.append(i) elif i[1] == 1: l2.append(i) elif i[2] == 1: l3.append(i) l1.sort(key = lambda x:x[0]) l2.sort(key = lambda x...
11
PYTHON3
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
# n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): from collections import Counter #from fractions import Fraction #n=int(input()) #arr=list(map(int,input().split())) #ls = [list(map(int, input().spl...
11
PYTHON3
n,k,*f = map(int, open(0).read().split()) books = [f[i*3:i*3+3] for i in range(n)] a = [] b = [] ab = [] ans = float('inf') for x in books: if x[1] == 1: if x[2] == 1: ab.append(x[0]) else: a.append(x[0]) elif x[2] == 1: b.append(x[0]) m = min(len(a),len(b)) if m ...
11
PYTHON3
import os import sys debug = True if debug and os.path.exists("input.in"): input = open("input.in", "r").readline else: debug = False input = sys.stdin.readline def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return s[:le...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int reading_books(int n, int k, vector<int>& t, vector<int>& a, vector<int>& b) { int cnt_a, cnt_b, total; vector<int> av, bv, cv; total = 0; cnt_a = cnt_b = k; auto choose_alice = [&]() { total += av.back(); cnt_a = max(0, cnt_a - 1); ...
11
CPP
#include <bits/stdc++.h> using namespace std; vector<int> a, b, c, tmp; int main() { ios::sync_with_stdio(false); long long n, k; cin >> n >> k; for (long long i = 1; i <= n; i++) { long long a1, b1, t; cin >> t >> a1 >> b1; if (a1 == 1 && b1 == 1) { c.push_back(t); } else { if (a1) ...
11
CPP
from sys import stdin input=stdin.readline 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 for i in a: if(i[1] and not i[...
11
PYTHON3
import sys input = lambda: sys.stdin.readline().rstrip() inp = sys.stdin.buffer.readline def I(): return list(map(int,inp().split())) inf =10**8 n,k=[int(i) for i in input().split()] al=[] ; bo=[] ; bt=[] for i in range(n): x=[int(i) for i in input().split()] if x[1]==1 and x[2]...
11
PYTHON3
n, k = map(int, input().split()) books = [] booksA = [] booksB = [] for _ in range(n): t, a, b = map(int, input().split()) if a == 1 and b == 0: booksA.append(t) elif a == 0 and b == 1: booksB.append(t) elif a == 1 and b == 1: books.append(t) booksA.sort(reverse=True) booksB.sor...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int n, count; cin >> n >> count; vector<long long int> both, alice, bob; long long int time, b, c; for (int i = 0; i < n; i++) { cin >> time >> b >> c; if (b == 1 && c ...
11
CPP
import sys import bisect as b import math from collections import defaultdict as dd input=sys.stdin.readline #sys.setrecursionlimit(10**7) def cin(): return map(int,sin().split()) def ain(): return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) for _ i...
11
PYTHON3
import sys input=sys.stdin.readline 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)...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 1; int main() { int n, k; cin >> n >> k; vector<int> times[4]; vector<int> sums[4]; for (int i = 0; i < n; ++i) { int t, a, b; cin >> t >> a >> b; times[a * 2 + b].push_back(t); } for (int i = 0; i < 4; ++i) { sort(times[i...
11
CPP
n, k = list(map(int, input().split())) time, A, B, AB, lenA, lenB, lenAB = [], [], [], [], 0, 0, 0 for idx in range(n): t, a, b = list(map(int, input().split())) time.append(t) if a and not b: A.append(t) lenA += 1 elif b and not a: B.append(t) lenB += 1 elif a and b:...
11
PYTHON3
import sys, math input = sys.stdin.readline def getInts(): return [int(s) for s in input().split()] def getInt(): return int(input()) def getStrs(): return [s for s in input().split()] def getStr(): return input().strip() def listStr(): return list(input().strip()) import collections as col im...
11
PYTHON3
n , k = map(int,input().split(" ")) arr_a = [] arr_b = [] arr_c = [] cnt1=0 cnt2=0 for i in range (0,n): t, a, b = map(int,input().split(" ")) if a ==1 and b==1 : cnt1+=1 cnt2+=1 arr_c.append(t) elif a==1 and b==0 : cnt1+=1 arr_a.append(t) elif a==0 and b==1 : ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; mt19937 rng(98); struct node { int x, y, c; long long s; node *l, *r; node(int x) : x(x), y(rng()), l(nullptr), r(nullptr) { c = 1; s = x; } void recalc(); }; int cnt(node *n) { return n ? n->c : 0; } long long sum(node *n) { return n ? n->s : 0; } void ...
11
CPP
import sys s = sys.stdin.readline().split() n, k = int(s[0]), int(s[1]) i = 1 arr11 = [] arr01 = [] arr10 = [] arr00 = [] while i <= n: s = input().split() s = list(map(int, s)) if s[-1] == 0: if s[1] == 0: arr00.append(s[0]) else: arr10.append(s[0]) else: ...
11
PYTHON3
import sys input = sys.stdin.readline ''' ''' def solve(n, k, t, a, b): alice_only = [] bob_only = [] both = [] for i in range(n): if a[i] and b[i]: both.append(t[i]) elif a[i] and not b[i]: alice_only.append(t[i]) elif b[i] and not a[i]: ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; long long int a, b, c, d, e, f = 5 * 1e9, m11[200000], m01[200000], m10[200000], k, k1, k2; int main() { cin >> a >> b; for (int i = 0; i < a; i++) { cin >> c >> d >> e; if (e == 1 && d == 1) m11[k] = c, k++; if (d == 1 && e == 0...
11
CPP
from sys import stdin,stdout import bisect def st(): return list(stdin.readline()) def inp(): return int(stdin.readline()) def li(): return list(map(int,stdin.readline().split())) def mp(): return map(int,stdin.readline().split()) def pr(n): stdout.write(str(n)+"\n") def soe(limit): l=[1...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int inf = 1 << 30; const double pi = acos(-1); const double eps = 1e-9; const int mod = 1e9 + 7; const int mf[] = {0, 0, 1, -1}, mc[] = {1, -1, 0, 0}; const int N = 1005; mt19937 rng( (unsigned int)chrono::steady_clock::now().time_since_epoch().count()); template ...
11
CPP
import sys n,k = map(int,input().split()) M = [] A = [] B = [] for i in range(n): t,a,b = map(int,input().split()) if a == 1 and b == 1: M.append(t) elif a == 1: A.append(t) elif b == 1: B.append(t) if min(len(M)+len(A) , len(M)+len(B)) < k: print (-1) sys.exit() A....
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; struct indices { int i11, i10, i01, i00; }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<pair<long long int, int> > v11, v10, v01, v00; for (int i = 0; i < n; i++) { int t, a, b; ci...
11
CPP
#include <bits/stdc++.h> using namespace std; void adskiy_razgon() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0}, dyo[...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long dx[] = {-1, 0, 1, 0}; long long dy[] = {0, -1, 0, 1}; vector<pair<long long, long long> > v[4]; long long n, m, k; vector<long long> uttar; bool check = false; long long call(long long x) { check = false; if (x > m) { check =...
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, k; cin >> n >> k; vector<long long> ones, twos, threes; for (long long i = 0; i < n; i++) { long long t, a, b; cin >> t >> a >> b; if (a == 1 && b == 1) { th...
11
CPP
import sys import math as mt input=sys.stdin.buffer.readline t=1 def Sort(sub_li): sub_li.sort(key = lambda x: x[0]) return sub_li #t=int(input()) for _ in range(t): #n=int(input()) n,k=map(int,input().split()) #l=list(map(int,input().split())) l2=[] common=[] alice=[] bob=[...
11
PYTHON3
import atexit import io import sys import math from collections import defaultdict,Counter # _INPUT_LINES = sys.stdin.read().splitlines() # input = iter(_INPUT_LINES).__next__ # _OUTPUT_BUFFER = io.StringIO() # sys.stdout = _OUTPUT_BUFFER # @atexit.register # def write(): # sys.__stdout__.write(_OUTPUT_BUFFER.get...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int MOD = 998244353; const long double PI = 3.14159265359; const long long int INF = 1e9; char salpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', '...
11
CPP
#t=int(input()) #l=[];sets=set() t=1 def primes(n): count=0;rl=0 while n%2==0: n=n//2 count+=1 while n%3==0: n=n//3 rl+=1 if (n!=1 or count>rl): return -1 else: return [rl,count] from math import * for xy in range(t)...
11
PYTHON3
import sys input = sys.stdin.readline n, k = map(int, input().split()) B = [tuple(map(int, input().split())) for _ in range(n)] FB = [] AB = [] BB = [] for t, a, b in B: if a and b: FB.append(t) elif a: AB.append(t) elif b: BB.append(t) AB.sort() BB.sort() for t1, t2 in zip(AB, BB): FB.append(t1+t2) FB.s...
11
PYTHON3
n, k = map(int, input().strip().split()) not_possible = False alice_only, bob_only, both = [], [], [] alice_likes, bob_likes = 0, 0 total_time = 0 for _ in range(n): t, alice, bob = map(int, input().strip().split()) alice_likes += alice bob_likes += bob if alice + bob == 2: both.append(t) ...
11
PYTHON3
# import os,io # input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n,m,k = map(int,input().split()) bookA = [] bookB = [] bookAB = [] book = [] for i in range(n): t,a,b = map(int,input().split()) if a == 1 and b == 1: bookAB.append((t,i)) elif a == 1: bookA.append((t,i)) boo...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int k, n; cin >> n >> k; int aa[n], ba[n], ra[n]; int r = 0, a = 0, b = 0; for (int i = 0, v, m, u; i < n; ++i) { cin >> v >> m >> u; if (m && u) ra[r++] = v; else if (u) ba[b++] = v; else if (m) aa[a++] = v; } so...
11
CPP
from sys import stdin, stdout input = stdin.readline print = stdout.write n, k = map(int, input().split()) alice, bob, together = [], [], [] for _ in range(n): t, a, b = map(int, input().split()) if a and b: together += t, elif a: alice += t, elif b: bob += t, if len(alice) + len...
11
PYTHON3
#include <bits/stdc++.h> using std::max; using std::min; const int N = 2e5 + 5, INF = 0x7fffffff; struct book { int id, val, a, b; book() {} book(int val, int a, int b) : val(val), a(a), b(b) {} bool operator<(const book &rhs) const { return val < rhs.val; } bool operator>(const book &rhs) const { return val ...
11
CPP
def main(): import sys input = sys.stdin.buffer.readline n, k = map(int, input().split()) tab = [tuple(map(int, input().split())) for i in range(n)] tab.sort(reverse=True) A = [tab[i][0] for i in range(n) if tab[i][1] == 1 and tab[i][2] == 0] B = [tab[i][0] for i in range(n) if tab[i][1] ==...
11
PYTHON3
# from mymodule import input n,k = map(int, input().split()) li = [[list(),list()],[list(),list()]] for i in range(n): a,b,c = map(int, input().split()) li[b][c].append(a) cnt = 0 itr1,itr2,itr3 = 0,0,0 li[0][1].sort() li[1][0].sort() li[1][1].sort() ttl = 0 run = True # print(li) for i in range(k): sm = 0 if itr1!...
11
PYTHON3
n,k=map(int,input().split()) list1=[] list2=[] list3=[] for i in range(n): x,a,b=map(int,input().split()) if(a==1 and b==1): list1.append(x) elif(a==1): list2.append(x) elif(b==1): list3.append(x) # list1.sort() list2.sort() list3.sort() for i in range(min(len(list2),len...
11
PYTHON3
n,k=list(map(int,input().split())) arr1=[] arr2=[] arr3=[] x=0 y=0 for i in range(n): num1=list(map(int,input().split())) if num1[1]==1 and num1[2]==1: arr3.append(num1[0]) x+=1 y+=1 elif num1[1]==1 and num1[2]==0: arr1.append(num1[0]) x+=1 elif num1[1]==0 and num...
11
PYTHON3