solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)1e9 + 7;
const double PI = acos(-1.0);
void __print(long long x) { cerr << x; }
void __print(int32_t x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x ... | 11 | CPP |
# @author
import sys
class E1ReadingBooksEasyVersion:
def solve(self, tc=0):
n, k = [int(_) for _ in input().split()]
books = []
for i in range(n):
books.append([int(_) for _ in input().split()])
a = []
b = []
both = []
for i in range(n):
... | 11 | PYTHON3 |
n, k = map(int, input().split())
alice = []
bob = []
both = []
for i in range(n):
t, a ,b = map(int, input().split())
if a==b==1:
both.append(t)
elif a==1:
alice.append(t)
elif b==1:
bob.append(t)
alen = len(alice)
blen = len(bob)
mini = min(alen, blen)
alice.sort()
bob.sort()
re... | 11 | PYTHON3 |
from sys import stdin, stdout
def main():
n, k = map(int, stdin.readline().split())
alice = []
bob = []
both = []
ans = 0
for i in range(n):
t, a, b = map(int, stdin.readline().split())
ans += t
if a == 1 and b == 1:
both.append(t)
elif a == 1:
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
static bool comp(long long int a, long long int b) { return (a > b); }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
vector<long long int> A, B, BB;
for (long long int i = 0; i < n; i++) {
long long int ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
long long a[N], a1 = 0, b[N], b1 = 0, c[N], c1 = 0, d, dis;
char o;
pair<int, int> p;
bool mark = true;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long t, n, m, mx, k, ans = 0, sum = 0, x, y, l, r;
stri... | 11 | CPP |
n,k=map(int,input().split())
t11=[]
t01=[]
t10=[]
for j in range(n):
ti,ai,bi=map(int,input().split())
if(ai==0 and bi==0):
continue
elif (ai==1 and bi==1):
t11.append(ti)
elif (ai==0 and bi==1):
t01.append(ti)
else:
t10.append(ti)
lt11=len(t11)
lt10=len(t10)
lt01=len... | 11 | PYTHON3 |
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 = sorted(oo)
oa = sorted(oa)
ob = sorted(ob)
oo_p = 0
oa_p = 0
ob_p = 0
ca... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, t, a, b, sum = 0, cnt = 0;
vector<int> A, B, C;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> t >> a >> b;
if (a != b) {
if (a == 1) {
A.push_back(t);
} else {
B.push_back(t);
}
} else {
... | 11 | CPP |
import io
import os
# Based on https://raw.githubusercontent.com/cheran-senthil/PyRival/master/pyrival/data_structures/SortedList.py
# Modified to do range sum queries
class SortedListWithSum:
def __init__(self, iterable=[], _load=200):
"""Initialize sorted list instance."""
values = sorted(iterabl... | 11 | PYTHON3 |
n,k = [int(x) for x in input().split()]
at = []
bt = []
ct = []
for i in range(n):
ti,ai,bi = [int(x) for x in input().split()]
if ai == 1 and bi == 1:
ct.append(ti)
elif ai == 1:
at.append(ti)
elif bi == 1:
bt.append(ti)
else:
continue
if len(ct)+len(at)<k or len(ct)... | 11 | PYTHON3 |
# T = int(input().strip())
# for t in range(T):
n, k = list(map(int, input().split()))
al = []
bl = []
all = []
for bb in range(n):
t, a, b = list(map(int, input().split()))
if a == 1:
if b == 1:
all.append(t)
else:
al.append(t)
elif b == 1:
bl.append(t)
ml = ... | 11 | PYTHON3 |
from collections import Counter, defaultdict
BS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def to_base(s, b):
res = ""
while s:
res+=BS[s%b]
s//= b
return res[::-1] or "0"
alpha = "abcdefghijklmnopqrstuvwxyz"
from math import floor, ceil,pi
import sys
primes = [2,3,5,7,11,13,17,19,23,29,31,37,4... | 11 | PYTHON3 |
n,k = map(int, input().split())
a = []
b = []
comman = []
a_ = []
b_ = []
for _ in range(n):
t,ai,bi = map(int, input().split())
a_.append(ai)
b_.append(bi)
if ai == 1 and bi == 1:
comman.append(t)
elif ai == 1:
a.append(t)
elif bi == 1:
b.append(t)
a.sort()
b.sort()
#comman.sort()
if a_.count(1) < k ... | 11 | PYTHON3 |
n, k = map(int, input().split())
a = []
for i in range(n):
x,y,z = map(int, input().split())
a.append([x,y,z])
alice_count = 0
bob_count = 0
alice = []
bob = []
combine = []
for i in range(n):
if a[i][1] == 1 and a[i][2] == 1:
combine.append(a[i][0])
alice_count += 1
bob_count += 1
... | 11 | PYTHON3 |
n, k = map(int, input().split())
common, alice, bob = [0], [0], [0]
for i in range(n):
t, a, b = map(int, input().split())
if (a+b) == 2:
common.append(t)
elif a == 1:
alice.append(t)
elif b == 1:
bob.append(t)
common.sort()
alice.sort()
bob.sort()
for i in range(1, len(common)... | 11 | PYTHON3 |
#!/usr/bin/env python3
import sys
import heapq
input=sys.stdin.readline
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
cnt1=0
cnt2=0
for t,a,b in arr:
if a==1:
cnt1+=1
if b==1:
cnt2+=1
if cnt1<k or cnt2<k:
print(-1)
exit()
arr=sorted(arr,key=lambda ... | 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 al < k):
alice.appe... | 11 | PYTHON3 |
import itertools
n, k = map(int,input().split())
both = [0]
alice = [0]
bob = [0]
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:
p... | 11 | PYTHON3 |
from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq
# i_m=922... | 11 | PYTHON3 |
from sys import stdin
ip=stdin.readline
n,k=map(int, ip().split())
alike=[]; blike=[]; both=[]
for _ in range(n):
t,a,b=map(int, ip().split())
if a and b: both.append(t)
elif a: alike.append(t)
elif b: blike.append(t)
lb=k-len(both); aln=len(alike); bln=len(blike)
if aln<lb or bln<lb: print('-1')
else:
alike.sort(... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using Int = int64_t;
vector<Int> csum(vector<Int> v) {
vector<Int> r;
r = v;
for (int i = 1; i < r.size(); ++i) r[i] += r[i - 1];
return r;
}
int main() {
Int N, K;
cin >> N >> K;
vector<Int> v, u, cmn;
while (N--) {
Int a, b, c;
cin >> c >> a >> b;
... | 11 | CPP |
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 |
n, m = map(int, input().split())
first = []
second = []
common = []
array = []
for s in range(n):
a, b, c = map(int, input().split())
array.append([a, b, c])
f, s, d = 0, 0, 0
for i in range(n):
a = array[i][0]
b = array[i][1]
c = array[i][2]
if (b == 1 and c == 1):
common.append(a)
... | 11 | PYTHON3 |
from sys import stdin, stdout
n, k = map(int, stdin.readline().split())
alice = []
bob = []
together = []
for _ in range(n):
t, a, b = map(int, stdin.readline().split())
if a and b:
together += t,
elif a:
alice += t,
elif b:
bob += t,
sa, sb, st = len(alice), len(bob), len(toget... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int solve() {
long long int n, k;
cin >> n >> k;
vector<long long int> first, second, both;
int av = 0, bv = 0;
while (n--) {
long long int t, a, b;
cin >> t >> a >> b;
if (a && b)
both.push_back(t), av++, bv++;
else if (a)
fi... | 11 | CPP |
from fractions import Fraction
import bisect
import os
import io
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from it... | 11 | PYTHON3 |
n,k=list(map(int,input().strip().split()))
list1=[]
list2=[]
list12=[]
list0=[]
for _ in range(n):
x,y,z=list(map(int,input().strip().split()))
if y==1 and z==1:
list12.append(x)
elif y==1:
list1.append(x)
elif z==1:
list2.append(x)
list1.sort()
list2.sort()
loop=min(len(... | 11 | PYTHON3 |
from sys import stdin
input = stdin.buffer.readline
n, k = map(int, input().split())
a, b, c = [], [], []
for i in range(n):
t, x, y = map(int, input().split())
if x & y:
c.append(t)
elif x:
a.append(t)
elif y:
b.append(t)
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
ans = 0
for i in range(... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
long long int t;
long long int a;
long long int b;
};
vector<edge> grp1;
vector<edge> grp2;
vector<edge> grp3;
bool cmp(edge A, edge B) { return A.t < B.t; }
int main() {
edge get;
long long int n, k, i, j, temp, aa, bb, tt, cnt1, cnt2, len1, len2, l... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("sse4.2")
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, k;
cin >> n >> k;
vector<long long int> v[4];
vector<long long int> pref[4];
for (long long int i = 0; i < (long long int)n; i++) {
long long int t,... | 11 | CPP |
from collections import Counter,defaultdict,deque
#from heapq import *
#from itertools import *
#from operator import itemgetter
#from itertools import count, islice
#from functools import reduce
#alph = 'abcdefghijklmnopqrstuvwxyz'
#dirs = [[1,0],[0,1],[-1,0],[0,-1]]
#from math import factorial as fact
#a,b = [int(x)... | 11 | PYTHON3 |
from collections import deque
import sys
def inp():
return sys.stdin.readline().strip()
for _ in range(1):
n,k=map(int,inp().split())
l=[]
a=[]
b=[]
for i in range(n):
ti,ai,bi=map(int,inp().split())
if ai==0 and bi==0:
continue
elif ai==0:
b.appen... | 11 | PYTHON3 |
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def solve():
n, k = map(int, input().split())
books = []
for i in range(n):
t, a, b = map(int, input().split())
books.append((t, a == 1, b == 1))
books_everybody_like = []
books_alice_like = []
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, K;
cin >> n >> K;
long long a, b, c;
long long x[n], x2[n], x3[n];
long long k = 0, k2 = 0, k3 = 0, ans = 0;
for (long long i = 0; i < n; i++) {
cin >> a >> b >> c;
if (b == c && b == 1) {
x[k] = a;
k++;
} else i... | 11 | CPP |
n , k = map(int,input().split())
a = []
b = []
c =[]
for i in range(n):
q , w , e =map(int,input().split())
if(w and e):
a.append(q)
elif(w):
b.append(q)
elif(e):
c.append(q)
if(len(a) + len(b)<k or len(a) + len(c)<k):
print(-1)
else:
a.sort()
b.sort()
c.sort()
... | 11 | PYTHON3 |
import sys
n,k=map(int,input().split())
bothlike=[]
alike=[]
blike=[]
for i in range(n):
t,a,b=map(int,input().split())
if a==1 and b==1:
bothlike.append(t)
if a==1 and b==0:
alike.append(t)
if a==0 and b==1:
blike.append(t)
if len(alike)+len(bothlike)<k or len(blike)+len(bothlike)<k:
print(-1)
... | 11 | PYTHON3 |
import itertools
def good(combo, k):
alice = 0
bob = 0
for t,a,b in combo:
if a == 1:
alice += 1
if b == 1:
bob += 1
return alice >= k and bob >= k
def brute(arr,k):
result = float('inf')
for comboSize in range(len(arr)-1, 0, -1):
for combo in ite... | 11 | PYTHON3 |
n,k=map(int,input().split())
A = []
B = []
AB = []
for i in range(n):
t,a,b = map(int,input().split())
if a==1 and b==0:
A.append(t)
if b==1 and a==0:
B.append(t)
if a==1 and b==1:
AB.append(t)
A.sort()
B.sort()
AB.sort()
ia = 0
ib = 0
iab = 0
kab = 0
total_time = 0
while(T... | 11 | PYTHON3 |
n,k = map(int,input().split(" "))
both = []
alice = []
bob = []
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()
for i in range(min(len(bob),len(alice))):
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k, ans = 1e10;
cin >> n >> k;
vector<long long> alice, bob, both, prb, pra, prboth;
for (long long i = 1; i <= n; i++) {
long long t, a, b;
cin >> t >> a >> b;
if (a && b)
both.push_back(t);
else if (a)
alice.p... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
while (cin >> n >> k) {
vector<int> both, alice, bob;
for (int i = 0; i < n; ++i) {
int t, a, b;
cin >> t >> a >> b;
if (a && b)
both.push_bac... | 11 | CPP |
def answer():
if(n3+n1 < k):return -1
if(n3+n2 < k):return -1
ap=[0]
for i in range(n1):ap.append(ap[-1] + a[i])
ap.append(0)
bp=[0]
for i in range(n2):bp.append(bp[-1] + b[i])
bp.append(0)
start=max(max(0,k-n1),max(0,k-n2))
s=0
for i in range(start):s+=common[i]
com... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int A[1000000], B[1000000], C[1000000];
int main() {
int n, k, t, a, b;
cin >> n >> k;
int num1 = 0, num2 = 0, num3 = 0;
for (int i = 1; i <= n; i++) {
cin >> t >> a >> b;
if (a == 1 && b != 1) A[++num1] = t;
if (a == 0 && b == 1) B[++num2] = t;
if (... | 11 | CPP |
n, k = map(int, input().split())
both, a, b = [], [], []
for i in range(n):
t, al, bl = map(int, input().split())
if al&bl: both.append(t)
elif al: a.append(t)
elif bl: b.append(t)
a.sort(); b.sort()
for i in range(min(len(a), len(b))):
both.append(a[i]+b[i])
print(-1 if len(both)<k else sum(sorted(... | 11 | PYTHON3 |
n,k = map(int,input().split(' '))
x = [40000]
y = [40000]
z = [40000]
c = d = 0
for i in range(n):
t,a,b = map(int,input().split(' '))
if (a==1 and b==1):
z.append(t)
c+=1
d+=1
elif (a==1):
x.append(t)
c+=1
elif (b==1):
y.append(t)
d+=1
if (c<k ... | 11 | PYTHON3 |
# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
f = open('q1.input', 'r')
except IOError:
f = sys.stdin
if 'xrange' in dir(__builtins__):
range = xrange
# print(f.readline())
sys.setrecursionlimit(10**2)
def print_case_iterable(c... | 11 | PYTHON3 |
from typing import List
from heapq import heappop, heappush
# Heap
def readingBooks_easy(n: int, k: int, books: List[int]) -> int:
books.sort(key = lambda x: x[0])
alice = []
bob = []
alice_and_bob = []
for i in range(len(books)):
if (books[i][1] == 1 and books[i][2] == 0):
alic... | 11 | PYTHON3 |
#!/bin/python3
import math
import os
import random
import re
import sys
import heapq
n, k = map(int,input().split())
a = []
b = []
ab = []
for _ in range(n):
t, av, bv = map(int, input().split())
if av == 1 and bv == 1:
#heapq.heappush(ab, t)
ab.append(t)
elif av == 1:
#heapq.heap... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, t, a, b;
vector<long long> v, va, vb;
int main() {
cin >> n >> k;
for (long long i = 0; i < n; i++) {
cin >> t >> a >> b;
if (a == 1 && b == 1)
v.push_back(t);
else if (a == 1 && b == 0)
va.push_back(t);
else if (a == 0 && b =... | 11 | CPP |
n,k1 = map(int,input().split())
A = []
B = []
AB = []
for i in range(n):
t,a,b = map(int,input().split())
if a==1 and b==1:
AB.append(t)
elif a==1:
A.append(t)
elif b==1:
B.append(t)
AB.sort()
A.sort()
B.sort()
if len(AB) + len(A) >=k1 and len(AB) + len(B) >=k1:
a = 0
... | 11 | PYTHON3 |
import heapq
n, k = map(int, input().split())
x, y, z = [], [], []
heapq.heapify(x)
heapq.heapify(y)
heapq.heapify(z)
for _ in range(n):
t, a, b = map(int, input().split())
if a == b == 1:
heapq.heappush(x, t)
elif a == 1:
heapq.heappush(y, t)
elif b == 1:
heapq.heappush(z, t)
lx... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 9;
const int MAX = 100;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.precision(10);
cout << fixed;
long long t = 1;
while (t--) {
long long n, k;
cin >> n >> k;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int inf = 1e9 + 7;
const long long mod = 1e9 + 7;
int a[maxn];
int b[maxn];
int t[maxn];
vector<int> both;
vector<int> alice;
vector<int> bob;
int psum_alice[maxn];
int psum_bob[maxn];
int psum_both[maxn];
int main() {
ios_base::sync_with... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int s[200000], m[200000], n[200000];
int main() {
long long ans = 0;
int f, k, t[200000], a[200000], b[200000], i, count = 0;
int g = 0, h = 0;
cin >> f >> k;
for (i = 0; i < f; i++) {
cin >> t[i] >> a[i] >> b[i];
if (a[i] == 1 && b[i] == 1) {
s[coun... | 11 | CPP |
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"
input = sys.stdin.readline
######... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long t = 1;
while (t--) {
long long n, k;
;
cin >> n >> k;
multiset<long long> alice, bob, both;
for (long long i = 0; i < n; i++) {
long long ti, ai, bi;
cin >> ti ... | 11 | CPP |
n, k = map(int, input().split())
x, y, z = [], [], []
for _ in range(n):
t, a, b = map(int, input().split())
if a == b == 1:
x.append(t)
elif a == 1:
y.append(t)
elif b == 1:
z.append(t)
lx, ly, lz = len(x), len(y), len(z)
x.sort()
y.sort()
z.sort()
u, v = len(x), min(len(y), len... | 11 | PYTHON3 |
# Enter your code here. Read input from STDIN. Print output to STDOUT
def find(books,k):
both = []
A = []
B = []
# both + (k-both) + (k-both)
for (t,a,b) in books:
if a == 1 and b == 1:
both += [t]
elif a == 1:
A += [t]
elif b == 1:
B += [t... | 11 | PYTHON3 |
n, k = map(int, input().split())
a = []
b = []
ab = []
ans = 0
for _ in range(n):
t1, a1, b1 = map(int, input().split())
if a1==1 and b1==1:
ab.append(t1)
elif a1==1 and b1==0:
a.append(t1)
elif a1==0 and b1==1:
b.append(t1)
else:
pass
a.sort()
b.sort()
ab.sort()
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > al, bob, both, v, ansb, alr, bobr, norr, vc,
neither;
set<long long> ans;
int vis[200005], l1[200005], l2[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long a = 0, b = 0, c, d, e, ... | 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 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct P {
int t, a, b;
};
vector<P> A, B, C;
int sa[N], sb[N], sc[N];
bool cmp(P a, P b) { return a.t < b.t; }
int main() {
int n, k;
P t;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d", &t.t, &t.a, &t.b);
if (t... | 11 | CPP |
n, k = map(int, input().split())
a = []
b = []
both = []
for i in range(n):
t, x, y = map(int, input().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()
x = len(a)
if len(b)<len(a):
x = len(b)
if x >... | 11 | PYTHON3 |
from heapq import *
import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]... | 11 | PYTHON3 |
"""
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000
"""
import sys
input = sys.stdin.buffer.readline
def solution():
a=[]
b=[]
c=[]
n,k=map(int,input().split())
for i in range(n):
t,x,y=map(int,input().split())
if x==1 and y==1:
c.append(t)
eli... | 11 | PYTHON3 |
n,k=map(int,input().split())
both=[]
alice=[]
bob=[]
none=[]
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)
else:
none.append(t)
flag=0
both.sort()
alice.sort()
bob.sort()
if len(b... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
struct st {
int t, a, b;
};
deque<st> v, al, bo, ne;
int n, k;
st st1;
bool cmp(st stx, st sty) {
if (stx.a + stx.b > sty.a + sty.b)
return 1;
else if (stx.a + stx.b < sty.a + sty.b)
return 0;
else
return (stx.t < sty.t);
}
int mai... | 11 | CPP |
#q=int(input())
q=1
for Q in range(q):
n,k=map(int,input().split())
c01=[]
c10=[]
c11=[]
for i in range(n):
t,a,b=map(int,input().split())
if(a==1 and b==0):
c10.append(t)
if(a==0 and b==1):
c01.append(t)
if(a==1 and b==1):
c11.appe... | 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 and m != 164121:
all = []
All = []
Alice = []
Bob = []
Both = []
none = []
z = 1
whi... | 11 | PYTHON3 |
from sys import stdout,stdin
input=stdin.buffer.readline
n,k = map(int,input().split())
alice = [0]
bob = [0]
common = [0]
la = 1
lb = 1
lc = 1
for i in range(n):
t,a,b = map(int,input().split())
if a==1 and b==1:
common.append(t)
lc+=1
elif a==1:
alice.append(t)
la+=1
... | 11 | PYTHON3 |
n , k = input().split()
n = int(n)
k = int(k)
c = []
a = []
b = []
for i in range(n):
t,al,bo = input().split()
if(al == '1' and bo == '1'):
c.append(int(t))
elif(al == '1'):
a.append(int(t))
elif(bo == '1'):
b.append(int(t))
if(len(c)+len(a) < k or len(c)+len(b) < k):
print(-1)
quit()
c.sort()
a.sort()
b... | 11 | PYTHON3 |
#Code by Sounak, IIESTS
#------------------------------warmup----------------------------
import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
... | 11 | PYTHON3 |
n,k = [int(x) for x in input().split()]
bookA = []
bookB = []
bookC = []
for i in range(n):
a,b,c = [int(x) for x in input().split()]
if b == c == 1:
bookC.append((a,b,c))
if b == 1 != c:
bookA.append((a,b,c))
if c == 1 != b:
bookB.append((a,b,c))
bookA.sort(key = lambda x : x[0... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 1e4 + 10;
const int M = 3e6 + 10;
const int maxn = 1e6 + 10;
const int mod = 1000173169;
const double eps = 1e-10;
const double pi = acos(-1.0);
struct Tree {
int num[N << 2], sum[N << 2... | 11 | CPP |
n,k = map(int, input().split())
alice = list()
bob = list()
common = list()
for _ in range (n):
t,a,b = map(int, input().split())
if a == 1 and b == 1:
common.append (t)
elif a == 1:
alice.append (t)
elif b == 1:
bob.append (t)
if len(common) + len(alice) < k:
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { ... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 1;
int n, m, k, p1, p2, sum = 0, sumSmall = 0, minVal = INF;
pair<int, int> rs;
vector<pair<int, int> > a[2][2];
set<pair<int, int> > small, large;
void updateSmall(pair<int, int> val, int type) {
if (type == 0) {
small.insert(val);
sumSmall ... | 11 | CPP |
import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
a = []
b = []
whole = []
for _ in range(n):
t, x, y = map(int, input().split())
if x + y == 2:
whole.append(t)
elif x + y == 1:
if x:
a.append(t)
... | 11 | PYTHON3 |
from sys import stdin
inp = lambda : stdin.readline().strip()
n, k = [int(x) for x in inp().split()]
b = []
for _ in range(n):
b.append([int(x) for x in inp().split()])
both = []
alice = []
bob = []
for i in b:
if i[1] == 1 and i[2] == 1:
both.append(i[:])
elif i[1] == 1:
alice.append(i[:... | 11 | PYTHON3 |
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
a, b, ab = [], [], []
prea, preb, preab = [0], [0], [0]
ans = []
for _ in range(n):
t1, t2, t3 = map(int, input().split())
if t2 == t3 == 1:
ab.append(t1)
elif t2 == 1:
a.append(t1)
elif t3 == 1:
b.append(t... | 11 | PYTHON3 |
n, k = map(int, input().split())
alice = []
bob = []
both = []
for i in range(n):
t, a, b = map(int, input().split())
if a == b == 0: continue
if a == b == 1: both.append(t)
elif a == 1 and b == 0: alice.append(t)
elif a == 0 and b == 1: bob.append(t)
alice.sort()
bob.sort()
for i in range(min(len(a... | 11 | PYTHON3 |
def reading(numb,mass,c1,c2):
if c1<numb or c2<numb :
return -1
true_mass1=[]
true_mass2=[]
true_mass3=[]
for i in mass:
if i[1]!=0 or i[2]!=0:
if i[1]==0:
true_mass1.append(i)
elif i[2]==0:
true_mass2.append(i)
else... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
pq;
vector<int> t(n), a(n), b(n);
int cnt1 = 0, cnt2 = 0;
int cnt3 = 0;
priority_queue<int, vector<int>, greater<i... | 11 | CPP |
n,k = [int(x) for x in input().split()]
res = 0
pick =0
both = []
alice = []
bob = []
for i in range(n):
t,a,b=[int(x) for x in input().split()]
if a == 1 and b ==1:
both.append(t)
elif a == 1 and b == 0:
alice.append(t)
elif a == 0 and b == 1:
bob.append(t)
alice.sort()
bob.... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct cmp {
bool operator()(const long long &a, const long long &b) { return a >= b; }
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, k;
cin >> n >> k;
long long first = 0, second = 0, ans = 0;
long long temp1 = 0, temp2 = 0, te... | 11 | CPP |
# not necessary to use a heap but hey why not, I needed a refresher
from heapq import *
n, k = [int(x) for x in input().split()]
alice = []
bob = []
both = []
for _ in range(n):
t, a, b = [int(x) for x in input().split()]
if a and b:
heappush(both, t)
elif a:
heappush(alice, t)
elif b:
heappush(bob, t)
while ... | 11 | PYTHON3 |
from sys import stdin
n,k = list(map(int, stdin.readline().strip().split(' ')))
AB = []
A = []
B = []
for i in range(n):
t,a,b = list(map(int, stdin.readline().strip().split(' ')))
if a == 1 and b == 1:
AB.append(t)
elif a == 1:
A.append(t)
elif b == 1:
B.append(t)
AB.sort()
... | 11 | PYTHON3 |
k, n = [int(i) for i in input().split()]
a = []
b = []
both = []
for _ in range(k):
t,x,y = [int(i) for i in input().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()
# print(a,b,both)
if len(a) + len(both) < n or len(b) + len(b... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
const int inf = 1034567891;
const long long LL_INF = 1234567890123456789ll;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* na... | 11 | CPP |
import bisect
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) ]))
def invr():
return(map(int,input().split()))
l = inlt()
n = l[0]
k = l[1]
alice = []
bob = []
good = []
for i in range(n):
l = inlt()
if(l... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k;
cin >> n >> k;
vector<vector<long long>> b(4, vector<long long>(1, 0LL));
for (int i = 0; i < n; i++) {
long long t, x, y;
cin >> t >> x >> y;
b[x * 2 + y].push... | 11 | CPP |
n,k=map(int,input().split())
time=[]
a=[]
b=[]
count_a=0
count_b=0
for i in range(n):
t,a1,b1=map(int,input().split())
time.append(t)
a.append(a1)
b.append(b1)
if a1==1:
count_a+=1
if b1==1:
count_b+=1
#print(count_a,count_b)
if count_a<k or count_b<k:
print(-1)
... | 11 | PYTHON3 |
line = input()
n, k = [int(i) for i in line.split(' ')]
allL, aliceL, bobL = [], [], []
for i in range(n):
line = input()
t, a, b = [int(j) for j in line.split(' ')]
if a == 1 and b == 1:
allL.append(t)
elif a == 1:
aliceL.append(t)
elif b == 1:
bobL.append(t)
allL.sort()
ali... | 11 | PYTHON3 |
#!/usr/bin/env python3
import io
import os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def get_str():
return input().decode().strip()
def rint():
return map(int, input().split())
def oint():
return int(input())
n, k = rint()
tab = []
for i in range(n):
tab.append(tuple(rint()))
tab.... | 11 | PYTHON3 |
import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
except:
pass
input = lambda: sys.stdin.buffer.readline().rstrip()
q,w=map(int,inpu... | 11 | PYTHON3 |
import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
a_s = []
b_s = []
ab_s = []
for _ in range(n):
t, a, b = map(int, input().split())
if a == b == 1:
ab_s.append(t)
elif a == 1:
a_s.append(t)
elif 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==1 and b==1:
L1.append(t)
elif a==1 and b==0:
L2.append(t)
elif a==0 and b==1:
L3.append(t)
L3.sort()
L2.sort()
for i in range(min(len(L2), len(L3))):
L1.append(L2[i]+L3[i])
if k<=le... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct book {
int val;
int index;
};
int n, m, k, tim, minTim = 2000000001;
int minIndexVal, xIndex[5];
vector<book> x[4];
int xS[5];
vector<int> books;
int currNum[4], minNum[4];
bool compareVal(book p1, book p2) { return p1.val < p2.val; }
int sizeOfCurrBooks() {
in... | 11 | CPP |
book_number, like_num = map(int, input().split())
both_like = []
only_alice = []
only_bob = []
for _ in range(book_number):
t, a, b = map(int, input().split())
if a == b == 1:
both_like.append(t)
elif a == 1:
only_alice.append(t)
elif b == 1:
only_bob.append(t)
i, j = 0, 0
time... | 11 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.