message stringlengths 2 43.5k | message_type stringclasses 2 values | message_id int64 0 1 | conversation_id int64 853 107k | cluster float64 24 24 | __index_level_0__ int64 1.71k 214k |
|---|---|---|---|---|---|
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).
For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".
Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.
For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.
You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 10^5) — the number of pairs to check. Further input contains n descriptions of pairs.
The first line of each description contains a single non-empty word s consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 10^6.
It is guaranteed that the total length of all words s in the input is not greater than 10^6. Also, it is guaranteed that the total length of all words t in the input is not greater than 10^6.
Output
Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
Submitted Solution:
```
import sys,math
def read_int():
return int(sys.stdin.readline().strip())
def read_int_list():
return list(map(int,sys.stdin.readline().strip().split()))
def read_string():
return sys.stdin.readline().strip()
def read_string_list(delim=" "):
return sys.stdin.readline().strip().split(delim)
def print_list(l):
print(" ".join(map(str, l)))
###### Author : Samir Vyas #######
###### Write Code Below #######
n = read_int()
for i in range(n):
broken = 0
actual = read_string()
garbled = read_string()
actual_group = []
j = 0
counter = 1
while j < len(actual)-1 :
if actual[j] == actual[j+1]:
j += 1
counter += 1
else:
actual_group.append((actual[j],counter))
j += 1
counter = 1
actual_group.append((actual[j],counter))
garbled_group = []
j = 0
counter = 1
while j < len(garbled)-1 :
if garbled[j] == garbled[j+1]:
j += 1
counter += 1
else:
garbled_group.append((garbled[j],counter))
j += 1
counter = 1
garbled_group.append((garbled[j],counter))
if len(actual_group) != len(garbled_group):
print("NO")
continue
for j in range(len(actual_group)):
if actual_group[j][0] != garbled_group[j][0] or actual_group[j][1] > garbled_group[j][1]:
broken = 1
break
if broken:
print("NO")
else:
print("YES")
``` | instruction | 0 | 76,793 | 24 | 153,586 |
Yes | output | 1 | 76,793 | 24 | 153,587 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).
For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".
Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.
For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.
You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 10^5) — the number of pairs to check. Further input contains n descriptions of pairs.
The first line of each description contains a single non-empty word s consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 10^6.
It is guaranteed that the total length of all words s in the input is not greater than 10^6. Also, it is guaranteed that the total length of all words t in the input is not greater than 10^6.
Output
Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
Submitted Solution:
```
from itertools import groupby
for _ in range(int(input())):
a = input().strip()
b = input().strip()
a = [[i, len(list(j))] for i, j in groupby(a)]
b = [[i, len(list(j))] for i, j in groupby(b)]
## print(a)
## print(b)
if len(b)!=len(a):
print("NO")
else:
flag = True
for i in range(len(a)):
if a[i][0]!=b[i][0] or b[i][1]<a[i][1]:
print("NO")
flag = False
break
if flag:
print("YES")
``` | instruction | 0 | 76,794 | 24 | 153,588 |
Yes | output | 1 | 76,794 | 24 | 153,589 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).
For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".
Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.
For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.
You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 10^5) — the number of pairs to check. Further input contains n descriptions of pairs.
The first line of each description contains a single non-empty word s consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 10^6.
It is guaranteed that the total length of all words s in the input is not greater than 10^6. Also, it is guaranteed that the total length of all words t in the input is not greater than 10^6.
Output
Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
Submitted Solution:
```
n = int(input())
for k in range(n):
s = input()
t = input()
i = 0
j = 0
while i < len(s) and j < len(t):
if s[i] == t[j]:
if i < len(s) - 1 and s[i] != s[i + 1]:
while j < len(t) and s[i] == t[j]:
j += 1
i += 1
elif i == len(s) - 1:
while j < len(t) and s[i] == t[j]:
j += 1
i += 1
else:
i += 1
j += 1
else:
break
if i == len(s) and j == len(t):
print('YES')
else:
print('NO')
``` | instruction | 0 | 76,795 | 24 | 153,590 |
Yes | output | 1 | 76,795 | 24 | 153,591 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).
For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".
Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.
For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.
You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 10^5) — the number of pairs to check. Further input contains n descriptions of pairs.
The first line of each description contains a single non-empty word s consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 10^6.
It is guaranteed that the total length of all words s in the input is not greater than 10^6. Also, it is guaranteed that the total length of all words t in the input is not greater than 10^6.
Output
Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
Submitted Solution:
```
#Anuneet Anand
n=int(input())
for i in range(n):
s=input()
t=input()
z=1;j=0;k=0;c=0
v=s[0]
if len(t)<len(s) or s[0]!=t[0] or s[-1]!=t[-1]:
z=0
else:
while j<len(s) and k<len(t):
if s[j]==t[k]:
v=s[j]
j=j+1
c=c+1
k=k+1
elif t[k]==v:
k=k+1
else:
break
if c<len(s):
z=0
if z:
print("YES")
else:
print("NO")
``` | instruction | 0 | 76,796 | 24 | 153,592 |
No | output | 1 | 76,796 | 24 | 153,593 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).
For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".
Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.
For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.
You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 10^5) — the number of pairs to check. Further input contains n descriptions of pairs.
The first line of each description contains a single non-empty word s consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 10^6.
It is guaranteed that the total length of all words s in the input is not greater than 10^6. Also, it is guaranteed that the total length of all words t in the input is not greater than 10^6.
Output
Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
Submitted Solution:
```
tt=int(input())
for _ in range(tt):
s=input()
t=input()
s1=s[0]
t1=t[0]
if set(s)!=set(t):
print('NO')
elif len(s)>len(t):
print('NO')
else:
for i in range(1,len(s)):
if s[i]!=s1[-1]:
s1+=s[i]
for i in range(1,len(t)):
if t[i]!=t1[-1]:
t1+=t[i]
f=0
if s1==t1:
for x in set(s):
if s.count(x)>t.count(x):
f=1
break
if f==0:
print('YES')
else:
print('NO')
else:
for x in set(s):
if s.count(x)>t.count(x):
f=1
break
if f==0:
print('YES')
else:
print('NO')
#print('NO')
``` | instruction | 0 | 76,797 | 24 | 153,594 |
No | output | 1 | 76,797 | 24 | 153,595 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).
For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".
Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.
For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.
You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 10^5) — the number of pairs to check. Further input contains n descriptions of pairs.
The first line of each description contains a single non-empty word s consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 10^6.
It is guaranteed that the total length of all words s in the input is not greater than 10^6. Also, it is guaranteed that the total length of all words t in the input is not greater than 10^6.
Output
Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
Submitted Solution:
```
from os import path
import sys,time
# mod = int(1e9 + 7)
# import re
from math import ceil, floor,gcd,log,log2 ,factorial
from collections import defaultdict ,Counter , OrderedDict , deque
# from itertools import combinations
from string import ascii_lowercase ,ascii_uppercase
# from bisect import *
from functools import reduce
from operator import mul
maxx = float('inf')
#----------------------------INPUT FUNCTIONS------------------------------------------#
I = lambda :int(sys.stdin.buffer.readline())
tup= lambda : map(int , sys.stdin.buffer.readline().split())
lint = lambda :[int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda: sys.stdin.readline().strip('\n')
grid = lambda r :[lint() for i in range(r)]
stpr = lambda x : sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if (path.exists('input.txt')):
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
#left shift --- num*(2**k) --(k - shift)
inp = sys.stdin.readline
for _ in range(I()):
a = inp()
b = inp()
n , m , x , y = len(a) , len(b) , '' , ''
#b could be extracted from a
d = defaultdict(int)
for i in range(n-1):
if a[i] != a[i+1]:
x+=a[i]
d[a[i]]+=1
d2 = defaultdict(int)
for i in b:
d2[i]+=1
f = True
for i in range(m-1):
if d[b[i]] > d2[b[i]]:
f = False
if b[i]!= b[i+1] :
y+=b[i]
if x== y:
if f :
print('YES')
else:
print('NO')
else:
print('NO')
if localsys:
print("\n\nTime Elased :",time.time() - start_time,"seconds")
``` | instruction | 0 | 76,798 | 24 | 153,596 |
No | output | 1 | 76,798 | 24 | 153,597 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).
For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".
Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.
For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.
You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 10^5) — the number of pairs to check. Further input contains n descriptions of pairs.
The first line of each description contains a single non-empty word s consisting of lowercase Latin letters. The second line of the description contains a single non-empty word t consisting of lowercase Latin letters. The lengths of both strings are not greater than 10^6.
It is guaranteed that the total length of all words s in the input is not greater than 10^6. Also, it is guaranteed that the total length of all words t in the input is not greater than 10^6.
Output
Output n lines. In the i-th line for the i-th pair of words s and t print YES if the word t could be printed by typing the word s. Otherwise, print NO.
Examples
Input
4
hello
hello
hello
helloo
hello
hlllloo
hello
helo
Output
YES
YES
NO
NO
Input
5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz
Output
NO
NO
YES
NO
NO
Submitted Solution:
```
for _ in range(int(input())):
a=list(input())
b=list(input())
if len(b)<len(a):
print('NO')
else:
i=0
j=0
f=0
se=''
while i<len(a) and j<len(b):
s=a[i]
i+=1
while i<len(a) and s[0]==a[i]:
s+=a[i]
i+=1
if b[j]==s[0]:
se=b[j]
j+=1
while j<len(b) and se[0]==b[j]:
se+=b[j]
j+=1
if len(s)>len(se):
f=1
print('N0')
break
else:
f=1
print('NO')
break
if f==0 and i==len(a) and j<len(b):
while j<len(b) and se[0]==b[j]:
j+=1
if j<len(b):
f=1
print('NO')
if f==0 and i==len(a):
print('YES')
``` | instruction | 0 | 76,799 | 24 | 153,598 |
No | output | 1 | 76,799 | 24 | 153,599 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,800 | 24 | 153,600 |
Tags: greedy
Correct Solution:
```
from functools import cmp_to_key
from operator import itemgetter
def main():
n, r = map(int, input().split())
ps = [tuple(map(int, input().split())) for _ in range(n)]
pos_ps = [(a, b) for a, b in ps if b >= 0]
neg_ps = [(a, b) for a, b in ps if b < 0]
def cmp(a, b):
(aa, ab), (ba, bb) = a, b
return max(aa, max(*b) - ab) - max(ba, max(*a) - bb)
pos_ps.sort(key=itemgetter(0))
neg_ps.sort(key=cmp_to_key(cmp))
del cmp
res = 0
for a, b in pos_ps:
if r >= a:
res += 1
r += b
cur = [r]
for a, b in neg_ps:
nxt = [-1]*(len(cur)+1)
for i, r in enumerate(cur):
if r >= 0:
nxt[i] = max(nxt[i], r)
if r >= a:
nxt[i+1] = r + b
while nxt[-1] < 0:
nxt.pop()
cur = nxt
print(res + len(cur) - 1)
if __name__ == '__main__':
main()
``` | output | 1 | 76,800 | 24 | 153,601 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,801 | 24 | 153,602 |
Tags: greedy
Correct Solution:
```
from sys import stdin
from sys import setrecursionlimit as SRL; SRL(10**7)
rd = stdin.readline
rrd = lambda: map(int, rd().strip().split())
n,r = rrd()
pos = []
neg = []
for i in range(n):
a,b = rrd()
if b < 0:
neg.append([a,b])
else:
pos.append([a,b])
pos.sort(key=lambda x: x[0])
neg.sort(key=lambda x: x[0]+x[1])
ans = 0
for a,b in pos:
if r>=a:
r += b
ans += 1
else:
break
dp = [[0]*105 for _i in range(60005)]
for i in range(r+10):
for j in range(len(neg)):
if i >= neg[j][0] and i+neg[j][1] >= 0:
if j:
dp[i][j] = max(dp[i][j], dp[i + neg[j][1]][j - 1] + 1,dp[i][j-1])
else:
dp[i][j] = 1
else:
if j:
dp[i][j] = dp[i][j-1]
print("YES" if dp[r][len(neg)-1] + ans == n else "NO")
``` | output | 1 | 76,801 | 24 | 153,603 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,802 | 24 | 153,604 |
Tags: greedy
Correct Solution:
```
z, r = map(int, input().split())
a = []
cnt = 0
for i in range(z):
a.append([int(j) for j in input().split()])
flag = True
while flag:
flag = False
for i in a:
if r >= i[0] and i[1] >= 0:
flag = True
r += i[1]
cnt += 1
a.remove(i)
break
a = sorted(a, key=lambda x: x[0] + x[1])
dp = [[0] * (r + 1) for i in range(len(a) + 1)]
for i in range(len(a)):
for j in range(r + 1):
dp[i][j] = dp[i - 1][j]
if j >= a[i][0] and j + a[i][1] >= 0:
dp[i][j] = max(dp[i][j], dp[i - 1][j + a[i][1]] + 1)
print(cnt + dp[len(a) - 1][r])
#print(dp, a)
``` | output | 1 | 76,802 | 24 | 153,605 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,803 | 24 | 153,606 |
Tags: greedy
Correct Solution:
```
n,r=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
pos = []
neg = []
ans=0
for x in a:
if x[1]>0:
pos.append(x)
else:
neg.append(x)
pos.sort(key=lambda k: k[0])
flag=True
for x in pos:
if r>=x[0]:
r+=x[1]
ans+=1
neg.sort(key=lambda i: i[0]+i[1],reverse=True)
arr=[0]*(r+1)
for i in range(len(neg)):
for j in range(neg[i][0],r+1):
if j+neg[i][1]>=0:
arr[j+neg[i][1]]=max(arr[j+neg[i][1]],arr[j]+1)
ans+=max(arr)
print(ans)
``` | output | 1 | 76,803 | 24 | 153,607 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,804 | 24 | 153,608 |
Tags: greedy
Correct Solution:
```
from sys import stdin
input=stdin.readline
n,r=map(int,input().split())
poz=[]
neg=[]
for i in range(n):
a,b=map(int,input().split())
if b<0:
neg.append((max(a,-b),b))
else:
poz.append((a,b))
poz.sort()
neg.sort(key=lambda x: sum(x),reverse=True)
for a,b in poz:
if a<=r:
r+=b
else:
print('NO')
exit()
for a,b in neg:
if a<=r:
r+=b
else:
print('NO')
exit()
if r<0:
print('NO')
else:
print('YES')
``` | output | 1 | 76,804 | 24 | 153,609 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,805 | 24 | 153,610 |
Tags: greedy
Correct Solution:
```
num_p, rating = map(int, input().split(' '))
def do_projs(L, rating):
for r, change in L:
if r > rating:
return 'NO', rating
if r <= rating:
rating += change
if rating < 0:
return 'NO', rating
return 'YES', rating
projl = []
for project in range(num_p):
projl.append(tuple(map(int, input().split(' '))))
projl.sort(key=lambda i: i[1], reverse=True) #sort by highest gain -> lowest
for idx, proj in enumerate(projl):
if proj[1] <= 0:
break
projl_pos = projl[:idx]
projl_neg = projl[idx:]
projl_pos.sort(key =lambda i: i[0], reverse=False)
mark = False
res, rating = do_projs(projl_pos, rating)
if res == 'NO':
print(res)
else:
projl_neg.sort(key=lambda i: i[0]+i[1], reverse=True)
res, rating = do_projs(projl_neg, rating)
print(res)
``` | output | 1 | 76,805 | 24 | 153,611 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,806 | 24 | 153,612 |
Tags: greedy
Correct Solution:
```
'''input
5 20
45 -6
34 -15
10 34
1 27
40 -45
'''
import sys
from collections import defaultdict as dd
mod=10**9+7
def ri(flag=0):
if flag==0:
return [int(i) for i in sys.stdin.readline().split()]
else:
return int(sys.stdin.readline())
n, r = ri()
eventspos = []
eventsneg = []
for i in range(n):
temp =ri()
if temp[1]>=0:
eventspos.append(temp)
else:
eventsneg.append(temp)
eventspos.sort()
eventsneg.sort(key = lambda x: x[0]+x[1])
eventsneg.reverse()
status =1
ans=0
for i in range(len(eventspos)):
if eventspos[i][0] <= r:
r+= eventspos[i][1]
ans+=1
else:
status = 0
check = [0 for i in range(r+1)]
#print(eventsneg)
for i in range(len(eventsneg)):
for j in range(eventsneg[i][0] , r+1):
if j+eventsneg[i][1]>=0:
check[j+eventsneg[i][1]] = max(check[j+eventsneg[i][1]] , check[j]+1)
if max(check)+ ans == n:
print("YES")
else:
print("NO")
#print(eventsneg,eventspos)
``` | output | 1 | 76,806 | 24 | 153,613 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2. | instruction | 0 | 76,807 | 24 | 153,614 |
Tags: greedy
Correct Solution:
```
def myFunc(e):
return e[0] + e[1]
count, rating = map(int, input().split())
goodJob = []
badJob = []
for i in range(count):
a, b = map(int, input().split())
if b >= 0:
goodJob.append([a, b])
else:
badJob.append([a, b])
goodJob.sort()
badJob.sort(reverse=True, key=myFunc)
flag = False
for job in goodJob:
if job[0] <= rating:
rating += job[1]
else:
flag = True
break
if not flag:
for job in badJob:
if job[0] <= rating:
rating += job[1]
else:
flag = True
break
if rating < 0:
flag = True
print("NO") if flag else print("YES")
``` | output | 1 | 76,807 | 24 | 153,615 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
import sys
from collections import defaultdict as dd
mod=10**9+7
def ri(flag=0):
if flag==0:
return [int(i) for i in sys.stdin.readline().split()]
else:
return int(sys.stdin.readline())
n, r = ri()
eventspos = []
eventsneg = []
for i in range(n):
temp =ri()
if temp[1]>=0:
eventspos.append(temp)
else:
eventsneg.append(temp)
eventspos.sort()
eventsneg.sort(key = lambda x: x[0]+x[1])
eventsneg.reverse()
status =1
ans=0
for i in range(len(eventspos)):
if eventspos[i][0] <= r:
r+= eventspos[i][1]
ans+=1
else:
status = 0
check = [0 for i in range(r+1)]
#print(eventsneg)
for i in range(len(eventsneg)):
for j in range(eventsneg[i][0] , r+1):
if j+eventsneg[i][1]>=0:
check[j+eventsneg[i][1]] = max(check[j+eventsneg[i][1]] , check[j]+1)
# if status and r>=0 and sum(check)==len(check):
# print("YES")
# else:
# print("NO")
#print(eventsneg,eventspos)
print(max(check) + ans)
``` | instruction | 0 | 76,808 | 24 | 153,616 |
Yes | output | 1 | 76,808 | 24 | 153,617 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 9 11:12:02 2020
@author: Rodro
"""
inp = str(input()).split()
size = int(inp[0])
r = int(inp[1])
pos = []
neg = []
for i in range(size):
inp = str(input()).split()
a = int(inp[0])
b = int(inp[1])
if b >= 0: pos.append((a, b))
else: neg.append((a,b))
pos = sorted(pos)
projects = 0
for ab in pos:
a, b = ab
if r >= a:
r += b
projects += 1
else: break
neg = sorted(neg, key = lambda ab: ab[0] + ab[1], reverse = True)
n = len(neg)
dp = [[0]*(r + 1) for _ in range(n + 1)]
dp[0][r] = projects
for i in range(0, n):
for j in range(0, r + 1):
if j >= neg[i][0] and j + neg[i][1] >= 0:
dp[i + 1][j + neg[i][1]] = max(dp[i + 1][j + neg[i][1]], dp[i][j] + 1)
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(max(dp[n]))
``` | instruction | 0 | 76,809 | 24 | 153,618 |
Yes | output | 1 | 76,809 | 24 | 153,619 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
# Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
from sys import stderr
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
# ===============================================================================================
# some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def fsep(): return map(float, inp().split())
def nextline(): out("\n") # as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def pow(x, y, p):
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1): # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def gcd(a, b):
if a == b: return a
while b > 0: a, b = b, a % b
return a
# discrete binary search
# minimise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# if isvalid(l):
# return l
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m - 1):
# return m
# if isvalid(m):
# r = m + 1
# else:
# l = m
# return m
# maximise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# # print(l,r)
# if isvalid(r):
# return r
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m + 1):
# return m
# if isvalid(m):
# l = m
# else:
# r = m - 1
# return m
#to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
# fac.append((fac[-1] * i) % mod)
# inv.append(mod - (inv[mod % i] * (mod // i) % mod))
# finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
# if n < r:
# return 0
# else:
# return fac[n] * (finv[r] * finv[n - r] % mod) % mod
##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
# dp[pos]=0
# l=max(1,k+pos-n-1)
# for j in range(min(pos,k),l-1,-1):
# dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])
def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10]
return list(accumulate(ar))
def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4]
return list(accumulate(ar[::-1]))[::-1]
def N():
return int(inp())
dx=[0,0,1,-1]
dy=[1,-1,0,0]
# =========================================================================================
from collections import defaultdict
def numberOfSetBits(i):
i = i - ((i >> 1) & 0x55555555)
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
from decimal import *
def solve():
class SegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (_size) + data + [default] * (_size - self._len)
for i in range(_size - 1, -1, -1):
self.data[i] = func(self.data[2 * i], self.data[2 * i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
"""func of data[start, stop)"""
start += self._size
stop += self._size
res_left = res_right = self._default
while start < stop:
if start & 1:
res_left = self._func(res_left, self.data[start])
start += 1
if stop & 1:
stop -= 1
res_right = self._func(self.data[stop], res_right)
start >>= 1
stop >>= 1
return self._func(res_left, res_right)
def __repr__(self):
return "SegmentTree({0})".format(self.data)
n,r=sep()
posrat=[]
negrat=[]
c=0
for _ in range(n):
a,b=sep()
if b>=0:
posrat.append((a,b))
else:
negrat.append((a,b))
posrat.sort()
def f(x):
return x[0]+x[1]
negrat.sort(reverse=True,key=f)
cr=r
for i in posrat:
ai,bi=i
if ai<=cr:
c+=1
cr+=bi
l=len(negrat)
R=cr
dp=[[0]*(R+1) for _ in range(l+1)]
for i in range(1,l+1):
for j in range(R,-1,-1):
dp[i][j]=dp[i-1][j]
if j-negrat[i-1][1]>=negrat[i-1][0] and j-negrat[i-1][1]<=R:
dp[i][j]=max(dp[i][j],dp[i-1][j-negrat[i-1][1]]+1)
m=0
for i in range(1,l+1):
for j in range(R,-1,-1):
m=max(m,dp[i][j])
print(m+c)
solve()
#testcase(int(inp()))
``` | instruction | 0 | 76,810 | 24 | 153,620 |
Yes | output | 1 | 76,810 | 24 | 153,621 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
import math
import sys
from collections import defaultdict
#input = sys.stdin.readline
nt = lambda: map(int, input().split())
def main():
n, r = nt()
projects = [tuple(nt()) for _ in range(n)]
positive = [t for t in projects if t[1] > 0]
negative = [t for t in projects if t[1] <= 0]
ok = True
for p in sorted(positive):
if p[0] <= r:
r += p[1]
else:
ok = False
break
if ok:
for p in sorted(negative, key=lambda x: -x[0]-x[1]):
if p[0] <= r:
r += p[1]
if r < 0:
ok = False
break
else:
ok = False
break
print('YES' if ok else 'NO')
if __name__ == '__main__':
main()
``` | instruction | 0 | 76,811 | 24 | 153,622 |
Yes | output | 1 | 76,811 | 24 | 153,623 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
# Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
from sys import stderr
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
# ===============================================================================================
# some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def fsep(): return map(float, inp().split())
def nextline(): out("\n") # as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def pow(x, y, p):
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1): # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def gcd(a, b):
if a == b: return a
while b > 0: a, b = b, a % b
return a
# discrete binary search
# minimise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# if isvalid(l):
# return l
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m - 1):
# return m
# if isvalid(m):
# r = m + 1
# else:
# l = m
# return m
# maximise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# # print(l,r)
# if isvalid(r):
# return r
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m + 1):
# return m
# if isvalid(m):
# l = m
# else:
# r = m - 1
# return m
#to find factorial and ncr
# N=100000
# mod = 10**9 +7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, N + 1):
# fac.append((fac[-1] * i) % mod)
# inv.append(mod - (inv[mod % i] * (mod // i) % mod))
# finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
# if n < r:
# return 0
# else:
# return fac[n] * (finv[r] * finv[n - r] % mod) % mod
##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
# dp[pos]=0
# l=max(1,k+pos-n-1)
# for j in range(min(pos,k),l-1,-1):
# dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])
def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10]
return list(accumulate(ar))
def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4]
return list(accumulate(ar[::-1]))[::-1]
def N():
return int(inp())
dx=[0,0,1,-1]
dy=[1,-1,0,0]
# =========================================================================================
from collections import defaultdict
def numberOfSetBits(i):
i = i - ((i >> 1) & 0x55555555)
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
from decimal import *
def solve():
class SegmentTree:
def __init__(self, data, default=0, func=max):
"""initialize the segment tree with data"""
self._default = default
self._func = func
self._len = len(data)
self._size = _size = 1 << (self._len - 1).bit_length()
self.data = [default] * (_size) + data + [default] * (_size - self._len)
for i in range(_size - 1, -1, -1):
self.data[i] = func(self.data[2 * i], self.data[2 * i + 1])
def __delitem__(self, idx):
self[idx] = self._default
def __getitem__(self, idx):
return self.data[idx + self._size]
def __setitem__(self, idx, value):
idx += self._size
self.data[idx] = value
idx >>= 1
while idx:
self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
idx >>= 1
def __len__(self):
return self._len
def query(self, start, stop):
"""func of data[start, stop)"""
start += self._size
stop += self._size
res_left = res_right = self._default
while start < stop:
if start & 1:
res_left = self._func(res_left, self.data[start])
start += 1
if stop & 1:
stop -= 1
res_right = self._func(self.data[stop], res_right)
start >>= 1
stop >>= 1
return self._func(res_left, res_right)
def __repr__(self):
return "SegmentTree({0})".format(self.data)
n,r=sep()
posrat=[]
negrat=[]
for _ in range(n):
a,b=sep()
if b>=0:
posrat.append((a,b))
else:
negrat.append((a,b))
posrat.sort()
negrat.sort(reverse=True)
cr=r
# print(posrat,negrat)
for i in posrat:
ai,bi=i
# print(ai,cr)
if ai>cr:
print("NO")
return
else:
cr+=bi
for i in negrat:
ai,bi=i
if ai>cr:
print("NO")
return
else:
cr+=bi
print("YES")
solve()
#testcase(int(inp()))
``` | instruction | 0 | 76,812 | 24 | 153,624 |
No | output | 1 | 76,812 | 24 | 153,625 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
import collections, heapq, bisect, math
def gcd(a, b):
if b == 0: return a
return gcd(b, a%b)
def solve(r, A):
r = int(r)
while A:
opt = max(range(len(A)), key=lambda x: A[x][1] if r >= A[x][0] else -400)
if A[opt][0] > r: return "NO"
if A[opt][1] < 0:
A.sort(key=lambda x: -x[0])
r0 = r
for i in range(len(A)):
r = r0
B = A[:i] + A[i+1:]
for req, cost in B:
if req > r: break
r += cost
else:
if A[i][0] <= r: return "YES"
return "NO"
r += A[opt][1]
A[opt], A[-1] = A[-1], A[opt]
A.pop()
return "YES"
q = 1#input()
n, r = input().split(' ')
tests = []
for test in range(int(n)):
#n = input()
tests.append([int(p) for p in input().split(' ')])
print(solve(r,tests))
#print(solve(n,b))
``` | instruction | 0 | 76,813 | 24 | 153,626 |
No | output | 1 | 76,813 | 24 | 153,627 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
n,r = map(int,(input().split()))
copy=r
plus=[]
minn=[]
maxmin=0
for i in range (0,n):
temp = list(map(int,input().split()))
if temp[1] <=0:
temp.append(temp[0]+temp[1])
minn.append(temp)
maxmin=max(maxmin,temp[0])
else:
plus.append(temp)
plus.sort()
#print(minn)
flag = True
count=0
for i in plus:
if i[0] <= r:
r+= i[1]
count +=1
else:
break
print("GANTI",r)
k=0
deleted=0
while k != len(minn):
if minn[k][0] > r:
del minn[k]
deleted+=1
k-=1
k+=1
#print(minn)
minn.sort(reverse=True,key = lambda x: x[1])
if len(minn)!=0:
while (r)> maxmin :
if r+ minn[k][1] >=maxmin:
print(r,minn[k][1])
r=r+minn[k][1]
count +=1
#print(r,count)
del minn[k]
if len(minn)==0:break
#print("GANTI2")
minn.sort(key = lambda x: x[0])
for i in minn:
if i[0] <= r and r+i[1]>=0:
r +=i[1]
count +=1
#print(r,count)
if n==100 and copy == 300 and count ==99:
print(100)
else:
print(count)
``` | instruction | 0 | 76,814 | 24 | 153,628 |
No | output | 1 | 76,814 | 24 | 153,629 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is r units.
Some very rich customers asked him to complete some projects for their companies. To complete the i-th project, Polycarp needs to have at least a_i units of rating; after he completes this project, his rating will change by b_i (his rating will increase or decrease by b_i) (b_i can be positive or negative). Polycarp's rating should not fall below zero because then people won't trust such a low rated freelancer.
Is it possible to complete all the projects? Formally, write a program to check if such an order of the projects exists, that Polycarp has enough rating before starting each project, and he has non-negative rating after completing each project.
In other words, you have to check that there exists such an order of projects in which Polycarp will complete them, so he has enough rating before starting each project, and has non-negative rating after completing each project.
Input
The first line of the input contains two integers n and r (1 ≤ n ≤ 100, 1 ≤ r ≤ 30000) — the number of projects and the initial rating of Polycarp, respectively.
The next n lines contain projects, one per line. The i-th project is represented as a pair of integers a_i and b_i (1 ≤ a_i ≤ 30000, -300 ≤ b_i ≤ 300) — the rating required to complete the i-th project and the rating change after the project completion.
Output
Print "YES" or "NO".
Examples
Input
3 4
4 6
10 -2
8 -1
Output
YES
Input
3 5
4 -5
4 -2
1 3
Output
YES
Input
4 4
5 2
5 -3
2 1
4 -2
Output
YES
Input
3 10
10 0
10 -10
30 0
Output
NO
Note
In the first example, the possible order is: 1, 2, 3.
In the second example, the possible order is: 2, 3, 1.
In the third example, the possible order is: 3, 1, 4, 2.
Submitted Solution:
```
import sys
input = sys.stdin.readline
def getInt(): return int(input())
def getVars(): return map(int, input().split())
def getArr(): return list(map(int, input().split()))
def getStr(): return input().strip()
## -------------------------------
def ObrabotkaPlus():
global PLUS, res, R
keys = list(PLUS.keys())
keys.sort()
for k in keys:
if k <= R:
R += sum(PLUS[k])
else:
res = 'NO'
break
def ObrabotkaNull():
global m0, res, R
if m0 > R:
res = 'NO'
def ObrabotkaMinus2():
global R, res, MINUS
keys = list(MINUS.keys())
keys.sort(reverse = True)
for k in keys:
for x in MINUS[k]:
if R < x[0]:
res = 'NO'
break
else:
R += x[1]
if R < 0:
res = 'NO'
break
if res == 'NO':
break
res = 'YES'
N, R = getVars()
m0 = 0
PLUS = {}
MINUS = {}
MINUS3 = []
for i in range(N):
a, b = getVars()
if b > 0:
if a <= R:
R += b
else:
if a not in PLUS:
PLUS[a] = []
PLUS[a].append(b)
elif b == 0:
m0 = max(m0, a)
else:
key = max(a, -b) + b
if key not in MINUS:
MINUS[key] = []
MINUS[key].append([a, b])
ObrabotkaPlus()
if res == 'YES':
ObrabotkaNull()
if res == 'YES':
ObrabotkaMinus2()
print(res)
``` | instruction | 0 | 76,815 | 24 | 153,630 |
No | output | 1 | 76,815 | 24 | 153,631 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,577 | 24 | 155,154 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n = int(input())
l = list(map(int,input().split()))
even = sorted([x for x in l if x%2 == 0],reverse = True)
odd = sorted([x for x in l if x%2],reverse = True)
steps_even = 0
steps_odd = 0
if len(odd) == len(even):
steps_even = len(odd)
steps_odd = len(even)
elif len(odd) > len(even):
steps_odd = len(even)+1
steps_even = len(even)
else:
steps_odd = len(odd)
steps_even = len(odd)+1
total = sum(even[steps_even:])+sum(odd[steps_odd:])
print (total)
``` | output | 1 | 77,577 | 24 | 155,155 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,578 | 24 | 155,156 |
Tags: greedy, implementation, sortings
Correct Solution:
```
a=int(input())
z=list(map(int,input().split()))
odd=[]
eve=[]
for i in range(len(z)):
if(z[i]%2==1):
odd.append(z[i])
else:
eve.append(z[i])
odd.sort(reverse=True)
eve.sort(reverse=True)
arr1=[]
arr2=[]
l1=0
l2=0
i=0
while(l1<len(odd) and l2<len(eve)):
if(i%2==1):
arr1.append(odd[l1])
l1+=1
else:
arr1.append(eve[l2])
l2+=1
i+=1
if(l1==len(odd) and l2<len(eve)):
arr1.append(eve[l2])
if(l1<len(odd) and l2==len(eve)):
arr1.append(odd[l1])
l1=0
l2=0
i=0
while(l1<len(odd) and l2<len(eve)):
if(i%2==1):
arr2.append(eve[l2])
l2+=1
else:
arr2.append(odd[l2])
l1+=1
i+=1
if(l1==len(odd) and l2<len(eve)):
arr2.append(eve[l2])
if(l1<len(odd) and l2==len(eve)):
arr2.append(odd[l1])
total=sum(z)
print(min(total-sum(arr1),total-sum(arr2)))
``` | output | 1 | 77,578 | 24 | 155,157 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,579 | 24 | 155,158 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
odd = [i for i in a if i&1]
odd.sort(reverse = True)
even = [i for i in a if i&1==0]
even.sort(reverse = True)
if len(odd) > len(even):
print(s-sum(odd[:len(even)+1])-sum(even))
elif len(odd) < len(even):
print(s-sum(even[:len(odd)+1])-sum(odd))
else:
print(0)
``` | output | 1 | 77,579 | 24 | 155,159 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,580 | 24 | 155,160 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
odd,even=[],[]
for num in a:
if num%2==1:
odd.append(num)
else:
even.append(num)
tmp = min(len(odd),len(even))
result = sum(a)-sum(odd[:tmp])-sum(even[:tmp])
if len(odd)!=len(even):
result -= (odd[tmp] if len(odd)>len(even) else even[tmp])
print(result)
``` | output | 1 | 77,580 | 24 | 155,161 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,581 | 24 | 155,162 |
Tags: greedy, implementation, sortings
Correct Solution:
```
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
even = list(filter(lambda x: x % 2 == 0, A))
odd = list(filter(lambda x: x % 2 != 0, A))
even = sorted(even)
odd = sorted(odd)
evenN = len(even)
oddN = len(odd)
ans = -1
if abs(evenN-oddN) <= 1:
ans = 0
else:
if evenN > oddN:
ans = sum(even[:evenN-oddN-1])
else:
ans = sum(odd[:oddN-evenN-1])
print(ans)
``` | output | 1 | 77,581 | 24 | 155,163 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,582 | 24 | 155,164 |
Tags: greedy, implementation, sortings
Correct Solution:
```
import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))
even = sorted(list(filter(lambda x: x%2 == 0, a)), key=lambda x: -x)
odd = sorted(list(filter(lambda x: x%2 != 0, a)), key=lambda x: -x)
s = sum(a)
if len(even) == 0:
print(s - odd[0])
exit()
if len(odd) == 0:
print(s - even[0])
exit()
x = min(len(even), len(odd))
s1 = sum(even[0:x]) + sum(odd[0:x+1])
s2 = sum(even[0:x+1]) + sum(odd[0:x])
print(s - max(s1, s2))
``` | output | 1 | 77,582 | 24 | 155,165 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,583 | 24 | 155,166 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n = int(input())
a = list(map(int,input().split()))
odd = []
even = []
for i in a:
if i & 1:
odd.append(i)
else:
even.append(i)
odd.sort(reverse = True)
even.sort(reverse = True)
e = len(even)
o = len(odd)
if o > e:
print(sum(odd[e+1:]))
elif e > o:
print(sum(even[o+1:]))
else:
print('0')
``` | output | 1 | 77,583 | 24 | 155,167 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000 | instruction | 0 | 77,584 | 24 | 155,168 |
Tags: greedy, implementation, sortings
Correct Solution:
```
n=int(input())
l=list(map(int, input().split()))
l1=[]
l2=[]
for i in range(n):
if(l[i]%2==1):
l1.append(l[i])
else:
l2.append(l[i])
def f(x, y):
m=len(x)
n=len(y)
k=m-n-1
if(k>=1):
x.sort()
tmp=0
for i in range(k):
tmp+=x[i]
return tmp
else:
return 0
if(len(l1)>len(l2)):
print(f(l1, l2))
else:
print(f(l2, l1))
``` | output | 1 | 77,584 | 24 | 155,169 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
input()
n=list(map(int, input().split()))
e=[]
o=[]
for i in n:
if i%2==1:
o.append(i)
else:
e.append(i)
o.sort(reverse=True)
e.sort(reverse=True)
if len(o)>len(e):
print(sum(o[len(e)+1:]))
else:
print(sum(e[len(o)+1:]))
``` | instruction | 0 | 77,585 | 24 | 155,170 |
Yes | output | 1 | 77,585 | 24 | 155,171 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
from collections import Counter
n = int(input())
a = sorted(list(map(int, input().split())))[::-1]
even = []
odd = []
for i in a:
if i % 2 == 0: even.append(i)
else: (odd.append(i))
turn = 0
z = len(even) > len(odd)
z1 = len(even) == len(odd)
if(z):
even.remove(even[0])
turn = 1
else:
odd.remove(odd[0])
if(z1):
if(odd[0] > even[0]): odd.remove(odd[0])
else: even.remove(even[0])
s = [even, odd]
while len(s[turn]) != 0:
s[turn].remove(s[turn][0])
turn = (turn+1)%2
print(sum(s[0])+sum(s[1]))
``` | instruction | 0 | 77,586 | 24 | 155,172 |
Yes | output | 1 | 77,586 | 24 | 155,173 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
import sys
def input():
return sys.stdin.readline().strip()
def print(*x, sep=' ', end='\n'):
return sys.stdout.write(sep.join(map(str, x)) + end)
def read():
return sys.stdin.read()
def get():
return int(input()), [int(i) for i in input().split()]
def out(*arg):
if type(arg[0]) == list:
for i in arg[0]:
print(i)
else:
print(arg)
def main():
n, a = get()
odd = []
even = []
for i in range(n):
if a[i] % 2 == 0:
odd.append(a[i])
else:
even.append(a[i])
x, y = len(odd), len(even)
if abs(x - y) <= 1:
print(0)
else:
odd = sorted(odd, reverse=True)
even = sorted(even, reverse=True)
if x > y:
print(sum(odd) - sum(odd[:y + 1]))
else:
print(sum(even) - sum(even[:x + 1]))
if __name__ == "__main__":
main()
``` | instruction | 0 | 77,587 | 24 | 155,174 |
Yes | output | 1 | 77,587 | 24 | 155,175 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
input()
even, odd = [], []
for a in sorted(map(int, input().split())):
if a % 2:
odd.append(a)
else:
even.append(a)
x = min(len(even), len(odd)) + 1
print(sum(even[:-x]) + sum(odd[:-x]))
``` | instruction | 0 | 77,588 | 24 | 155,176 |
Yes | output | 1 | 77,588 | 24 | 155,177 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
import sys
n = int(sys.stdin.readline())
arr = [int(i) for i in sys.stdin.readline().split()]
c = []
d = []
for i in arr:
if i % 2 == 0:
c.append(i)
else:
d.append(i)
c.sort()
d.sort()
if abs(len(c)-len(d))<2:
print(0)
elif len(d) == 2 and len(c) == 0 :
print(min(d))
elif len(c) == 2 and len(d) == 0:
print(min(c))
else:
if len(c)>len(d):
print(sum(c[:len(d)]))
else:
print(sum(d[:len(c)]))
``` | instruction | 0 | 77,589 | 24 | 155,178 |
No | output | 1 | 77,589 | 24 | 155,179 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
n = int(input())
lst = [int(i) for i in input().split()]
even = []
odd = []
for i in lst:
if i%2:
odd.append(i)
else:
even.append(i)
even = sorted(even)
odd = sorted(odd)
if len(even) == len(odd) or abs(len(even)-len(odd)) == 1:
print(0)
elif len(even) > len(odd):
print(sum(even[:len(odd)+1]))
else:
print(sum(odd[:len(even)+1]))
``` | instruction | 0 | 77,590 | 24 | 155,180 |
No | output | 1 | 77,590 | 24 | 155,181 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
n = int(input())
A = list(map(int,input().split()))
A.sort()
o=0;e=0
for i in range(n):
if(A[i]%2):
o+=1
else:
e+=1
if(abs(o-e)<2):
print(0)
else:
if(o>e):
a = o-e-1;sum = 0
for i in range(n):
if(A[i]%2!=0):
sum+=A[i]
a-=1
if(a==-1):
break
else:
a = e-o-1;sum = 0
for i in range(n):
if(A[i]%2==0):
sum+=A[i]
a-=1
if(a==-1):
break
print(sum)
``` | instruction | 0 | 77,591 | 24 | 155,182 |
No | output | 1 | 77,591 | 24 | 155,183 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has an array a consisting of n integers.
He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.
Formally:
* If it is the first move, he chooses any element and deletes it;
* If it is the second or any next move:
* if the last deleted element was odd, Polycarp chooses any even element and deletes it;
* if the last deleted element was even, Polycarp chooses any odd element and deletes it.
* If after some move Polycarp cannot make a move, the game ends.
Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.
Help Polycarp find this value.
Input
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements of a.
The second line of the input contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 10^6), where a_i is the i-th element of a.
Output
Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.
Examples
Input
5
1 5 7 8 2
Output
0
Input
6
5 1 2 4 6 3
Output
0
Input
2
1000000 1000000
Output
1000000
Submitted Solution:
```
n = int(input())
l = list(map(int,input().split()))
even = []
odd = []
for i in l:
if(i&1):
odd.append(i)
else:
even.append(i)
if(len(even)==len(odd)):
print(0)
elif(len(even)+1==len(odd) or len(odd)+1 == len(even)):
print(0)
else:
if(len(even)>len(odd)):
x = len(even)+len(odd)-1
even.sort()
s=0
for i in range(x):
s+=even[i]
print(s)
else:
x = len(odd)+len(even)-1
odd.sort()
s=0
for i in range(x):
s+=odd[i]
print(s)
``` | instruction | 0 | 77,592 | 24 | 155,184 |
No | output | 1 | 77,592 | 24 | 155,185 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!
Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.
Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
Input
The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
Output
In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts.
In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input.
If there are multiple optimal distributions, you are allowed to print any of them.
Examples
Input
3 2
2 1
3 2
3 1
Output
5.5
2 1 2
1 3
Input
4 3
4 1
1 2
2 2
3 2
Output
8.0
1 1
2 4 2
1 3
Note
In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. | instruction | 0 | 77,753 | 24 | 155,506 |
Tags: constructive algorithms, greedy, sortings
Correct Solution:
```
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
##########################################################
#print('%d %d' %ans)
from collections import Counter
import math
#for _ in range(int(input())):
#n=int(input())
n,k= map(int, input().split())
s=[]
p=[]
ex=1e9
for i in range(n):
c,t = map(int, input().split())
ex = min(ex, c)
if t==1:
s.append((c,i))
else:
p.append((c,i))
s.sort(reverse=True)
var=0
cost=0
ans=[[] for i in range(k)]
for i,j in s:
ans[var].append((j+1))
if var<k-1:
cost+=i
var+=1
else:
cost+=2*i
for i,j in p:
ans[var].append((j+1))
if var<k-1:var+=1
cost+=2*i
#print("%.1f"%cost/2)
if len(s)>=k:
cost-=ex
cost=cost/2
print("%.1f"%cost)
for i in ans:
print(len(i), *i)
``` | output | 1 | 77,753 | 24 | 155,507 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!
Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.
Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
Input
The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
Output
In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts.
In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input.
If there are multiple optimal distributions, you are allowed to print any of them.
Examples
Input
3 2
2 1
3 2
3 1
Output
5.5
2 1 2
1 3
Input
4 3
4 1
1 2
2 2
3 2
Output
8.0
1 1
2 4 2
1 3
Note
In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. | instruction | 0 | 77,754 | 24 | 155,508 |
Tags: constructive algorithms, greedy, sortings
Correct Solution:
```
n, k = list(map(int, input().split()))
p = [[], []]
for i in range(1, n + 1):
c, t = map(int, input().split())
p[t > 1].append((c, i))
if k > len(p[0]):
l = k - len(p[0]) - 1
print(sum(c for c, i in p[0]) / 2 + sum(c for c, i in p[1]))
print('\n'.join('1 ' + str(i) for c, i in p[0]))
print('\n'.join('1 ' + str(i) for c, i in p[1][: l]))
print(len(p[1]) - l, ' '.join(str(i) for c, i in p[1][l: ]))
else:
p[1].sort()
p[0].sort(reverse = True)
print(sum(c for c, i in p[0][: k - 1]) / 2 + sum(c for c, i in p[0][k - 1: ]) + sum(c for c, i in p[1]) - min(c for c, i in p[1] + p[0][k - 1: ]) / 2)
print('\n'.join('1 ' + str(i) for c, i in p[0][: k - 1]))
print(n - k + 1, ' '.join(str(i) for c, i in p[0][k - 1:]), ' '.join(str(i) for c, i in p[1]))
# Made By Mostafa_Khaled
``` | output | 1 | 77,754 | 24 | 155,509 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!
Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.
Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
Input
The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
Output
In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts.
In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input.
If there are multiple optimal distributions, you are allowed to print any of them.
Examples
Input
3 2
2 1
3 2
3 1
Output
5.5
2 1 2
1 3
Input
4 3
4 1
1 2
2 2
3 2
Output
8.0
1 1
2 4 2
1 3
Note
In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. | instruction | 0 | 77,755 | 24 | 155,510 |
Tags: constructive algorithms, greedy, sortings
Correct Solution:
```
I = lambda: map(int, input().split())
n, k = I()
fs = []
sc = []
Min = 1e9
for i in range(n):
c, t = I()
Min = min(c, Min)
if t == 1 :
fs += [(c, i+1)]
else:
sc += [(c, i+1)]
fs = sorted(fs, reverse = True)
z = [[] for i in range(k)]
sz = 0
ans = 0
for c, i in fs:
z[sz] += [i]
if sz < k-1:
ans += c
sz += 1
else:
ans += 2*c
for c, i in sc:
z[sz] += [i]
ans += 2*c
if sz < k-1:
sz += 1
if len(fs) >= k:
ans -= Min
print("%.1f"%(1.0*ans/2.0))
for i in z:
print(len(i), end = ' ')
for j in range(len(i)):
if j==len(i)-1:
print(i[j])
else:
print(i[j], end = ' ')
``` | output | 1 | 77,755 | 24 | 155,511 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!
Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.
Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
Input
The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
Output
In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts.
In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input.
If there are multiple optimal distributions, you are allowed to print any of them.
Examples
Input
3 2
2 1
3 2
3 1
Output
5.5
2 1 2
1 3
Input
4 3
4 1
1 2
2 2
3 2
Output
8.0
1 1
2 4 2
1 3
Note
In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. | instruction | 0 | 77,756 | 24 | 155,512 |
Tags: constructive algorithms, greedy, sortings
Correct Solution:
```
n, k = list(map(int, input().split()))
p = [[], []]
for i in range(1, n + 1):
c, t = map(int, input().split())
p[t > 1].append((c, i))
if k > len(p[0]):
l = k - len(p[0]) - 1
print(sum(c for c, i in p[0]) / 2 + sum(c for c, i in p[1]))
print('\n'.join('1 ' + str(i) for c, i in p[0]))
print('\n'.join('1 ' + str(i) for c, i in p[1][: l]))
print(len(p[1]) - l, ' '.join(str(i) for c, i in p[1][l: ]))
else:
p[1].sort()
p[0].sort(reverse = True)
print(sum(c for c, i in p[0][: k - 1]) / 2 + sum(c for c, i in p[0][k - 1: ]) + sum(c for c, i in p[1]) - min(c for c, i in p[1] + p[0][k - 1: ]) / 2)
print('\n'.join('1 ' + str(i) for c, i in p[0][: k - 1]))
print(n - k + 1, ' '.join(str(i) for c, i in p[0][k - 1:]), ' '.join(str(i) for c, i in p[1]))
``` | output | 1 | 77,756 | 24 | 155,513 |
Provide tags and a correct Python 3 solution for this coding contest problem.
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them!
Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible.
Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils.
Input
The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces.
Output
In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts.
In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input.
If there are multiple optimal distributions, you are allowed to print any of them.
Examples
Input
3 2
2 1
3 2
3 1
Output
5.5
2 1 2
1 3
Input
4 3
4 1
1 2
2 2
3 2
Output
8.0
1 1
2 4 2
1 3
Note
In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. | instruction | 0 | 77,757 | 24 | 155,514 |
Tags: constructive algorithms, greedy, sortings
Correct Solution:
```
l=input().split()
n=int(l[0])
k=int(l[1])
qofp=[]
qofs=[]
for i in range(n):
l=input().split()
if(int(l[1])==1):
qofs.append((int(l[0]),i+1))
else:
qofp.append((int(l[0]),i+1))
qofs.sort()
qofs.reverse()
fina=[[] for i in range(k)]
if(len(qofs)<k):
price=0
i=0
while(qofs!=[]):
fina[i].append(qofs[0][1])
price+=(qofs[0][0]*0.5)
qofs.pop(0)
i+=1
for j in range(i,k-1):
fina[j].append(qofp[0][1])
price+=qofp[0][0]
qofp.pop(0)
for i in qofp:
fina[k-1].append(i[1])
price+=i[0]
print("{:.1f}".format(price))
for i in fina:
print(len(i),end=" ")
for j in i:
print(j,end=" ")
print()
else:
price=0
for i in range(k-1):
fina[i].append(qofs[0][1])
price+=(0.5*qofs[0][0])
qofs.pop(0)
fool=[]
while(qofs!=[]):
fina[k-1].append(qofs[0][1])
fool.append(qofs[0][0])
price+=qofs[0][0]
qofs.pop(0)
while(qofp!=[]):
fina[k-1].append(qofp[0][1])
fool.append(qofp[0][0])
price+=qofp[0][0]
qofp.pop(0)
z=min(fool)
price-=(z/2)
print("{:.1f}".format(price))
for i in fina:
print(len(i),end=" ")
for j in i:
print(j,end=" ")
print()
``` | output | 1 | 77,757 | 24 | 155,515 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move.
There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0).
You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.
Input
The first line contains four integers: xp, yp, xv, yv (0 ≤ xp, yp, xv, yv ≤ 105) — Polycarp's and Vasiliy's starting coordinates.
It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0).
Output
Output the name of the winner: "Polycarp" or "Vasiliy".
Examples
Input
2 1 2 2
Output
Polycarp
Input
4 7 7 4
Output
Vasiliy
Note
In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn. | instruction | 0 | 78,685 | 24 | 157,370 |
Tags: games, greedy, implementation, math
Correct Solution:
```
def dist(a,b,c,d):
poly = a + b
vasi = max(c,d)
if(poly<=vasi):
return True
return False
a,b,c,d= map(int,input().split())
x,y = min(a,c), min(b,d)
if((a<=c and b<=d) or (dist(a,b,c,d))):
print("Polycarp")
else:
print("Vasiliy")
``` | output | 1 | 78,685 | 24 | 157,371 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move.
There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0).
You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.
Input
The first line contains four integers: xp, yp, xv, yv (0 ≤ xp, yp, xv, yv ≤ 105) — Polycarp's and Vasiliy's starting coordinates.
It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0).
Output
Output the name of the winner: "Polycarp" or "Vasiliy".
Examples
Input
2 1 2 2
Output
Polycarp
Input
4 7 7 4
Output
Vasiliy
Note
In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn.
Submitted Solution:
```
x, y, a, b = map(int, input().split())
print('Vasiliy' if b + a < x + y or b + a == x + y and a and b else 'Polycarp')
``` | instruction | 0 | 78,692 | 24 | 157,384 |
No | output | 1 | 78,692 | 24 | 157,385 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move.
There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0).
You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.
Input
The first line contains four integers: xp, yp, xv, yv (0 ≤ xp, yp, xv, yv ≤ 105) — Polycarp's and Vasiliy's starting coordinates.
It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0).
Output
Output the name of the winner: "Polycarp" or "Vasiliy".
Examples
Input
2 1 2 2
Output
Polycarp
Input
4 7 7 4
Output
Vasiliy
Note
In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn.
Submitted Solution:
```
x,y,z,w=map(int,input().split())
val1=x+y
val2=max(z,w)
if(val1<=val2):
print("Polycarp")
else:
print("Vasiliy")
``` | instruction | 0 | 78,693 | 24 | 157,386 |
No | output | 1 | 78,693 | 24 | 157,387 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move.
There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0).
You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.
Input
The first line contains four integers: xp, yp, xv, yv (0 ≤ xp, yp, xv, yv ≤ 105) — Polycarp's and Vasiliy's starting coordinates.
It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0).
Output
Output the name of the winner: "Polycarp" or "Vasiliy".
Examples
Input
2 1 2 2
Output
Polycarp
Input
4 7 7 4
Output
Vasiliy
Note
In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn.
Submitted Solution:
```
x, y, a, b = map(int, input().split())
print('Vasiliy' if b < x and a < x + y or a < y and b < x + y else 'Polycarp')
``` | instruction | 0 | 78,694 | 24 | 157,388 |
No | output | 1 | 78,694 | 24 | 157,389 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3 | instruction | 0 | 78,733 | 24 | 157,466 |
Tags: brute force, dp
Correct Solution:
```
#-*- coding:utf-8 -*-
#!/usr/bin/python3
def dfs(step, left, mx):
#print(step, left)
if step == 0:
for i in range(left - 1, n):
if h[i] >= 0:
return False
return True
else:
if h[left - 1] < 0 and h[left] < 0 and left + 2 != n:
if dfs(step, left + 1, mx):
return True
else:
if left >= mx:
h[left - 1] -= b; h[left] -= a; h[left + 1] -= b
ans[step] = left
if dfs(step - 1, left, left):
return True
h[left - 1] += b; h[left] += a; h[left + 1] += b
if left + 1 >= mx and left + 1 < n - 1:
h[left] -= b; h[left + 1] -= a; h[left + 2] -= b
ans[step] = left + 1
if dfs(step - 1, left, left + 1):
return True
h[left] += b; h[left + 1] += a; h[left + 2] += b
return False
n, a, b = input().split()
n = int(n)
a = int(a)
b = int(b)
h = list(map(int, input().split()))
ans = list(range(0, 200))
for i in range(0, 200):
if (dfs(i, 1, 1)):
print(i)
for j in range(1, i):
print(ans[j] + 1, end = " ")
print(ans[i] + 1)
break
``` | output | 1 | 78,733 | 24 | 157,467 |
Provide tags and a correct Python 3 solution for this coding contest problem.
This is simplified version of the problem used on the original contest. The original problem seems to have too difiicult solution. The constraints for input data have been reduced.
Polycarp likes to play computer role-playing game «Lizards and Basements». At the moment he is playing it as a magician. At one of the last levels he has to fight the line of archers. The only spell with which he can damage them is a fire ball. If Polycarp hits the i-th archer with his fire ball (they are numbered from left to right), the archer loses a health points. At the same time the spell damages the archers adjacent to the i-th (if any) — they lose b (1 ≤ b < a ≤ 10) health points each.
As the extreme archers (i.e. archers numbered 1 and n) are very far, the fire ball cannot reach them. Polycarp can hit any other archer with his fire ball.
The amount of health points for each archer is known. An archer will be killed when this amount is less than 0. What is the minimum amount of spells Polycarp can use to kill all the enemies?
Polycarp can throw his fire ball into an archer if the latter is already killed.
Input
The first line of the input contains three integers n, a, b (3 ≤ n ≤ 10; 1 ≤ b < a ≤ 10). The second line contains a sequence of n integers — h1, h2, ..., hn (1 ≤ hi ≤ 15), where hi is the amount of health points the i-th archer has.
Output
In the first line print t — the required minimum amount of fire balls.
In the second line print t numbers — indexes of the archers that Polycarp should hit to kill all the archers in t shots. All these numbers should be between 2 and n - 1. Separate numbers with spaces. If there are several solutions, output any of them. Print numbers in any order.
Examples
Input
3 2 1
2 2 2
Output
3
2 2 2
Input
4 3 1
1 4 1 1
Output
4
2 2 3 3 | instruction | 0 | 78,734 | 24 | 157,468 |
Tags: brute force, dp
Correct Solution:
```
"""
Codeforces
6D - Lizards and Basements 2
http://codeforces.com/contest/6/problem/D
Héctor González Belver
../07/2018
"""
import sys
def main():
n, a, b = map(int,sys.stdin.readline().strip().split())
archers = list(map(int,sys.stdin.readline().strip().split()))
temp = [0] * n
shots = []
shots_first = archers[0]//b + 1
archers[0] -= shots_first*b
archers[1] -= shots_first*a
archers[2] -= shots_first*b
shots_last = archers[n-1]//b + 1
archers[n-1] -= shots_last*b
archers[n-2] -= shots_last*a
archers[n-3] -= shots_last*b
min_shots = 10000
def kill(current_archer, life_current, life_left):
nonlocal temp, shots, min_shots
next_archer = current_archer+1
min_shots_kill_left = life_left//b + 1 if life_left >= 0 else 0
min_shots_kill_current = life_current//a + 1 if life_current >= 0 else 0
min_shots_kill_right = archers[next_archer]//b + 1 if archers[next_archer] >= 0 else 0
min_shots_kill_trio = max(min_shots_kill_left, min_shots_kill_current, min_shots_kill_right)
accum_shots = sum(temp[:current_archer])
if current_archer == n-2:
temp[n-2] = min_shots_kill_trio
accum_shots += min_shots_kill_trio
if min_shots > accum_shots:
min_shots = accum_shots
shots = temp.copy()
return
for j in range(min_shots_kill_left, min_shots_kill_trio + 1):
if accum_shots + j >= min_shots:
return
temp[current_archer] = j
kill(next_archer, archers[next_archer] - j*b, life_current - j*a)
kill(1, archers[1], archers[0])
shots[1] += shots_first
shots[n-2] += shots_last
min_shots += shots_first + shots_last
sys.stdout.write(str(min_shots) + '\n')
sys.stdout.write(' '.join(str(pos) for pos, s in enumerate(shots, start=1) for _ in range(s)) + '\n')
if __name__ == '__main__':
main()
``` | output | 1 | 78,734 | 24 | 157,469 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.