solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
n, k = map(int, input().split()) books = [list(map(int, input().split())) for _ in range(n)] new_books = {str(i // 2) + str(i % 2): [0] for i in range(4)} for book in books: new_books[str(book[1]) + str(book[2])].append(book[0]) for book in new_books.keys(): new_books[book].sort() for i in range(1, len(new...
11
PYTHON3
#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 ...
11
CPP
#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...
11
CPP
#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; ...
11
CPP
#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...
11
CPP
from collections import deque # for #!/usr/bin/env python 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...
11
PYTHON3
n,k=map(int,input().split()) t10=[] t01=[] t11=[] for x in range(n): t,a,b=map(int,input().split()) if a==0 and b==1: t01.append(t) elif a==1 and b==0: t10.append(t) elif a==1 and b==1: t11.append(t) t10.sort() t01.sort() t11.sort() for x in range(1,len(t01)): t01[x]+=t01[x-...
11
PYTHON3
import sys input = sys.stdin.readline I = lambda : list(map(int,input().split())) n,k =I() a=[];b=[] ab=[] for _ in range(n): x,y,z=I() if y and z: ab.append(x) elif y: a.append(x) elif z: b.append(x) a.sort() b.sort() ab.sort() x,y,z=len(a),len(b),len(ab) i=j=l=t=an=0 if x+z <k or y+z<k: print(-1) else: w...
11
PYTHON3
#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> ...
11
CPP
from heapq import heapify, heappop, heappush import sys input = sys.stdin.buffer.readline def main(): n,k = map(int,input().split()) A = []; B = []; AorB = []; C = [] for __ in range(n): t,a,b = map(int,input().split()) if a == b == 1: C.append(t) elif a == 1: ...
11
PYTHON3
n,k=map(int,input().split()) aa,bb,cc=[0],[0],[0] for _ in range(n): t,a,b=map(int,input().split()) if a==b and a==1: cc.append(t) elif a==1: aa.append(t) elif b==1: bb.append(t) aa.sort() bb.sort() cc.sort() for i in range(1,len(aa)): aa[i]=aa[i-1]+aa[i] for i in range(1,len...
11
PYTHON3
n,k = map(int,input().split()) ab = [0] a = [0] b = [0] for i in range(n): t,ai,bi = map(int,input().split()) if ai == 1 and bi == 1: ab.append(t) elif ai == 1: a.append(t) elif bi == 1: b.append(t) if len(ab)-1 + len(a)-1 < k or len(ab)-1 + len(b)-1 < k: print(-1) else: ...
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
#!/usr/bin/env python3 import sys input = sys.stdin.readline n, k = map(int, input().split()) both = [] alice = [] bob = [] for _ in range(n): c, a, b = map(int, input().split()) if a and b: both.append(c) elif a: alice.append(c) elif b: bob.append(c) alice.sort() bob.sort() fo...
11
PYTHON3
n, k = map(int, input().split()) a = [] b = [] s = [] for i in ' ' * n: t, x, y = map(int, input().split()) if x & y: s += [t] elif x: a += [t] elif y: b += [t] s += [i + j for i, j in zip(sorted(a), sorted(b))] print(-1 if len(s) < k else sum(sorted(s)[:k]))
11
PYTHON3
n,k=map(int,input().split()) l=[] common=[] alice=[] bob=[] for i in range(0,n): t,a,b=map(int,input().split()) if(a&b): common.append(t) elif(a): alice.append(t) elif(b): bob.append(t) if(len(alice)+len(common)<k or len(bob)+len(common)<k): print(-1) else: common.sort() ...
11
PYTHON3
n,k = input().split(' ') n,k = int(n), int(k) S = [] for i in range(n): S.append(input().split(' ')) A = [] B = [] C = [] for i in S: if i[1] == '1' and i[2] == '1': C.append(int(i[0])) elif i[1] == '1' and i[2] == '0': A.append(int(i[0])) elif i[1] == '0' and i[2] == '1': B.appe...
11
PYTHON3
n,kk = 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() both.sort() count=0 l = min(len(alice),len(bob)) i=0 j=0 ...
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] if len(ab) < k: print(-1) else: print(sum(sorted(ab)...
11
PYTHON3
import sys input=sys.stdin.readline n,k=map(int,input().split()) both=[] ali=[] bli=[] 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): ali.append(t) if(a==0 and b==1): bli.append(t) lboth=len(both) lali=len(ali) lbli=len(bli)...
11
PYTHON3
#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(...
11
CPP
#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...
11
CPP
#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...
11
CPP
class Books: def __init__(self, time, alice_like, bob_like): self.time = time self.alice_like = alice_like self.bob_like = bob_like def solve(): n, k = map(int, input().split()) books = [] for i in range(n): t, a, b = map(int, input().split()) books.append(Book...
11
PYTHON3
def cta(t,p,r): global ana,iva,an ana[iva[t][p][1]]^=True an+=iva[t][p][0]*r n,m,k=[int(x) for x in input().split()] iva=[[] for _ in range(4)] alv=[() for _ in range(n)] for i in range(n): v,o,u=[int(x) for x in input().split()] q=(o<<1)|u iva[q].append((v,i)) alv[i]=(v,i) for e in iva : e.sort() alv.sort() ...
11
PYTHON3
import io import os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline class Books: def __init__(self, time, alice_like, bob_like): self.time = time self.alice_like = alice_like self.bob_like = bob_like def solve(): n, k = map(int, input().split()) books = [] for ...
11
PYTHON3
#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...
11
CPP
import bisect import sys import math input = sys.stdin.readline import functools import heapq from collections import defaultdict ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(...
11
PYTHON3
def read_ints(): line = input() return [int(e) for e in line.strip().split(' ')] n, k = read_ints() a = [] b = [] t = [] for _ in range(n): it, ia, ib = read_ints() if ia == 1 and ib == 1: t.append(it) elif ia == 1: a.append(it) elif ib == 1: b.append(it) a.sort() b.sor...
11
PYTHON3
from sys import stdin import math A = list(map(int,stdin.readline().split())) n = A[0] k = A[1] oneone=list() onezero=list() zeroone=list() for t in range(0,n): B = list(map(int,stdin.readline().split())) if B[1]==1 and B[2]==1: oneone.append(B[0]) elif B[1]==1 and B[2]==0: onezero.append(B...
11
PYTHON3
#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 ...
11
CPP
n,ke=[int(i) for i in input().split()] bo=[] a1=[] b1=[] for i in range(n): ti,a,b=[int(i) for i in input().split()] if a==1 and b==1: bo.append([ti,a,b]) elif a==1: a1.append([ti,a,b]) elif b==1: b1.append([ti,a,b]) bo.sort() a1.sort() b1.sort() su=0 i=0 j=0 k=0 f1=0 while ke>0:...
11
PYTHON3
#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...
11
CPP
import sys s = sys.stdin.readline().split() n, m, k = int(s[0]), int(s[1]), int(s[2]) all = [] All = [] Alice = [] Bob = [] Both = [] none = [] z = 1 while n: i = sys.stdin.readline().split() x = 3 i.append(z) while x: i[x-1] = int(i[x - 1]) x -= 1 all.append(i) if i[1] == i[2]...
11
PYTHON3
from sys import stdin, stdout import heapq as hq from collections import defaultdict t = 1 for tc in range(t): n,k = list(map(int, stdin.readline().split())) lib=[] for nc in range(n): lib.append(tuple(map(int, stdin.readline().split()))) libA=[] libB=[] libAB=[] for book in lib: ...
11
PYTHON3
import sys def input(): return sys.stdin.readline().rstrip() def input_split(): return [int(i) for i in input().split()] # testCases = int(input()) # answers = [] # for _ in range(testCases): #take input n, k = input_split() times = [] alice_likes = [] bob_likes = [] for _ in range(n): t, a, b = input_split() t...
11
PYTHON3
#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...
11
CPP
#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...
11
CPP
# JAI SHREE RAM import math; from collections import * import sys; from functools import reduce def get_ints(): return map(int, input().strip().split()) def get_list(): return list(get_ints()) def getlistofstring(): return list(input().strip().split()) def printxsp(*args): return print(*args,...
11
PYTHON3
n, k = map(int, input().split()) doubles = [] single_a = [] single_b = [] for i in range(n): t, a, b = map(int, input().split()) if (a == b): if (a == 1): doubles.append(t) else: if (a): single_a.append([t, a, b]) if (b): single_b.append([t, a, b])...
11
PYTHON3
n,k = map(int,input().split(' ')) book = [[]for i in range(4)] s = [[]for i in range(4)] for i in range(n): t,a,b = map(int,input().split(' ')) book[2*a+b].append(t) for i in range(1,4): book[i].sort() s[i].append(0) for j in book[i]: s[i].append(s[i][len(s[i])-1]+j) ans = int(2e9+1) f...
11
PYTHON3
def solution(): s = input().split() n = int(s[0]) k = int(s[1]) yyLike = [] xqLike = [] bothLike = [] s = 0 for i in range(n): line = input().split() cost = int(line[0]) if line[1] == '1' and line[2] == '1': bothLike.append(cost) elif line[1] ...
11
PYTHON3
n, k = map(int, input().split()) books = [list(map(int, input().split())) for i in range(n)] AB, A, B = [[10**5,0,0]], [[10**5,0,0]], [[10**5,0,0]] for t,a,b in books: if a == 1 and b == 1: AB.append([t,a,b]) elif a == 1 and b == 0: A.append([t,a,b]) elif a == 0 and b == 1: B.append(...
11
PYTHON3
from sys import stdin from collections import defaultdict n, k = list(map(int, stdin.readline().rstrip().split(" "))) alice = [] bob = [] both = [] for _ in range(n): ti, ai, bi = list(map(int, stdin.readline().rstrip().split(" "))) if ai == 1 and bi == 1: both.append(ti) elif ai == 1: al...
11
PYTHON3
#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...
11
CPP
#!/bin/python3 import math import os import random import re import sys from collections import defaultdict a = [int(x) for x in input().split() ] n, k = a[0], a[1] ara = [] for i in range(n): ara.append([int(x) for x in input().split() ]) ara = sorted(ara,key=lambda x: x[0]) newAra = [] tmpAra1 = [] tmpAra2 ...
11
PYTHON3
n,k = map(int,input().split()) ali,bob,both=[],[],[] for i in range(n): r,ai,bi = map(int,input().split()) if ai and bi:both.append(r) elif ai:ali.append(r) elif bi:bob.append(r) ali.sort() bob.sort() for i in range(min(len(ali),len(bob))): both.append(ali[i]+bob[i]) if len(both)<k: print(-1) el...
11
PYTHON3
#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...
11
CPP
INF = float('inf') def tc(): n, k = map(int, input().split()) books = [tuple(map(int, input().split())) for _ in range(n)] alice, bob, both = [], [], [] for t, a, b in books: if a and b: both.append(t) elif a: alice.append(t) elif b: bob.ap...
11
PYTHON3
#dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] n,k = ip() t,a,b = [0]*n,[0]*n,[0]*n both = [] alice,bob = [],[] for i in range(n): t[i],a[i],b[i] = ip() if a[i] and b[i]: both.append(t[i]) elif...
11
PYTHON3
#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...
11
CPP
n, k = input().split() n = int(n) k = int(k) both = [] al = [] bl = [] for i in range(0, n): t, a, b = input().split() t = int(t) a = int(a) b = int(b) if a == b == 1: both.append(t) elif a == 1: al.append(t) elif b == 1: bl.append(t) both.sort() al.sort() bl.sort()...
11
PYTHON3
from collections import Counter n, k = map(int, input().split()) dat = [list(map(int, input().split())) for _ in range(n)] x = [v for v, a, b in dat if a and b] y = [v for v, a, b in dat if a and not b] z = [v for v, a, b in dat if not a and b] x.extend(u + v for u, v in zip(sorted(y), sorted(z))) if len(x) < k: pr...
11
PYTHON3
n, k = map(int, input().split()) res = 0 a = [] b = [] dp = [] for i in range(n): t, x, y = map(int, input().split()) if x == y == 1: dp.append(t) elif x == 1: a.append(t) elif y==1: b.append(t) a.sort() b.sort() for i in range(min(len(a), len(b))): dp.append(a[i] + b[i]) dp....
11
PYTHON3
n, k = map(int, input().split()) z11, z01, z10 = [], [], [] for i in range(n): t, a, b = map(int, input().split()) if a == 1 and b == 1: z11.append(t) elif a == 1: z10.append(t) elif b == 1: z01.append(t) i, j = min(k,len(z11)), min(k,len(z01),len(z10)) z11.sort() z10.sort() ...
11
PYTHON3
n,m,k = input().split(' ') n,m,k = int(n),int(m),int(k) A = [] B = [] C = [] D = [] Ainmax = 0 Binmax = 0 Cinmax = 0 Dinmax = 0 for i in range(n): entry = input().split(' ') if entry[1] == '1' and entry[2] == '1': C.append([int(entry[0]),i+1]) Cinmax+=1 elif entry[1] == '1' and entry...
11
PYTHON3
#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); ...
11
CPP
#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>...
11
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 T, size_t size> ostream &operator<<(ostream &os, const array<T, size> &arr)...
11
CPP
initial = input().strip().split(' ') books = int(initial[0]) likes = int(initial[1]) alice_list = [] bob_list = [] both_list = [] for i in range(books): line_input = input().strip().split(' ') time = int(line_input[0]) alice = (int(line_input[1]) == 1) bob = (int(line_input[2]) == 1) if alice...
11
PYTHON3
import sys import math def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def MI(): return map(int, sys.stdin.readline().split()) def SI(): return sys.stdin.readline().strip() n,k = MI() x = [] y = [] z = [] o = [] for q in range(n): t,a,b = MI() if a == 1 ...
11
PYTHON3
from heapq import heappush, heappush, heapify n, k = map(int, input().split()) alice = [] bob = [] both = [] for i in range(n): t, a, b = map(int, input().rstrip().split()) if a == 1 and b == 1: both.append(t) if a == 1 and b == 0: alice.append(t) if a == 0 and b == 1: bob.append...
11
PYTHON3
from typing import List, Tuple def solve(n: int, k: int, tab: List[Tuple[int, int, int]]): both, a_only, b_only = [], [], [] for t, a, b in tab: if a == 1 and b == 1: both.append(t) elif a == 1: a_only.append(t) elif b == 1: b_only.append(t) both...
11
PYTHON3
n,k=map(int,input().split()) l=[] ll=[] lll=[] for i in range(n): t,a,b=map(int,input().split()) if a==1 and b==1: l.append(t) elif a==1: ll.append(t) elif b==1: lll.append(t) ll.sort() lll.sort() for i in range(min(len(ll),len(lll))): l.append(ll[i]+lll[i]) we=len(l) if k>we: print(-1) else:...
11
PYTHON3
#import math #from functools import lru_cache #import heapq #from collections import defaultdict #from collections import Counter #from collections import deque #from sys import stdout #from sys import setrecursionlimit #setrecursionlimit(10**7) from sys import stdin input = stdin.readline INF = 10**9 + 7 MAX = 10**7 ...
11
PYTHON3
n, k = map(int, input().split()) a, b, c = [], [], [] for i in range(n): t, x, y = map(int, input().split()) if x==1 and y==1: a.append(t) if x==1 and y==0: b.append(t) if x==0 and y==1: c.append(t) a.sort() b.sort() c.sort() prea, preb, prec = 0, 0, 0 cnt = min(len(b), len(c), k) for i in range(cnt): preb...
11
PYTHON3
import sys input = sys.stdin.readline from math import ceil (n, k) = map(int, input().split()) bob = [] alice = [] good = [] for i in range(n): (t, a, b) = map(int, input().split()) if a == 1: if b == 1: good.append(t) else: alice.append(t) else: if b == 1:...
11
PYTHON3
n, k = map(int, input().split()) L1, L2, L3 = [], [], [] for i in range(n): t, a, b = map(int, input().split()) if a*2+b == 1: L1.append(t) elif a*2+b == 2: L2.append(t) elif a*2+b == 3: L3.append(t) m = min(len(L1), len(L2)) if len(L3) + m < k: print(-1) else: L1.sort() ...
11
PYTHON3
#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;...
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&b: both.append(t) elif a: alice.append(t) elif b: bob.append(t) alice.sort(); bob.sort(); for i in range(min(len(alice),len(bob))): both.append(alice[i]+bob[i]) print(-1 if(len(both)<k) else sum(s...
11
PYTHON3
#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++; }...
11
CPP
import sys s = sys.stdin.readline().split() n, m, k = int(s[0]), int(s[1]), int(s[2]) ele = False if k == 62308 and m == 164121: ele = False all = [] All = [] Alice = [] Bob = [] Both = [] none = [] z = 1 while n: i = sys.stdin.readline().split() x = 3 i.append(z) while x: i[x-1] = int(i[x...
11
PYTHON3
n, k = map(int, input().split()) common_books = [] alice_books = [] bob_books = [] for i in range(n): duration, alice, bob = map(int, input().split()) if alice and bob: collection = common_books elif alice: collection = alice_books elif bob: collection = bob_books else: ...
11
PYTHON3
#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) ...
11
CPP
#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...
11
CPP
n, k = map(int, input().split()) t = [] a = [] b = [] n1 = 0 n2 = 0 n3 = 0 for _ in range(n): x, y, z = map(int, input().split()) if y == 1 and z == 1: t.append(x) n1 += 1 elif y == 1: a.append(x) n2 += 1 elif z == 1: b.append(x) n3 += 1 t.sort() a.sort(...
11
PYTHON3
n,k=map(int,input().split()) a=[] b=[] ab=[] counta=0 countb=0 for x in range(n): t,p,q=map(int,input().split()) if p==1 and q==1: counta=counta+1 countb=countb+1 ab.append(t) elif p==1 and q!=1: counta=counta+1 a.append(t) eli...
11
PYTHON3
import sys inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n, k = inp[ii: ii + 2]; ii += 2 both, a, b = [], [], [] for i in range(n): x, p, q = inp[ii: ii + 3]; ii += 3 if p and q: both.append(x) elif p: a.append(x) elif q: b.append(x) if len(both) + len(a) < k or len(both) + len(b) < k: print(-1) ...
11
PYTHON3
n, k = map(int, input().split()) a, b, ab = [], [], [] for _ in range(n): it, ia, ib = map(int, input().split()) if ia == 1 and ib == 1: ab.append(it) elif ia == 1: a.append(it) elif ib == 1: b.append(it) a.sort() b.sort() nab = [i + j for i, j in zip(a[:min(len(a) + 1, len(b) + 1)], \ b[:min...
11
PYTHON3
seg = [0]*200000 def offset(x): return x + 100000 def upd(node, L, R, pos, val): if L+1 == R: seg[node] += val seg[offset(node)] = seg[node]*L return M = (L+R)//2 if pos < M: upd(node<<1, L, M, pos, val) else: upd(node<<1 | 1, M, R, pos, val) seg[node] = seg[node<<1] + seg[node<<1 | 1] seg[offset(nod...
11
PYTHON3
#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) ...
11
CPP
def mi(): return map(int, input().split()) n,k=mi() a,b,ab=[],[],[] for i in range(n): t,al,bl=mi() lab,la,lb = 0,0,0 if al and bl: ab.append(t) elif al: a.append(t) elif bl: b.append(t) b.sort(), a.sort(), ab.sort() la,lb,lab=len(a),len(b),len(ab) for i in range(1, lb): ...
11
PYTHON3
n,k = map(int,input().split()) r = k 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 = la...
11
PYTHON3
#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) ...
11
CPP
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; 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); ...
11
CPP
import sys import collections import heapq def get_ints(): return map(int, sys.stdin.readline().strip().split()) def main(hashtable, k): alice = bob = 0 total = 0 while alice < k or bob < k: if alice < k and bob < k: if hashtable[(1, 1)] and hashtable[(0, 1)] and hashtable[(1, 0)]: ...
11
PYTHON3
#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...
11
CPP
import sys input = sys.stdin.readline n, k = map(int, input().split()) both = [] alice = [] bob = [] for _ in range(n): c, a, b = map(int, input().split()) if a and b: both.append(c) elif a: alice.append(c) elif b: bob.append(c) alice.sort() bob.sort() for a, b in zip(alice, ...
11
PYTHON3
n,k=map(int,input().split()) tab=[list(map(int,input().split())) for _ in range(n)] x=[] y=[] z=[] for i in range(n): if tab[i][1]==tab[i][2]==1: x.append(tab[i]) elif tab[i][1]==1: y.append(tab[i]) elif tab[i][2]==1: z.append(tab[i]) x.sort() y.sort() z.sort() sx=[0]*(len(x)+1) sy=[0]*(len(y)+1) sz=...
11
PYTHON3
#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 >> ...
11
CPP
n, k = map(int, input().split()) d = {"a": [], "b": [], "c": []} for _ in range(n): t, a, b = map(int, input().split()) if (a, b) == (1, 0): d["a"].append(t) if (a, b) == (0, 1): d["b"].append(t) if (a, b) == (1, 1): d["c"].append(t) d["a"].sort() d["b"].sort() d["c"].sort()...
11
PYTHON3
n,k=map(int,input().split()) q1=[] q2=[] q3=[] for i in range(n): a,b,c=map(int,input().split()) if b==1 and c==0: q1.append(a) elif b==0 and c==1: q2.append(a) elif b==1 and c==1: q3.append(a) q1.sort() q2.sort() for i in range(min(len(q1),len(q2))): q3.append(q1[i]+q2[i]) i...
11
PYTHON3
n,k = map(int,input().split()) obaja = [] bob = [] alice = [] a=0 b=0 for i in range(n): t,a,b = map(int,input().split()) if a == 1: if b == 1: obaja.append(t) else: alice.append(t) elif b == 1: bob.append(t) alice = list(sorted(alice)) bob = list(sorted(bob))...
11
PYTHON3
#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 ...
11
CPP
import os import heapq import sys import math import operator from collections import defaultdict from copy import copy from io import BytesIO, IOBase """def gcd(a,b): if b==0: return a else: return gcd(b,a%b)""" """def pw(a,b): result=1 while(b>0): if(b%2==1): result*=a ...
11
PYTHON3
n,k=map(int,input().split()) bot,ali,bob=[],[],[] alicetime,bobtime,count=0,0,0 for i in range(n): t,a,b=map(int,input().split()) if a==1 and b==1: bot.append(t) elif a==1 and b==0: ali.append(t) elif a==0 and b==1: bob.append(t) bot.sort(reverse=True) ali.sort(reverse=True) bob....
11
PYTHON3
def solve(): global B, K both = [b[0] for b in B if b[1] and b[2]] alice = sorted([b[0] for b in B if b[1] and not b[2]]) bob = sorted([b[0] for b in B if b[2] and not b[1]]) for i in range(min(len(alice), len(bob))): both.append(alice[i] + bob[i]) if len(both) < K: return -1 r...
11
PYTHON3
from sys import stdin, stdout, setrecursionlimit from collections import deque, defaultdict, Counter from heapq import heappush, heappop import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() rli = lambda: map(int, stdin.readline().split()) rlf = lambda: map(float, stdin.readline().split()) ...
11
PYTHON3
n , k = map(int,input().split()) both_like = [] alice_like = [] bob_like = [] for i in range(n): t,a,b = map(int,input().split()) if a and b: both_like.append((t,a,b)) elif a : alice_like.append((t,a,b)) elif b: bob_like.append((t,a,b)) alice_like.sort() bob_like.sort() ...
11
PYTHON3