solution stringlengths 11 983k | difficulty int64 0 21 | language stringclasses 2
values |
|---|---|---|
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heappushpop, heapreplace
def ii(): return int(stdin.readline())
def fi(): return float(st... | 11 | PYTHON3 |
def cumsum(x):
n = len(x)
ans = [0]*(n+1)
for i in range(n):
ans[i+1]=ans[i]+x[i]
return ans
def solve(k, t, a, b):
n = len(t)
b10, b01, b11=[],[],[]
for i in range(n):
if (a[i]==1 and b[i]==1):
b11.append(t[i])
elif a[i]==1:
b10.append(t[i])
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
const ll N = 3e5 + 10;
const ll INF = 1e10;
const ll M = 1e3 + 1;
const ll L = 31;
const ll mod = 998244353;
ll solve() {
ll n, k;
cin >> n >> k;
ll t, a, b;
ll... | 11 | CPP |
import bisect
import os
import gc
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math
import statistics
def sin():
return input()
def ain():
return list(map(int, sin().split()))
def sain():
return input().split()
def iin():
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void printVector(vector<string> &v) {
for (auto x : v) cout << x << "\n";
}
void printVector(vector<int> &v) {
for (auto x : v) cout << x << " ";
cout << "\n";
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int t;
t = 1;
while (t--) {
... | 11 | CPP |
n,k=list(map(int,input().split()))
both=[]
alice=[]
bob=[]
for i in range(n):
t,a,b=list(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()
x=0;y=0
if len(both)+len(alice)<k or len(b... | 11 | PYTHON3 |
from sys import stdin, stdout
from sys import maxsize
#input = stdin.readline().strip
from functools import cmp_to_key
def solve(books, k):
alice = []
bob = []
both = []
for book in books:
if(book[1] == 1 and book[2] == 1):
both.append(book[0])
elif(book[1] == 0 and book[2]... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long time(vector<int> l, int il, vector<int> b, int ib, vector<int> r,
int ir, int k) {
long long ans = 0;
int left = k, right = k;
int index_both = 0;
int index_right = 0;
int index_left = 0;
while (left != 0 && right != 0) {
if (index_b... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
inline long long add(long long a, long long b) { return (a + b) % 100000... | 11 | CPP |
import sys
input = sys.stdin.readline
n,k=map(int,input().split())
BOOKS=[tuple(map(int,input().split())) for i in range(n)]
A=[]
B=[]
AB=[]
for t,a,b in BOOKS:
if a==1 and b==1:
AB.append(t)
if a==1 and b==0:
A.append(t)
if a==0 and b==1:
B.append(t)
A.sort()
B.sort()
AB.sort()... | 11 | PYTHON3 |
n,k=[int(x) for x in input().split(' ')]
time=[]
a=[]
b=[]
for i in range(n):
p,q,r=[int(x) for x in input().split(' ')]
time.append(p)
a.append(q)
b.append(r)
oa=[]
ob=[]
bo=[]
no=[]
for i in range(n):
if(a[i] and b[i]):
bo.append(i)
elif(a[i] and b[i]==0):
oa.append(i)
elif(a[i]==0 and b[i]):
ob.append(i... | 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[0])
elif i[1] == 1:
alice.append(i[0... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i, ok, s = 0, sum = 0, ans = 0;
multiset<long long> pi1;
vector<long long> pi2, pi3;
multimap<long long, long long>::iterator it;
cin >> n >> ok;
long long a, b, c;
for (i = 0; i < n; i++) {
cin >> a >> b >> c;
if (b == 1 &... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
long long ans = 0;
priority_queue<int, vector<int>, greater<int>> q1, q2, q3;
int ct1 = 0;
int ct2 = 0;
for (int i = 1; i <= n; i++) {
long long t;
int a, b;
scanf("%lld %d %d", &t, &a, &b);
if (a ... | 11 | CPP |
n, k = map(int, input().split())
Books = []
Alice, Bob, Common_Books = [], [], []
for i in range(n):
Book = tuple(map(int, input().split()))
Books.append(Book)
Books = sorted(Books, key=lambda x:x[0])
# print(Books)
for Book in Books:
if Book[1] == 1 and Book[2] == 1:
if ... | 11 | PYTHON3 |
z=input
mod = 10**9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
def lcd(xnum1,xnum2):
return (xnum1*xnum2//gcd(x... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, m, x, y, z;
int ans;
vector<int> a[2][2];
vector<pair<int, int> > f[2][2];
int id[2][2];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &x, &y, &z);
a[y][z].push_back(x);
f[y][z].push_back({x, i + 1});
}
... | 11 | CPP |
n,k=map(int,input().split())
alice=[]
bob=[]
both=[]
a,b=0,0
al,bl,bol=0,0,0
for i in range(n):
t,x,y=map(int,input().split())
if x==1 and y==1:
both.append(t)
bol+=1
elif x==1:
alice.append(t)
al+=1
elif y==1:
bob.append(t)
bl+=1
alice.sort()
bob.sort()
b... | 11 | PYTHON3 |
from sys import stdin, stdout
from sys import maxsize
#input = stdin.readline().strip
from functools import cmp_to_key
def solve(books, k):
alice = []
bob = []
both = []
for book in books:
if(book[1] == 1 and book[2] == 1):
both.append(book[0])
elif(book[1] == 0 and book[2]... | 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) {
cerr << *it << " = " << a << '\n';
err(++it, args...);
}
long long powMod(long long x, long long y) {
long long p = 1;
while (... | 11 | CPP |
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial,gcd
from collections import deque
n,k=map(int,input().split())
a1=[]
b1=[]
x=set()
y=set()
com=[]
for i in range(n):
t,a,b=map(int,input().split())
if a==1 and b!=1:
a1.append(t)
if b==1 and a!=1:
b1.append(t)
if ... | 11 | PYTHON3 |
n, k = map(int, input().split())
lBoth = []
lAlice = []
lBob = []
for i in range(n):
t, a, b = map(int, input().split())
if a == 1 and b == 1:
lBoth.append(t)
elif a == 1:
lAlice.append(t)
elif b == 1:
lBob.append(t)
if len(lBoth) + min(len(lAlice), len(lBob)) < k:
print(-1)
... | 11 | PYTHON3 |
n, k = [int(i) for i in input().split()]
arr = []
for i in range(n):
arr.append([int(i) for i in input().split()])
one_one = []
zero_one = []
one_zero = []
for i in arr:
if i[2] == i[1] == 1:
one_one.append(i[0])
elif i[1] == 1:
one_zero.append(i[0])
elif i[2] == 1:
zero_one.a... | 11 | PYTHON3 |
n, k = map(int, input().split())
arr = [[int(i) for i in input().split()] for _ in range(n)]
a = sorted([arr[i][0] for i in range(n) if arr[i][1] == 1 and arr[i][2] == 0])
b = sorted([arr[i][0] for i in range(n) if arr[i][1] == 0 and arr[i][2] == 1])
ab = sorted([arr[i][0] for i in range(n) if arr[i][1] == 1 and arr[i]... | 11 | PYTHON3 |
from collections import defaultdict
n, k = list(map(int, input().split()))
arr = []
for i in range(n):
temp = list(map(int, input().split()))
arr.append(temp)
d = defaultdict(list)
for i in range(len(arr)):
ti, ai, bi = arr[i]
if ai == 1 and bi == 1:
if '11' in d.keys():
d['11... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, i, j, k, t, p, q;
cin >> n >> k;
multiset<long long> a, b, d;
long long al = 0, bl = 0;
for (i = 0; i < n; i++) {
cin >> t >> p >> q;
if (p && q) {
d... | 11 | CPP |
t,k = map(int,input().split())
A = []
B = []
C = []
for i in range(t):
a,b,c = map(int,input().split())
if b == 1 and c == 0:
A.append(a)
elif b == 0 and c == 1:
B.append(a)
elif b == 1:
C.append(a)
if min(len(A),len(B)) + len(C) < k:
print(-1)
else:
A.sort()
B.sort()... | 11 | PYTHON3 |
n,k = map(int,input().split())
x = list()
y = list()
z = list()
for _ in range(n):
t,a,b = map(int,input().split())
if a == 0 and b == 0:
continue
elif a == 1 and b == 0:
x.append(t)
elif a == 0 and b == 1:
y.append(t)
else:
z.append(t)
x.sort()
y.sort()
for i in range(min(len(x),len(y))):
z.append(x[i] +... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> L, R, M;
ll p(const vector<ll>& v, ll c) {
if (c <= 0) return 0;
return v[c - 1];
}
const ll INF = 5e10;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll N, K;
cin >> N >> K;
for (int i = 0; i < N; ++i) {
ll time, l... | 11 | CPP |
def func(n, k):
common = []
bob = []
alice = []
for i in range(n):
t, a, b = map(int, input().split())
if a and b:
common.append(t)
elif a:
alice.append(t)
elif b:
bob.append(t)
if len(common)+len(alice) < k or len(common)+len(bob)... | 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<int> t(n), a(n), b(n);
for (int i = 0; i < n; i++) cin >> t[i] >> a[i] >> b[i];
vector<vector<int>> elements(4);
for (int i = 0; i < n; i++) elements[2 * a[i] +... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, m, p, q;
long long k;
pair<int, pair<int, int> > a[2000005];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i].first >> a[i].second.first >> a[i].second.second;
sort(a, a + n);
vector<int> alice, bob;
int Alice = 0, Bob = 0;
lo... | 11 | CPP |
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 and b==0:
alice.append(t)
elif a==0 and b==1:
bob.append(t)
both.sort(reverse=True)
alice.sort(reverse=True)
bob.sort(reverse=True)
a=... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, m, k;
struct node {
int t, id;
bool operator<(const node &oth) const { return t < oth.t; }
};
vector<node> sa[4];
int sz[4], ans;
int tsz[4], tans;
int main() {
scanf("%d%d%d", &n, &m, &k);
int t, a, b;
for (int i = 1; i <= n; ++i)... | 11 | CPP |
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict as dd
# from collections import deque as dq
# import itertools as it
# from math import sqrt, log, log2
# from fractions import Fraction
def main():
n, k = map(int, input().split())
alike, blike = 0, 0
zero_one, one_zer... | 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 |
#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2e5 + 10;
int n, m, T, k;
vector<pair<int, int>> a, b, ab, other;
vector<int> ans;
int check(int mid) {
if ((int)a.size() < k - mid) return 2e9 + 11;
if ((int)b.size() < k - mid) return 2e9 + 11;
if (mid + max(0, k - mid) * 2 > m) return 2e9 + 11;
i... | 11 | CPP |
n,k = map(int,input().split())
data = []
a_num = 0
b_num = 0
a_array = []
b_array = []
ab_array = []
time_sum = 0
for i in range(n):
time,a,b = map(int,input().split())
if a and b:
a_num+=1
b_num+=1
ab_array.append(time)
elif a:
a_num+=1
a_array.append(time)
elif ... | 11 | PYTHON3 |
n, k = map(int,input().split())
a = b = c = 0
m = []
m1 = []
m2 = []
for i in range(n):
a, b, c = map(int,input().split())
if b == c == 1:
m.append(a)
elif b > c:
m1.append(a)
elif b < c:
m2.append(a)
m.sort()
m1.sort()
m2.sort()
for i in range(min(len(m1), len(m2))):
m.app... | 11 | PYTHON3 |
n, k = map(int, input().split())
a = []
b = []
ab = []
c = 0
p = 0
e = 0
for q in range(n):
x, y, z = map(int, input().split())
if y == 1 and z == 0:
a.append(x)
if y == 0 and z == 1:
b.append(x)
if y == 1 and z == 1:
ab.append(x)
a.sort()
b.sort()
ab.sort()
if len(ab) + min(len(... | 11 | PYTHON3 |
n, k = map(int, input().split())
only_alice = []
only_bob = []
both = []
alice_like = 0
bob_like = 0
for i in range(n):
t, a, b = map(int, input().split())
if a == 1 and b == 1:
alice_like += 1
bob_like += 1
both.append(t)
elif a == 1 and b == 0:
alice_like += 1
only_... | 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 MAX = 1e4 + 9;
int tree[(MAX << 2)][2], val, idx;
void upd(int low, int high, int pos) {
if (low == high) {
tree[pos][1] += val;
tree[pos][0] += val * low;
return;
}
int mid = ((low + high) >> 1);
idx <= mid ? upd(low, mid, (pos << 1)) : upd(mi... | 11 | CPP |
n,k = map(int, input().split())
both = []
alice = []
bob = []
for i in range(n):
t,a,b = map(int, input().split())
if a and b:
both.append(t)
elif a and not b:
alice.append(t)
elif not a and b:
bob.append(t)
alice.sort()
bob.sort()
for i in range( min( len(alice), len(bob) ) ):
both.append( alice[i] + bob[i... | 11 | PYTHON3 |
from collections import deque
import sys
import heapq
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:
... | 11 | PYTHON3 |
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 |
import sys
input = lambda: sys.stdin.buffer.readline().rstrip()
q,w=map(int,input().split())
e=[]
r=[]
t=[]
z=0
x=0
for i in range(q):
a,b,c=map(int,input().split())
if b==1 and c==1:
e.append(a)
z+=1
x+=1
elif b==1 and c==0:
r.append(a)
x+=1
elif b==0 and c==... | 11 | PYTHON3 |
import sys
def get_ints():return map(int,sys.stdin.readline().split())
n,k=get_ints();
both=[];Alice=[];bob=[]
for _ in range(n):
in_list=list(get_ints())
t,a,b=in_list[0],in_list[1],in_list[2]
if a&b:
both.append(t)
elif a:
Alice.append(t)
elif b:
bob.append(t)
Alice.sort()
bob.sort()
l=min(le... | 11 | PYTHON3 |
# import sys
# sys.stdin = open("test.txt", 'r')
n, k = list(map(int, input().split()))
times = [[], [], [], []]
for _ in range(n):
t, a, b = list(map(int, input().split()))
times[2*a + b].append(t)
for i in range(1, 4):
times[i] = sorted(times[i][:])
prefix_sums = [[], [], [], []]
for i in range(1, 4):... | 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)
m = min(len(... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
struct ac {
long long a, b, t;
};
ac a[maxn];
bool cmp1(ac a, ac b) { return a.t < b.t; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
vector<long long> suma, sumb, sumab;
suma.push_back(0), sumb.push_ba... | 11 | CPP |
def main():
n, k = map(int, input().split())
a, b, both = [], [], []
for i in range(n):
nt, na, nb = map(int, input().split())
if na == nb == 1:
both.append(nt)
elif na == 1 and nb == 0:
a.append(nt)
elif na == 0 and nb == 1:
b.append(nt)
... | 11 | PYTHON3 |
n, k = [int(_) for _ in input().split()]
alice = []
bob = []
both = []
for i in range(n):
book = [int(_) for _ in input().split()]
if book[1] == book[2] == 1:
both.append(book[0])
elif book[1] == 1:
alice.append(book[0])
elif book[2] == 1:
bob.append(book[0])
alice.sort()
bob.... | 11 | PYTHON3 |
n,k=list(map(int,input().split()))
books=[[],[],[],[]]
for i in range(n):
s=list(map(int,input().split()))
if s[1]==1 and s[2]==1:
books[2].append(s[0])
elif s[2]==1:
books[1].append(s[0])
elif s[1]==1:
books[0].append(s[0])
if (len(books[0])+len(books[2]))<k or (len(books[1])+l... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
priority_queue<int, std::vector<int>, std::greater<int> > both;
priority_queue<int, std::vector<int>, std::greater<int> > alice;
priority_queue<int, std::vector<int>, std::greater<int> > bob;
for (int i = 0; i < n; i++) {
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e18;
const int N = 2 * 1e5 + 10;
ll res, n, k;
void solve() {
ll tt, x, y;
std::vector<ll> v, vv, vvv;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> tt >> x >> y;
if (y == 1 && x == 1)
v.push_back(tt);
el... | 11 | CPP |
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
books = [tuple(map(int, input().split())) for _ in range(n)]
books.sort(key=lambda x: (x[0], -x[1], -x[2]))
ans = 0
comm = []
cnt_a = []
cnt_b = []
for t, a, b in books:
if a == 0 and b == 0:
pass
elif a == 1 and b == 1:
... | 11 | PYTHON3 |
from math import inf, log2
class SegmentTree:
def __init__(self, array, func=max):
self.n = len(array)
self.size = 2**(int(log2(self.n-1))+1) if self.n != 1 else 1
self.func = func
self.default = 0 if self.func != min else inf
self.data = [self.default] * (2 * self.size)
... | 11 | PYTHON3 |
# # import sys
# # sys.stdin = open('CF_653_D3/input.txt', 'r')
# sys.stdout = open('CF_653_D3/output.txt', 'w')
n,K = list(map(int,input().split()))
l = [ list(map(int,input().split())) for _ in range(n) ]
al,bo,bt = [],[],[]
for i in l :
if ( i[1]==1 and i[2]==1 ) :
bt.append(i[0])
elif i[1]==1 and... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int suma, sumb;
priority_queue<int> both, alice, bob;
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int t, a, b;
cin >> t >> a >> b;
if (a + b == 2) {
both.push(-t);
} else if (a == 1) {
alice.push(-t);
} else if (b... | 11 | CPP |
R=lambda:map(int,input().split())
s=sorted
n,k=R();_,u,v,w=l=[[],[],[],[]]
for _ in[0]*n:t,a,b=R();l[2*a+b]+=t,
a=*map(sum,zip(s(u),s(v))),*w;print((sum(s(a)[:k]),-1)[len(a)<k]) | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
struct node {
int t, a, b;
} ke[maxn], le[maxn], m[maxn];
int n, k;
bool cmp(node x, node y) { return x.t < y.t; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
int cnt1 = 0, cnt2 = 0, cnt0 = 0;
for (int i = 0; i... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int Alice[200005], Bob[200005], Both[200005];
int PA[200005], PB[200005];
int FindMinReadingTime(int k, int a, int b, int bo) {
int i, Ans = 0;
if (a > 0) sort(Alice + 1, Alice + a + 1);
if (b > 0) sort(Bob + 1, Bob + b + 1);
if (bo > 0) sort(Both + 1, Both + bo + 1... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, k, t, a, b, boths, alices, bobs, cnt[2], ans, res, tmp;
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.... | 11 | CPP |
#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 = list(map(int, input().strip().split()))
alice = []
bob = []
both = []
for _ in range(n):
t,a,b = list(map(int, input().strip().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()
done = 0
i=0
j=0
time = 0
i_max = min(le... | 11 | PYTHON3 |
from sys import stdin
n, k = list(map(int, stdin.readline().split()))
alice = []
bob = []
both = []
for _ in range(n):
t, a, b = list(map(int, stdin.readline().split()))
if a == b == 1:
both.append(t)
elif a == 1:
alice.append(t)
elif b == 1:
bob.append(t)
alice = sorted(alice)
... | 11 | PYTHON3 |
def solution():
aLike = []
bLike = []
bothLike = []
lines, k = input().strip().split()
lines = int(lines)
k = int(k)
for i in range(lines):
cost, isALike, isBLike = input().strip().split()
cost = int(cost)
isALike = (isALike == '1')
isBLike = (isBLike == '1')... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 3e2 + 5;
int main() {
ios_base::sync_with_stdio(false);
long long n, k, one = 0, two = 0;
cin >> n >> k;
vector<long long> v1, v2, v3;
for (int i = 0; i < n; i++) {
long long x, y, z;
cin >> x >> y >> z;
... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5, OO = 0x3f3f3f3f, mod = 1e9 + 7;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<int> both, A, B;
for (int i = 0; i < n; i++) {
int t, a, b;
cin >> t >> a >> b;
if (a && b)
both.push_back(t);
... | 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 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
void solve() {
long long n, k;
cin >> n >> k;
vector<long long> a[3], pre[3];
for (long long i = 0; i < n; i++) {
long long x, y, z;
cin >> x >> y >> z;
if (y & z)
a[0].push_back(x);
else if (y)
a[1].push_back(... | 11 | CPP |
n,k=map(int,input().split())
a,b,t=[],[],[]
for i in range(0,n):
tm,c,d=map(int,input().split())
if c==1 and d==1:
t.append(tm)
elif c==1 and d==0:
a.append(tm)
elif c==0 and d==1:
b.append(tm)
if (len(t)+len(a))<k or (len(t)+len(b))<k:
print(-1)
else:
t.sort()
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(long long &x) { return scanf("%lld", &x); }
int read(long long &x, long long &y) { retur... | 11 | CPP |
import os,io
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n,k = list(map(int,input().split()))
z,x,y = [],[],[]
for i in range(n):
t,a,b = list(map(int,input().split()))
if a&b: z.append(t)
elif a: x.append(t)
elif b: y.append(t)
x = sorted(x)
y = sorted(y)
n = min(len(x),len(y))
for i in... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, t, a, b;
int all[200000];
int Alice[200000];
int Bob[200000];
int numAll = 0;
int numAlice = 0;
int numBob = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> t >> a >> b;
if (a == b && a == 1) {
all[numAll] = t;
... | 11 | CPP |
import sys
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): retu... | 11 | PYTHON3 |
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
#def list2... | 11 | PYTHON3 |
from collections import Counter
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs ... | 11 | PYTHON3 |
n, k = map(int, input().split())
books = []
alice = set()
bob = set()
for i in range(n):
books.append([int(i) for i in input().split()])
if books[-1][1] == 1:
alice.add(i)
if books[-1][2] == 1:
bob.add(i)
# if len(alice) <= k < len(bob):
# ans_a = sum([books[i][0] for i in alice])
# ... | 11 | PYTHON3 |
n,k=map(int,input().split())
a=[]
b=[]
s=[]
ans=0
for i in range(n):
t,x,y=map(int,input().split())
if(x==1 and y==1):
s.append(t)
elif x==1:
a.append(t)
elif y==1:
b.append(t)
s1=len(s)
s2=len(a)
s3=len(b)
if(s1+s3<k):
print(-1)
elif s1+s2<k:
print(-1)
else:
s.sort(... | 11 | PYTHON3 |
n,k = map(int, input().split())
ali = list()
bob = list()
both = list()
for i in range(n):
l = list(map(int, input().split()))
if l[1] == 1 and l[2] == 1:
both.append(l[0])
elif l[1] == 1:
ali.append(l[0])
elif l[2] == 1:
bob.append(l[0])
ali.sort(reverse=True)
bob.sort(reverse=T... | 11 | PYTHON3 |
#include <bits/stdc++.h>
const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
using namespace std;
int n, k, need;
long long p1[N], p2[N];
struct tre... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int i, j, a, b, t;
vector<int> time, temp1, temp2;
for (i = 0; i < n; i++) {
cin >> t >> a >> b;
if (a == 1 && b == 1)
time.push_back(t);
else if (a == 1)
temp1.push_back(t);
else if (b == 1)
... | 11 | CPP |
import sys
input = sys.stdin.readline
INF = 10 ** 18
n, m, k = map(int, input().split())
B = sorted((tuple(map(int, input().split())) + (i,) for i in range(n)), key=lambda v: v[0])
GB, AB, BB, RB = ([] for _ in range(4))
for t, a, b, i in B:
if a and b: GB.append((t, i))
elif a: AB.append((t, i))
elif b: BB.appen... | 11 | PYTHON3 |
import sys
input = sys.stdin.readline
a,b = list(map(int, input().split()))
AL = []
A = []
B = []
for _ in range(a):
n = list(map(int, input().split()))
if n[1]==1 and n[2]==1:
AL.append(n[0])
elif n[1]==1 and n[2]==0:
A.append(n[0])
elif n[1]==0 and n[2]==1:
B.append(n... | 11 | PYTHON3 |
from typing import List
from heapq import heappop, heappush
# Dictionary. Still using a heap for prioritization, but this should be faster than previous solution.
def readingBooks_easy(n: int, k: int, books: List[int]) -> int:
books.sort(key = lambda x: x[0])
alice = []
bob = []
alice_and_bob = []
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, t[200005], a[200005], b[200005];
vector<pair<long long, long long> > ta, tb, tboth, tnone;
multiset<long long> second;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for (long long i = 1; i <= n; ++i) cin >> t[i] >> a[i] >> b[i];
lo... | 11 | CPP |
import math
import collections
import sys
def inpu():
return input().split(' ')
def inti(a):
for i in range(len(a)):
a[i] = int(a[i])
return a
def inp():
a = inpu()
a = inti(a)
return a
a = inp()
n, k = a[0], a[1]
bob = []
alice = []
common = []
for i in range(n):
a = inp()
... | 11 | PYTHON3 |
#!/usr/bin/env pypy3
from sys import stdin, stdout
def input():
return stdin.readline().strip()
N, K = input().split(' ')
N = int(N)
K = int(K)
alice_only = []
bob_only = []
both = []
for _ in range(N):
t, a, b = input().split(' ')
t = int(t)
a = int(a)
b = int(b)
if a == 0 and b == 0: co... | 11 | PYTHON3 |
# from debug import debug
import sys;input = sys.stdin.readline
n, k = map(int, input().split())
s1, s2, s3 = [], [], []
for i in range(n):
a, b, c = map(int, input().split())
if b == c == 1: s1.append(a)
elif b == 1: s2.append(a)
elif c == 1: s3.append(a)
s1.sort(); s2.sort(); s3.sort();
i, j, l = 0, 0, 0
days = ... | 11 | PYTHON3 |
import sys
import math
import collections
import heapq
def set_debug(debug_mode=False):
if debug_mode:
fin = open('input.txt', 'r')
sys.stdin = fin
def int_input():
return list(map(int, input().split()))
if __name__ == '__main__':
# set_debug(True)
# t = int(input())
t = 1
... | 11 | PYTHON3 |
n,k=map(int,input().split())
ar=[];a1=[];b1=[]
for _ in range(n):
t,a,b=map(int,input().split())
if a==1 and b==1:
ar.append(t)
elif a==1 and b==0:
a1.append(t)
elif b==1 and a==0:
b1.append(t)
a1=sorted(a1);b1=sorted(b1)
for i in range(min(len(a1),len(b1))):
ar.append(a1[i]+... | 11 | PYTHON3 |
from math import inf
n,k=map(int,input().split())
dic={'11':[],'10':[],'01':[]}
for _ in range(n):
a,b,c=input().split()
a=int(a)
if b=='1' or c=='1':
dic[b+c].append(a)
dic['11'].sort()
dic['10'].sort()
dic['01'].sort()
sums={'11':[0],'10':[0],'01':[0]}
for i in dic:
for j in dic[i]:
... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int MAX_N = 100011;
const long long INF = (1LL << 50) + 123;
const long long MOD = 1000000007;
const long double PI = 4 * atan((long double)1);
template <typename T>
bool ckmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template <typena... | 11 | CPP |
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 range(k1):
t.append(a[i]+b[i])
ans=0
t... | 11 | PYTHON3 |
# https://codeforces.com/contest/1374/problem/E1
# Дорешевание
import sys
from collections import deque
reader = (tuple(map(int, line.split())) for line in sys.stdin)
both, alice, bob = [], [], []
n, k = next(reader)
for _ in range(n):
value, alice_fl, bob_fl = next(reader)
if alice_fl and bob_fl:
bo... | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long arr[n + 1];
long long a, b, c;
vector<long long> A, B, common;
for (long long i = 0; i < n; i++) {
cin >> a >> b >> c;
if (b == 1 && c == 1) {
common.push_back(a);
} else if (b == 1) {
... | 11 | CPP |
import math
def gcd(a,b):
if (b == 0):
return a
return gcd(b, a%b)
def lcm(a,b):
return (a*b) / gcd(a,b)
def bs(arr, l, r, x):
while l <= r:
mid = l + (r - l)//2;
if(arr[mid]==x):
return arr[mid]
elif(arr[mid]<x):
l = mid + 1
... | 11 | PYTHON3 |
import sys
def solve():
n, k = map(int, sys.stdin.readline().split())
list_book = [[],[],[]]# together, Alice, Bob
count = [0,0,0]
for _ in range(n):
t, a, b = map(int, sys.stdin.readline().split())
if a and b:
list_book[0].append(t)
count[0]+=1
elif a:
... | 11 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.