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.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
# rambo_1
from math import *
from copy import *
from string import * # alpha = ascii_lowercase
from sys import stdin
from sys import maxsize
from operator import * # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter # d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)
'''
4
onetwone
testme
oneoneone
twotwo
onetwonetwooneooonetwooo
'''
def solve(s):
n = len(s)
l = list(s)
one = s.count('one')
two = s.count('two')
total = one + two
llen = total*3
if(total == 0):
print(0)
print()
else:
i,ans = 0,0
L = []
s += 'zzzzz'
l = list(s)
while(i < n):
curr = ''.join(l[i:i+6])
# print("curr:",''.join(curr),len(curr),i)
if(curr == 'onetwo'):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(curr == 'oneone'):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(curr == 'twotwo'):
l[i+1] = 'z'
# print("@")
L.append(i+2)
i += 1
ans += 1
elif(l[i:i+5] == list('twone')):
# print("*",i)
l[i+2] = 'z'
L.append(i+3)
i += 1
ans += 1
elif(curr == 'onezzz'):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(curr == 'twozzz'):
l[i+1] = 'z'
# print("yeee")
i += 1
L.append(i+2)
ans += 1
elif(l[i:i+3] == list('two')):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
elif(l[i:i+3] == list('one')):
l[i+1] = 'z'
L.append(i+2)
i += 1
ans += 1
else:
i += 1
# print("l:",''.join(l))
# print("*",''.join(l))
print(ans)
print(*L)
T = int(input())
for _ in range(T):
s = input()
solve(s)
``` | instruction | 0 | 80,936 | 24 | 161,872 |
Yes | output | 1 | 80,936 | 24 | 161,873 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
# Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)
# Problem: (C) As Simple as One and Two
# Status: Accepted
for _ in [0] * int(input()):
ins = input()
lens= len(ins)
pos = 0
answer = []
while pos < lens:
if ins[pos:pos+5] == 'twone':
answer.append(pos + 3)
pos += 5
elif ins[pos:pos+3] == 'two':
answer.append(pos + 2)
pos += 3
elif ins[pos:pos+3] == "one":
answer.append(pos + 2)
pos += 3
else:
pos += 1
print(len(answer))
print(*answer)
``` | instruction | 0 | 80,937 | 24 | 161,874 |
Yes | output | 1 | 80,937 | 24 | 161,875 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
# lET's tRy ThIS...
import math
import os
import sys
#-------------------BOLT------------------#
#-------Genius----Billionare----Playboy----Philanthropist----NOT ME:D----#
input = lambda: sys.stdin.readline().strip("\r\n")
def cin(): return sys.stdin.readline().strip("\r\n")
def fora(): return list(map(int, sys.stdin.readline().strip().split()))
def string(): return sys.stdin.readline().strip()
def cout(ans): sys.stdout.write(str(ans))
def endl(): sys.stdout.write(str("\n"))
def ende(): sys.stdout.write(str(" "))
#---------ND-I-AM-IRON-MAN------------------#
def countDigit(n):
return math.floor(math.log(n, 10)+1)
def main():
for _ in range(int(input())):
#LET's sPill the BEANS
s=string()
a=[]
cnt=0
i=0
while(i<len(s)-2):
if(s[i]=='t'):
if(s[i+1]=='w'):
if(s[i+2]=='o'):
cnt+=1
if(i<len(s)-4 and s[i+3]=='n'):
if(s[i+4]=='e'):
a.append(i+3)
i+=4
else:
a.append(i+2)
i+=2
else:
a.append(i+2)
i+=2
elif(s[i]=='o'):
if(s[i+1]=='n'):
if(s[i+2]=='e'):
cnt+=1
a.append(i+2)
i+=2
i+=1
if(cnt==0):
cout(cnt)
else:
cout(cnt)
endl()
for i in a:
cout(i)
ende()
endl()
if __name__ == "__main__":
main()
``` | instruction | 0 | 80,938 | 24 | 161,876 |
Yes | output | 1 | 80,938 | 24 | 161,877 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
t = int(input())
for i in range(t):
s = input()
ss = []
c = 0
j = 0
while j < len(s)-2:
if s[j:j+3] == 'one' or s[j:j+3] == 'two':
ss.append(j+1)
c = c + 1
j = j + 3
else:
j = j + 1
print(c)
print(' '.join(map(str,ss)))
``` | instruction | 0 | 80,939 | 24 | 161,878 |
No | output | 1 | 80,939 | 24 | 161,879 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
for _ in range(int(input())):
old = list(input())
lst = []
i =0
while i<(len(old)-2):
if old[i]+old[i+1]+old[i+2]=='one' or old[i]+old[i+1]+old[i+2]=='two':
lst.append(i)
i+=3
else:
i+=1
print(len(lst))
if lst:
for j in lst:
print(j,end=" ")
print()
``` | instruction | 0 | 80,940 | 24 | 161,880 |
No | output | 1 | 80,940 | 24 | 161,881 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
a = int(input())
for x in range(a):
b = input()
c = len(b)
d = list(b)
k = 0
h = []
if c == 1 and c == 2:
print(0)
print()
elif c == 3:
if d[0] == "o":
if d[1] == "n":
if d[2] == "e":
k += 1
d[0] = "@"
h.append(1)
elif d[2] == "o":
if d[1] == "w":
if d[0] == "t":
k += 1
d[2] = "@"
h.append(3)
for y in range(c):
if d[y] == "o":
if y == 0 or y == 1:
if d[y+1] == "n":
if d[y+2] == "e":
k += 1
d[y+2] = "@"
h.append(y+3)
elif y == c-2 or y == c-1:
if d[y-1] =="w":
if d[y-2] == "t":
k += 1
d[y-2] = "@"
h.append(y-1)
else:
if (d[y+1] == "n" and d[y+2] == "e" ) and (d[y-1] == "w" and d[y-2] == "t"):
k += 1
d[y] = "@"
h.append(y+1)
elif (d[y+1] == "n" and d[y+2] == "e" ):
k += 1
d[y+2] == "@"
h.append(y+3)
elif (d[y-1] == "w" and d[y-2] == "t"):
k += 1
d[y-2] == "@"
h.append(y-1)
print(k)
print(*h)
``` | instruction | 0 | 80,941 | 24 | 161,882 |
No | output | 1 | 80,941 | 24 | 161,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j (1 β€ j β€ n-2), that s_{j}s_{j+1}s_{j+2}="one" or s_{j}s_{j+1}s_{j+2}="two".
For example:
* Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),
* Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two").
Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.
For example, if the string looks like s="onetwone", then if Polycarp selects two indices 3 and 6, then "onetwone" will be selected and the result is "ontwne".
What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?
Input
The first line of the input contains an integer t (1 β€ t β€ 10^4) β the number of test cases in the input. Next, the test cases are given.
Each test case consists of one non-empty string s. Its length does not exceed 1.5β
10^5. The string s consists only of lowercase Latin letters.
It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed 1.5β
10^6.
Output
Print an answer for each test case in the input in order of their appearance.
The first line of each answer should contain r (0 β€ r β€ |s|) β the required minimum number of positions to be removed, where |s| is the length of the given line. The second line of each answer should contain r different integers β the indices themselves for removal in any order. Indices are numbered from left to right from 1 to the length of the string. If r=0, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.
Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21
1
1
1
3
1
2
1
6
0
1
4
0
1
1
2
1 11
Note
In the first example, answers are:
* "onetwone",
* "testme" β Polycarp likes it, there is nothing to remove,
* "oneoneone",
* "twotwo".
In the second example, answers are:
* "onetwonetwooneooonetwooo",
* "two",
* "one",
* "twooooo",
* "ttttwo",
* "ttwwoo" β Polycarp likes it, there is nothing to remove,
* "ooone",
* "onnne" β Polycarp likes it, there is nothing to remove,
* "oneeeee",
* "oneeeeeeetwooooo".
Submitted Solution:
```
t = int(input())
for _ in range(t):
s = input()
one_pointer = 0
two_pointer = 0
one_counter = ['o', 'n', 'e']
two_counter = ['t', 'w', 'o']
i = 0
ans = []
while i < (len(s)):
if i == 0:
if s[i] == "o":
one_pointer += 1
elif s[i] == "t":
two_pointer += 1
else:
if s[i] == one_counter[one_pointer] or s[i] == two_counter[two_pointer]:
if one_pointer == 2 or two_pointer == 2:
if one_pointer == 2:
one_pointer -= 1
if two_pointer == 2:
two_pointer -= 1
ans.append(i+1)
i += 1
continue
else:
if s[i] == one_counter[one_pointer]:
one_pointer += 1
two_pointer = 0
if s[i] == two_counter[two_pointer]:
two_pointer += 1
one_pointer = 0
else:
if s[i] != one_counter[one_pointer]:
if s[i] == "o":
one_pointer = 1
else:
one_pointer = 0
if s[i] != two_counter[two_pointer]:
if s[i] == "t":
two_pointer = 1
else:
two_pointer = 0
i += 1
print(len(ans))
print(*ans)
``` | instruction | 0 | 80,942 | 24 | 161,884 |
No | output | 1 | 80,942 | 24 | 161,885 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,360 | 24 | 162,720 |
Tags: implementation
Correct Solution:
```
I = input
n, m = map(int, I().split())
board = []
yup, ydown, xleft, xrigth = 0, n, 0, m
for _ in range(n):
board.append(I())
for row in board:
if 'B' not in row:
yup += 1
else:
break
for row in board[::-1]:
if 'B' not in row:
ydown -= 1
else:
break
tr = list(zip(*board))
for row in tr:
if 'B' not in row:
xleft += 1
else:
break
for row in tr[::-1]:
if 'B' not in row:
xrigth -= 1
else:
break
if ydown - yup < 0:
print(1)
elif ydown - yup > m or xrigth - xleft > n:
print(-1)
else:
cnt = 0
for i in range(yup,ydown):
for j in range(xleft, xrigth):
if board[i][j]=='B':
cnt += 1
print(max(ydown - yup, xrigth - xleft) ** 2 - cnt)
``` | output | 1 | 81,360 | 24 | 162,721 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,361 | 24 | 162,722 |
Tags: implementation
Correct Solution:
```
import traceback
import os
import sys
from io import BytesIO, IOBase
import math
from collections import defaultdict, Counter
from functools import lru_cache
from itertools import accumulate
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")
def geti():
return int(input())
def gets():
return input()
def getil():
return list(map(int, input().split()))
def getsl():
return input().split()
def getinps(s):
inps = s.split()
m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
if len(inps) == 1: return m[s]()
return [m[k]() for k in inps]
def get2d(nrows, ncols, n=0):
return [[n] * ncols for r in range(nrows)]
def get_acc(a):
return list(accumulate(a))
def get_ncr(n, r):
if n < r: return 0
return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def get_npr(n, r):
if n < r: return 0
return math.factorial(n) // math.factorial(r)
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
inf = float('inf')
mod = 10 ** 9 + 7
def main():
N, M = getinps('il')
g = [gets() for _ in range(N)]
mnr, mxr = inf, -inf
mnc, mxc = inf, -inf
ans = 0
for i in range(N):
for j in range(M):
if g[i][j] == 'B':
ans -= 1
mnr = min(mnr, i)
mxr = max(mxr, i)
mnc = min(mnc, j)
mxc = max(mxc, j)
if ans == 0: return 1
s = max(abs(mnr-mxr), abs(mnc-mxc)) + 1
if s > min(N, M): return -1
ans += s * s
return ans
try:
ans = main()
print(ans)
except Exception as e:
print(e)
traceback.print_exc()
``` | output | 1 | 81,361 | 24 | 162,723 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,362 | 24 | 162,724 |
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
min_x = m
min_y = n
max_x = 0
max_y = 0
r = -1
s = 0
for y in range(n):
str = input()
for x in range(m):
if str[x] == 'B':
s += 1
if y < min_y:
min_y = y
if x < min_x:
min_x = x
if y > max_y:
max_y = y
if x > max_x:
max_x = x
if s > 0:
w = max_x-min_x+1
h = max_y-min_y+1
offset = abs(w-h)
if w < h:
if (offset+w) <= m:
w += offset
elif (h < w) and ((offset+h) <= n):
h += offset
if w == h:
r = w*h-s
else:
r = 1
print(r)
``` | output | 1 | 81,362 | 24 | 162,725 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,363 | 24 | 162,726 |
Tags: implementation
Correct Solution:
```
def polycarp(n, m, l):
left = min(l).find("B")
if left == -1:
return 1
right = m - min([x[::-1] for x in l]).find("B") - 1
top = bottom = -1
for i in range(n):
if l[i].find("B") != -1:
top = i
break
for i in range(n - 1, -1, -1):
if l[i].find("B") != -1:
bottom = i
break
w = right - left + 1
h = bottom - top + 1
if w > n or h > m:
return -1
r = 0
for i in range(top, bottom + 1):
for j in range(left, right + 1):
if l[i][j] == "W":
r += 1
if w > h:
r += (w - h) * w
else:
r += (h - w) * h
return r
n, m = list(map(int, input().strip().split()))
l = list()
for i in range(n):
l.append(input().strip())
print(polycarp(n, m, l))
``` | output | 1 | 81,363 | 24 | 162,727 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,364 | 24 | 162,728 |
Tags: implementation
Correct Solution:
```
length, width = map(int, input().strip().split());
left, right, up, down = 101, -1, 101, -1
count = 0
for i in range(length):
string = input()
for j in range(width):
if (string[j] == 'B'):
count += 1
left = min(left, j)
right = max(right, j)
up = min(up, i)
down = max(down, i)
if count == 0:
print('1')
elif right-left+1 > min(length, width) or down-up+1 > min(length,width):
print('-1')
else:
square_width = max(right-left+1, down-up+1)
print(square_width ** 2 - count)
area = length * width
``` | output | 1 | 81,364 | 24 | 162,729 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,365 | 24 | 162,730 |
Tags: implementation
Correct Solution:
```
n, m = map(int, input().split())
c = []
a = []
numBlack = 0
for i in range(n):
st = str(input())
#print(st)
c.append([])
for ch in st:
c[i].append(ch)
s = []
#print(c)
for i in range(n):
a.append([0]*m)
s.append([0]*m)
for j in range(m):
if (c[i][j] == 'W'):
a[i][j] = 0
else:
a[i][j] = 1
numBlack = numBlack + a[i][j]
s[0][0] = a[0][0]
for i in range(1, n):
s[i][0] = s[i - 1][0] + a[i][0]
for j in range(1, m):
s[0][j] = s[0][j - 1] + a[0][j]
for i in range(1, n):
for j in range(1, m):
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j]
#print(numBlack)
res = 123456789
for len in range(1, min(n, m) + 1):
for i in range(n - len + 1):
for j in range(m - len + 1):
square = len * len
if (i == 0):
One = 0;
else:
One = s[i - 1][j + len - 1];
Three = 0
if (j == 0):
Two = 0;
Three = 0
else:
Two = s[i + len - 1][j - 1];
if (i > 0 and j > 0): Three = s[i - 1][j - 1]
Four = s[i + len - 1][j + len - 1];
Black = Four - One - Two + Three
if (Black != numBlack): continue
#print(len, ' ',i,' ',j,' ',Black,' ', square)
cur = square - Black
res = min(res, cur)
if (res == 123456789): res = -1
print(res)
``` | output | 1 | 81,365 | 24 | 162,731 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,366 | 24 | 162,732 |
Tags: implementation
Correct Solution:
```
n,k=map(int,input().split(' '))
b=[]
r=[]
c=[]
for i in range (n):
b.append(input())
for i in range(n):
for j in range(k):
if b[i][j]=='B':
r.append(i)
c.append(j)
if len(c)==0:
print(1)
else:
maxr=max(r)-min(r)
maxc=max(c)-min(c)
size=max(maxc,maxr)+1
if (size>n or size>k):
print(-1)
else:
print(size**2-len(c))
``` | output | 1 | 81,366 | 24 | 162,733 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a checkered sheet of paper of size n Γ m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
Input
The first line contains two integers n and m (1 β€ n, m β€ 100) β the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each β the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
Output
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
Examples
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
Note
In the first example it is needed to paint 5 cells β (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black. | instruction | 0 | 81,367 | 24 | 162,734 |
Tags: implementation
Correct Solution:
```
n,m=map(int,input().split())
matr=[list(input()) for i in range(n)]
h1=h2=w1=w2=-1
cout=0
for i,x in enumerate(matr):
for j,y in enumerate(x):
if y=='B':
if h1==-1:
h1=h2=i
w1=w2=j
else:
h2=i
if j<w1:w1=j
if j>w2:w2=j
cout+=1
res=max(h2-h1+1,w2-w1+1)
if res>n or res>m:print(-1)
else:print(res*res-cout)
``` | output | 1 | 81,367 | 24 | 162,735 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes. | instruction | 0 | 81,732 | 24 | 163,464 |
Tags: binary search, dp, math
Correct Solution:
```
from math import sqrt
class pro(object):
def __init__(self,dif,sc):
self.dif=dif
self.sc=sc
def __lt__(self,other):
return self.dif>other.dif
T=int(input())
mul=[1]
for i in range(100):
mul.append(mul[i]*10/9)
inf=1000000007
for t in range(T):
n=int(input())
effi,tim=map(float,input().split())
prob=[]
for i in range(n):
x,y=map(int,input().split())
prob.append(pro(x,y))
prob.sort()
f=[[inf for i in range(n+1)] for j in range(1001)]
f[0][0]=0
totsc=0
for i in range(n):
totsc+=prob[i].sc
for j in range(totsc,prob[i].sc-1,-1):
for k in range(1,i+2):
f[j][k]=min(f[j][k],f[j-prob[i].sc][k-1]+prob[i].dif*mul[k])
for i in range(totsc,-1,-1):
flag=False
for j in range(n+1):
if sqrt(effi*f[i][j])>=1:
res=2*sqrt(f[i][j]/effi)-1/effi+10*j
else:
res=f[i][j]+10*j
if res<=tim:
print(i)
flag=True
break
if flag==True:
break
``` | output | 1 | 81,732 | 24 | 163,465 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort(reverse=True)
dp = [[-1]*1004 for i in range(n+1)]
#z = [0]*1004
dp[0][0] = 0
idx = -1
_9 = [1]*101
_10 = [10]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
_10[i] = _10[i-1]*10
for i in v:
a, p = i #[:2]
for k in range(n-1, -1, -1):
for j in range(1001-p):
if dp[k][j] >= 0:
d = dp[k][j]*9+a*_10[k]
if dp[k+1][j+p] < 0 or dp[k+1][j+p] > d:
dp[k+1][j+p] = d
for j in range(1000, -1, -1):
for k in range(n+1):
d = dp[k][j]
if d < 0:
continue
ok = False
if C*d < 250*(_9[k]):
ok = (d*1000 <= (T-k*10000)*(_9[k]))
elif (T-k*10000)*C+1000000 < 0:
ok = False
else:
ok = 4000000000*d*C <= (((T-k*10000)*C+1000000)**2)*(_9[k])
if ok:
print(j)
return
print(0)
tc = mint()
for i in range(tc):
solve()
``` | instruction | 0 | 81,733 | 24 | 163,466 |
No | output | 1 | 81,733 | 24 | 163,467 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort()
dp = [[-1]*1004 for i in range(n+1)]
#z = [0]*1004
dp[0][0] = 0
idx = -1
_9 = [1]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
for i in v:
a, p = i #[:2]
for k in range(n-1, -1, -1):
for j in range(1001-p):
if dp[k][j] >= 0:
d = (dp[k][j]+a*_9[k])*10
if dp[k+1][j+p] < 0 or dp[k+1][j+p] > d:
dp[k+1][j+p] = d
for j in range(1000, -1, -1):
for k in range(n+1):
d = dp[k][j]
if d < 0:
continue
ok = False
if C*d < 250*(_9[k]):
ok = (d*1000 <= (T-k*10000)*(_9[k]))
elif (T-k*10000)*C+1000000 < 0:
ok = False
else:
ok = 4000000000*d*C <= (((T-k*10000)*C+1000000)**2)*(_9[k])
if ok:
print(j)
return
print(0)
tc = mint()
for i in range(tc):
solve()
``` | instruction | 0 | 81,734 | 24 | 163,468 |
No | output | 1 | 81,734 | 24 | 163,469 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort()
dp = [0]*1004
dk = [1000]*1004
#z = [0]*1004
dp[0] = 0
dk[0] = 0
idx = -1
_9 = [1]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
for i in v:
a, p = i #[:2]
idx += 1
for j in range(1000, -1, -1):
if dk[j] >= 0 and dk[j] < 1000 and j+p <= 1000:
d = (dp[j]+a*_9[dk[j]])*10
if dk[j+p] > dk[j] + 1 \
or (dk[j+p] == dk[j] + 1 and dp[j+p] > d):
dk[j+p] = dk[j] + 1
dp[j+p] = d
#z[j+p] = idx
M = 0
#print([(dp[i],dk[i],v[z[i]][2]) for i in range(20)])
for j in range(1000, -1, -1):
if dk[j] > 100:
continue
ok = False
#t = 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000)
#4*dp[j]/(9**dk[j]*C/1000) < 1./(C^2/1000000)
#dp[j]*C < 250.*(9**dk[j])
if C*dp[j] < 1000*(9**dk[j]): # dp[j]/(9**dk[k])*(C/1000) <= 1
ok = (dp[j]*1000 <= (T-dk[j]*10000)*(9**dk[j])) # ok = dk[j]*10 + dp[j]/(9**dk[j]) <= T/1000
elif (T-dk[j]*10000)*C+1000000 < 0:
ok = False
else:# ok = dk[j]*10 + 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000) <= T/1000
# ok = dk[j]*10000 + 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) - 1000000./C <= T
# ok = 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) <= T-dk[j]*10000+1000000./C
#ok = 4000000*(dp[j]*C*1000/(9**dk[j])) <= ((T-dk[j]*10000)*C+1000000)**2
ok = 4000000000*dp[j]*C <= (((T-dk[j]*10000)*C+1000000)**2)*(9**dk[j])
if ok:
M = j
if False:
jj = j
print(dp[j], dk[j], C*dp[j], 250*(9**dk[j]))
while jj != 0:
print(v[z[jj]][2], end=' ')
jj -= v[z[jj]][1]
print()
break
print(M)
tc = mint()
for i in range(tc):
solve()
``` | instruction | 0 | 81,735 | 24 | 163,470 |
No | output | 1 | 81,735 | 24 | 163,471 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i β its difficulty and the score awarded by its solution.
Polycarp's experience suggests that his skill level is defined with positive real value s, and initially s=1.0. To solve the i-th problem Polycarp needs a_i/s minutes.
Polycarp loves to watch series, and before solving each of the problems he will definitely watch one episode. After Polycarp watches an episode, his skill decreases by 10\%, that is skill level s decreases to 0.9s. Each episode takes exactly 10 minutes to watch. When Polycarp decides to solve some problem, he firstly has to watch one episode, and only then he starts solving the problem without breaks for a_i/s minutes, where s is his current skill level. In calculation of a_i/s no rounding is performed, only division of integer value a_i by real value s happens.
Also, Polycarp can train for some time. If he trains for t minutes, he increases his skill by C β
t, where C is some given positive real constant. Polycarp can train only before solving any problem (and before watching series). Duration of the training can be arbitrary real value.
Polycarp is interested: what is the largest score he can get in the contest? It is allowed to solve problems in any order, while training is only allowed before solving the first problem.
Input
The first line contains one integer tc (1 β€ tc β€ 20) β the number of test cases. Then tc test cases follow.
The first line of each test contains one integer n (1 β€ n β€ 100) β the number of problems in the contest.
The second line of the test contains two real values C, T (0 < C < 10, 0 β€ T β€ 2 β
10^5), where C defines the efficiency of the training and T is the duration of the contest in minutes. Value C, T are given exactly with three digits after the decimal point.
Each of the next n lines of the test contain characteristics of the corresponding problem: two integers a_i, p_i (1 β€ a_i β€ 10^4, 1 β€ p_i β€ 10) β the difficulty and the score of the problem.
It is guaranteed that the value of T is such that changing it by the 0.001 in any direction will not change the test answer.
Please note that in hacks you can only use tc = 1.
Output
Print tc integers β the maximum possible score in each test case.
Examples
Input
2
4
1.000 31.000
12 3
20 6
30 1
5 1
3
1.000 30.000
1 10
10 10
20 8
Output
7
20
Note
In the first example, Polycarp can get score of 7 as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 4-th problem: he watches one episode in 10 minutes, his skill level decreases to s=5*0.9=4.5 and then he solves the problem in 5/s=5/4.5, which is roughly 1.111 minutes;
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill level decreases to s=4.5*0.9=4.05 and then he solves the problem in 20/s=20/4.05, which is roughly 4.938 minutes.
This way, Polycarp uses roughly 4+10+1.111+10+4.938=30.049 minutes, to get score of 7 points. It is not possible to achieve larger score in 31 minutes.
In the second example, Polycarp can get 20 points as follows:
1. Firstly he trains for 4 minutes, increasing s to the value of 5;
2. Then he decides to solve 1-st problem: he watches one episode in 10 minutes, his skill decreases to s=5*0.9=4.5 and then he solves problem in 1/s=1/4.5, which is roughly 0.222 minutes.
3. Finally, he decides to solve 2-nd problem: he watches one episode in 10 minutes, his skill decreases to s=4.5*0.9=4.05 and then he solves the problem in 10/s=10/4.05, which is roughly 2.469 minutes.
This way, Polycarp gets score of 20 in 4+10+0.222+10+2.469=26.691 minutes. It is not possible to achieve larger score in 30 minutes.
Submitted Solution:
```
import sys
from math import *
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def frac(x):
a = x.split('.')
return int(a[0])*1000+int(a[1])
def solve():
n = mint()
C, T = map(frac, minp().split())
v = [None]*n
for i in range(n):
a, p = mints()
v[i] = (a, p) #, i)
v.sort()
dp = [0]*1004
dk = [1000]*1004
#z = [0]*1004
dp[0] = 0
dk[0] = 0
idx = -1
_9 = [1]*101
for i in range(1,101):
_9[i] = _9[i-1]*9
for i in v:
a, p = i #[:2]
idx += 1
for j in range(1000, -1, -1):
if dk[j] >= 0 and dk[j] < 1000 and j+p <= 1000:
d = (dp[j]+a*_9[dk[j]])*10
if dk[j+p] > dk[j] + 1 \
or (dk[j+p] == dk[j] + 1 and dp[j+p] > d):
dk[j+p] = dk[j] + 1
dp[j+p] = d
#z[j+p] = idx
M = 0
#print([(dp[i],dk[i],v[z[i]][2]) for i in range(20)])
for j in range(1000, -1, -1):
if dk[j] > 100:
continue
ok = False
#t = 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000)
#4*dp[j]/(9**dk[j]*C/1000) < 1./(C^2/1000000)
#dp[j]*C < 250.*(9**dk[j])
if C*dp[j] < 250*(9**dk[j]): # t < 0
ok = (dp[j]*1000 <= (T-dk[j]*10000)*(9**dk[j])) # ok = dk[j]*10 + dp[j]/(9**dk[j]) <= T/1000
elif (T-dk[j]*10000)*C+1000000 < 0:
ok = False
else:# ok = dk[j]*10 + 2*sqrt(dp[j]/(9**dk[j]*C/1000)) - 1./(C/1000) <= T/1000
# ok = dk[j]*10000 + 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) - 1000000./C <= T
# ok = 2000*sqrt(dp[j]*1000/(9**dk[j]*C)) <= T-dk[j]*10000+1000000./C
#ok = 4000000*(dp[j]*C*1000/(9**dk[j])) <= ((T-dk[j]*10000)*C+1000000)**2
ok = 4000000000*dp[j]*C <= (((T-dk[j]*10000)*C+1000000)**2)*(9**dk[j])
if ok:
M = j
if False:
jj = j
print(dp[j], dk[j], C*dp[j], 250*(9**dk[j]))
while jj != 0:
print(v[z[jj]][2], end=' ')
jj -= v[z[jj]][1]
print()
break
print(M)
tc = mint()
for i in range(tc):
solve()
``` | instruction | 0 | 81,736 | 24 | 163,472 |
No | output | 1 | 81,736 | 24 | 163,473 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,934 | 24 | 163,868 |
Tags: dp, implementation, strings
Correct Solution:
```
t = int(input())
for i in range(t):
n = int(input())
a = input()
if a[0] + a[n - 3] + a[n - 2] + a[n - 1] == "2020" or a[0] + a[1] + a[n - 2] + a[n - 1] == "2020" or a[0] + a[
1] + a[2] + a[3] == "2020" or a[0] + a[1] + a[2] + a[n - 1] == "2020" or a[n - 4] + a[n - 3] + a[n - 2] + a[
n - 1] == "2020":
print("YES")
else :
print("NO")
``` | output | 1 | 81,934 | 24 | 163,869 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,935 | 24 | 163,870 |
Tags: dp, implementation, strings
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
s=input()
flag=-1
if s[0]=="2":
flag=3
if s[1]=="0":
flag=2
if s[2]=="2":
flag=1
if s[3]=="0":
flag=0
if flag==-1:
if s[n-4:]=="2020":
print("YES")
else:
print("NO")
else:
temp="2020"
if flag==0:
print("YES")
else:
if s[n-flag:]==temp[4-flag:]:
print("YES")
else:
print("NO")
``` | output | 1 | 81,935 | 24 | 163,871 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,936 | 24 | 163,872 |
Tags: dp, implementation, strings
Correct Solution:
```
t = int(input())
for ioijhjgyjvbrbgj in range (t):
n = int(input())
s = input()
if (s[0]=="2"):
if (s[1] == "0"):
if (s[2] == "2"):
if (s[3] == "0"):
print ("YES")
elif (s[n-1] == "0"):
print ("YES")
else:
print ("NO")
elif (s[n-2] == "2" and s[n-1] == "0"):
print ("YES")
else:
print ("NO")
elif (s[n-3] == "0" and s[n-2] == "2" and s[n-1] == "0"):
print ("YES")
else:
print ("NO")
elif(s[n-4] == "2" and s[n-3] == "0" and s[n-2] == "2" and s[n-1] == "0"):
print ("YES")
else:
print ("NO")
``` | output | 1 | 81,936 | 24 | 163,873 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,937 | 24 | 163,874 |
Tags: dp, implementation, strings
Correct Solution:
```
t = int(input())
for _ in range(t):
n = int(input())
s = str(input())
if s == '2020':
print('YES')
continue
m = len(s)-4
flag = False
for i in range(n-m+1):
t = s[0:i]+s[i+m:]
#print(t)
if t == '2020':
flag = True
break
if flag:
print('YES')
else:
print('NO')
``` | output | 1 | 81,937 | 24 | 163,875 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,938 | 24 | 163,876 |
Tags: dp, implementation, strings
Correct Solution:
```
# cook your dish here
for _ in range(int(input())):
n = int(input())
s = input()
flag = 0
if s[0] == "2" and s[n-1] == "0" and s[n-2] == "2" and s[n-3] == "0":
flag = 1
if s[0] == "2" and s[n-1] == "0" and s[n-2] == "2" and s[1] == "0":
flag = 1
if s[0] == "2" and s[1] == "0" and s[2] == "2" and s[n-1] == "0":
flag = 1
if s[0] == "2" and s[3] == "0" and s[2] == "2" and s[1] == "0":
flag = 1
if s[n-4] == "2" and s[n-1] == "0" and s[n-2] == "2" and s[n-3] == "0":
flag = 1
if flag == 1:
print("YES")
else:
print("NO")
``` | output | 1 | 81,938 | 24 | 163,877 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,939 | 24 | 163,878 |
Tags: dp, implementation, strings
Correct Solution:
```
from collections import defaultdict
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
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)
def input(): return sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
for _ in range(int(input())):
n=int(input())
s=list(input())
last=0
first=0
if s[0]=="2" and s[1]=="0" and s[2]=="2" and s[3]=="0":
last=1
first=1
if s[-1]=="0" and s[-2]=="2" and s[-3]=="0" and s[-4]=="2":
last=1
first=1
if s[0]=="2" and s[-1]=="0" and s[-2]=="2" and s[-3]=="0":
last=1
first=1
if s[0]=="2" and s[1]=="0" and s[2]=="2" and s[-1]=="0":
first=1
last=1
if s[0]=="2" and s[1]=="0" and s[-2]=="2" and s[-1]=="0":
first=1
last=1
if first==1 and last==1:
print("YES")
else:
print("NO")
``` | output | 1 | 81,939 | 24 | 163,879 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,940 | 24 | 163,880 |
Tags: dp, implementation, strings
Correct Solution:
```
t=int(input())
for z in range(t):
n=int(input())
s=input()
if s[:4]=="2020" or s[n-4:]=="2020":
print("YES")
elif s[0]=="2" and s[n-3:]=="020":
print("YES")
elif s[:2]=="20" and s[n-2:]=="20":
print("YES")
elif s[:3]=="202" and s[-1]=="0":
print("YES")
else:
print("NO")
``` | output | 1 | 81,940 | 24 | 163,881 |
Provide tags and a correct Python 3 solution for this coding contest problem.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string. | instruction | 0 | 81,941 | 24 | 163,882 |
Tags: dp, implementation, strings
Correct Solution:
```
for _ in range(int(input())):
n=int(input())
s=list(input())
if (s[0]=='2' and s[1]=='0' and s[2]=='2' and s[3]=='0') or (s[0]=='2' and s[1]=='0' and s[2]=='2' and s[-1]=='0') or (s[0]=='2' and s[1]=='0' and s[-2]=='2' and s[-1]=='0')or (s[0]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0') or (s[-4]=='2' and s[-3]=='0' and s[-2]=='2' and s[-1]=='0'):
print('YES')
else:
print('NO')
``` | output | 1 | 81,941 | 24 | 163,883 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
def R(): return map(int, input().split())
def L(): return list(map(int, input().split()))
def I(): return int(input())
def S(): return str(input())
for _ in range(I()):
l=I()
s=S()
fl=False
for i in range(5):
if i-1<l and l-4+i>=0 and s[0:i]+s[l-4+i:l]=='2020':
print('YES')
fl=True
break
if not fl:
print('NO')
``` | instruction | 0 | 81,942 | 24 | 163,884 |
Yes | output | 1 | 81,942 | 24 | 163,885 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t = int(input())
for j in range(t):
n = int(input())
s = input()
req = '2020'
f = False
if n < 4:
pritn('no')
else:
for i in range(4):
if s[0:i] == req[0:i] and s[-1*(4-i):] == req[i:]:
print('yes')
f = True
break
if s[0:4] == '2020' and f == False:
f = True
print('yes')
if f == False:
print('no')
``` | instruction | 0 | 81,943 | 24 | 163,886 |
Yes | output | 1 | 81,943 | 24 | 163,887 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
for _ in range(int(input())):
n = int(input())
s = input()
# if s[0:5]=="2020":
# print("yes")
# continue
# flag = 0
if s[n - 4:n] == "2020":
print("Yes")
elif s[0] + s[n - 3:n] == "2020":
print("Yes")
elif s[0:2] + s[n - 2:n] == "2020":
print("Yes")
elif s[0:3] + s[n - 1:n] == "2020":
print("Yes")
elif s[0:4] == "2020":
print("Yes")
else:
print("NO")
``` | instruction | 0 | 81,944 | 24 | 163,888 |
Yes | output | 1 | 81,944 | 24 | 163,889 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t = int(input())
while t:
n = int(input())
s = input()
if(s.startswith("2020") or s.endswith("2020") or (s.startswith("2") and s.endswith("020")) or (s.startswith("20") and s.endswith("20")) or (s.startswith("202") and s.endswith("0"))):
print("YES")
else: print("NO")
t-=1
``` | instruction | 0 | 81,945 | 24 | 163,890 |
Yes | output | 1 | 81,945 | 24 | 163,891 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t=int(input())
for _i in range(t):
n=int(input())
s=input()
arr=[]
ans=""
for i in range(1,5):
ans=""
ans+=s[0:i]+s[n-4+i:]
arr.append(ans)
if("2020" in arr):
print("YES")
else:
print("NO")
``` | instruction | 0 | 81,946 | 24 | 163,892 |
No | output | 1 | 81,946 | 24 | 163,893 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
t = int(input())
for i in range(t):
n = int(input())
s = input()
for p in range(n):
for q in range(n):
test = s[:p-1]+s[q:]
nn = 0
if test == "2020":
print('YES')
break
test=""
if test == "2020":
test=''
break
#print(test)
``` | instruction | 0 | 81,947 | 24 | 163,894 |
No | output | 1 | 81,947 | 24 | 163,895 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
l2=["2020","202","20","2"]
def func():
possible=False
for k in range(len(l2)):
if l2[k] in string:
if k == 0:
possible= True
return possible
elif k==1:
c=string.find(l2[k])
c+=3
kk=string[c:]
if kk != "":
cc=kk.find("0")
if cc != -1 and cc+1 != len(kk[cc:]):
possible = True
return possible
elif k== 2:
c=string.find(l2[k])
c+=2
kk=string[c:]
if kk != "":
cc=kk.find("20")
if cc != -1 and cc+2 != len(kk[cc:]):
possible = True
return possible
elif k==3:
c=string.find(l2[k])
c+=1
kk=string[c:]
if kk != "":
cc=kk.find("020")
if cc != -1 and cc+3 != len(kk[cc:]):
possible = True
return possible
for _ in range(int(input())):
x=int(input())
string=input()
l1=list(string)
if func() == True:
print("YES")
else: print("NO")
``` | instruction | 0 | 81,948 | 24 | 163,896 |
No | output | 1 | 81,948 | 24 | 163,897 |
Evaluate the correctness of the submitted Python 3 solution to the coding contest problem. Provide a "Yes" or "No" response.
Polycarp has a string s[1 ... n] of length n consisting of decimal digits. Polycarp performs the following operation with the string s no more than once (i.e. he can perform operation 0 or 1 time):
* Polycarp selects two numbers i and j (1 β€ i β€ j β€ n) and removes characters from the s string at the positions i, i+1, i+2, β¦, j (i.e. removes substring s[i ... j]). More formally, Polycarp turns the string s into the string s_1 s_2 β¦ s_{i-1} s_{j+1} s_{j+2} β¦ s_{n}.
For example, the string s = "20192020" Polycarp can turn into strings:
* "2020" (in this case (i, j)=(3, 6) or (i, j)=(1, 4));
* "2019220" (in this case (i, j)=(6, 6));
* "020" (in this case (i, j)=(1, 5));
* other operations are also possible, only a few of them are listed above.
Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string s into a string "2020" in no more than one operation? Note that you can perform zero operations.
Input
The first line contains a positive integer t (1 β€ t β€ 1000 ) β number of test cases in the test. Then t test cases follow.
The first line of each test case contains an integer n (4 β€ n β€ 200) β length of the string s. The next line contains a string s of length n consisting of decimal digits. It is allowed that the string s starts with digit 0.
Output
For each test case, output on a separate line:
* "YES" if Polycarp can turn the string s into a string "2020" in no more than one operation (i.e. he can perform 0 or 1 operation);
* "NO" otherwise.
You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).
Example
Input
6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
Output
YES
YES
YES
NO
NO
NO
Note
In the first test case, Polycarp could choose i=3 and j=6.
In the second test case, Polycarp could choose i=2 and j=5.
In the third test case, Polycarp did not perform any operations with the string.
Submitted Solution:
```
def solve(n,s):
for i in range(n):
if i>4:
#print(s[:i-4],s[i:])
if s[:i-4]+s[i:]=="2020":
return "YES"
else:
#print(s[:i],s[i+4:])
if s[:i]+s[i+4:]=="2020":
return "YES"
if s=="2020":
return "YES"
return "NO"
for _ in range(int(input())):
n=int(input())
s=input()
print(solve(n,s))
``` | instruction | 0 | 81,949 | 24 | 163,898 |
No | output | 1 | 81,949 | 24 | 163,899 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,628 | 24 | 165,256 |
Tags: brute force, greedy
Correct Solution:
```
n,s = list(map(int ,input().split()))
a = list(map(int, input().split()))
a.sort(reverse = True)
t = 0
for i in range(1,n+1) :
t = 0
for j in range (n) :
t += max(0, a[j] - j//i)
if t >= s :
print(i)
exit(0)
print(-1)
``` | output | 1 | 82,628 | 24 | 165,257 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,629 | 24 | 165,258 |
Tags: brute force, greedy
Correct Solution:
```
n, m = map(int, input().split())
l = list(map(int,input().split()))
l.sort(reverse = True)
left = 1
right = n
def check(k,m):
if m > 0:
lef = 0
z = 0
for i in range(n):
m -= max(0, l[i]-lef)
z += 1
if z == k:
z = 0
lef += 1
if m <= 0:
return 1
else:
return 0
res = []
while left <= right:
mid = int((left+right)/2)
if check(mid, m):
res.append(mid)
right = mid - 1
else:
left = mid + 1
if len(res) > 0:
print(min(res))
else:
print("-1")
"""
n, m = map(int, input().split())
l = list(map(int,input().split()))
s = sum(l)
ans = 0
def find(x):
su = 0
days = 0
z = 0
for i in l:
su += max(0, i-z)
days += 1
if days == x:
days = 0
z += 1
if su < m:
return 0
return x
def binary(left, right):
global ans
mid = int((left+right)/2)
r = find(mid)
if right == left:
ans = r
elif left == right - 1:
if r:
ans = r
else:
binary(r, r)
else:
if r:
binary(left, mid)
else:
binary(mid, right)
if s < m:
print("-1")
elif s == m:
print(n)
else:
l.sort(reverse = True)
binary(1,n)
print(ans)
print(ans)
"""
``` | output | 1 | 82,629 | 24 | 165,259 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,630 | 24 | 165,260 |
Tags: brute force, greedy
Correct Solution:
```
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineering College
'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def bo(i):
return ord(i)-ord('a')
def check(a,m):
n=len(a)
c,k,s=0,0,0
for i in range(n-1,-1,-1):
if(a[i]>k):
s+=(a[i]-k)
else:
break
c+=1
if(c%m==0):
k+=1
return s
def solve():
n,m=mi()
a=li()
if(m>sum(a)):
print('-1')
exit(0)
a.sort()
l=1
r=n
ans=n
while(l<=r):
mid=l+(r-l)//2
x=check(a,mid)
if(x>=m):
ans=mid
r=mid-1
else:
l=mid+1
print(ans)
if __name__ =="__main__":
solve()
``` | output | 1 | 82,630 | 24 | 165,261 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,631 | 24 | 165,262 |
Tags: brute force, greedy
Correct Solution:
```
def fastio():
import sys
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
# fastio()
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
n, m = I()
l = I()
l.sort(reverse = True)
lo = 1
hi = 10**20
def check(k):
# s = sum(l[:k])
s = 0
i = 0
d = 0
while i < n and s < m:
s += max(0, l[i] - d)
i += 1
if i%k == 0:
# print(s)
d += 1
# print(s, m)
return s >= m
while lo < hi:
mid = (lo + hi)//2
if check(mid):
hi = mid
else:
lo = mid + 1
# print(lo, hi)
if (lo == 10**20):
print(-1)
exit()
print(lo)
``` | output | 1 | 82,631 | 24 | 165,263 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,632 | 24 | 165,264 |
Tags: brute force, greedy
Correct Solution:
```
n, m = map(int, input().split())
coffees = sorted(map(int, input().split()), reverse=True)
total = sum(coffees)
if total < m:
print(-1)
exit()
for div in range(1, n):
a = [0] * div
index = 0
for pena in range(n):
for d in range(div):
if coffees[index] <= pena:
break
a[d] += coffees[index] - pena
index += 1
if index >= n or coffees[index] <= pena:
break
if index >= n or coffees[index] <= pena:
break
if sum(a) >= m:
print(div)
exit()
print(n)
``` | output | 1 | 82,632 | 24 | 165,265 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,633 | 24 | 165,266 |
Tags: brute force, greedy
Correct Solution:
```
l=input().split()
n=int(l[0])
m=int(l[1])
l=input().split()
li=[int(i) for i in l]
li.sort()
li.reverse()
if(sum(li)<m):
print(-1)
else:
ans=0
for i in range(1,n+1):
arr=list(li)
sumi=0
for j in range(n):
sumi+=max(arr[j]-(j//i),0)
if(sumi>=m):
ans=i
break
print(ans)
``` | output | 1 | 82,633 | 24 | 165,267 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,634 | 24 | 165,268 |
Tags: brute force, greedy
Correct Solution:
```
nb_cups, nb_task = [int(x) for x in input().split()]
caffines = sorted([int(x) for x in input().split()], reverse=True)
def check(d):
done = 0
for i, v in enumerate(caffines):
done += max(0, v - i // d)
return done >= nb_task
if sum(caffines) < nb_task:
print(-1)
else:
left, rite = 1, nb_cups
mid = left + rite >> 1
while left < rite:
if check(mid):
rite = mid
else:
left = mid + 1
mid = left + rite >> 1
print(left)
``` | output | 1 | 82,634 | 24 | 165,269 |
Provide tags and a correct Python 3 solution for this coding contest problem.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1. | instruction | 0 | 82,635 | 24 | 165,270 |
Tags: brute force, greedy
Correct Solution:
```
def check(d, a):
ans = 0
for q in range(len(a)):
ans += max(a[q]-q//d, 0)
return ans
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
if sum(a) < m:
print(-1)
else:
l, r = 0, n
while r-l > 1:
m1 = (l+r)//2
if check(m1, a) >= m:
r = m1
else:
l = m1
print(r)
``` | output | 1 | 82,635 | 24 | 165,271 |
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 the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
n, m = map(int, input().split())
a = list(sorted(map(int, input().split()), reverse=True))
def proc(n, m, a):
possible_minimum = -1
l, r = 1, n
sub_c = [0] * n
while l <= r:
i = (l + r) // 2
# if i == 100:
current_m = m
for j in range(i):
sub_c[j] = 0
for j in range(0, n):
# a[j:j + i]
pos = j % i
if a[j] < sub_c[pos]:
break
current_m -= a[j] - sub_c[pos]
sub_c[pos] += 1
if current_m <= 0:
break
if current_m <= 0:
# print('[{}, {}] => {} SUCCESS'.format(l, r, i))
possible_minimum = i
r = i - 1
else:
# print('[{}, {}] => {} FAIL'.format(l, r, i))
l = i + 1
return possible_minimum
print(proc(n, m, a))
``` | instruction | 0 | 82,636 | 24 | 165,272 |
Yes | output | 1 | 82,636 | 24 | 165,273 |
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 the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
def check_possibility(days, m, coffee):
sum_coffee = 0
for i, cup in enumerate(coffee):
tax = i // days
if sum_coffee >= m or tax >= cup:
break
sum_coffee += cup - tax
return sum_coffee >= m
n, m = map(int, input().split())
coffee = sorted(map(int, input().split()), reverse=True)
bad = 0
good = len(coffee)
while good - bad > 1:
days = (bad + good) // 2
if check_possibility(days, m, coffee):
good = days
else:
bad = days
possible = check_possibility(good, m, coffee)
print(good if possible else -1)
``` | instruction | 0 | 82,637 | 24 | 165,274 |
Yes | output | 1 | 82,637 | 24 | 165,275 |
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 the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))
def solve(a,mid,s):
c=0
i=0
p=0
while(i<len(a)):
c+=max(0,a[i]-p)
i=i+1
if(not i%mid):
p+=1
if(c>=s):
return(1)
return(0)
def case(test):
n,s=li()
a=li()
if(sum(a)<s):
print(-1)
return
a.sort(reverse=True)
l,r=1,n
m=n
while(l<=r):
#print(l,r)
mid=(l+r)//2
p=solve(a,mid,s)
if(p):
r=mid-1
m=min(m,mid)
else:
l=mid+1
print(m)
for test in range(1):
case(test+1)
``` | instruction | 0 | 82,638 | 24 | 165,276 |
Yes | output | 1 | 82,638 | 24 | 165,277 |
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 the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
n, m = (int(t) for t in input().split(' '))
a = [int(t) for t in input().split(' ')]
a.sort(reverse=True)
def possible(d):
total = 0
for i in range(d):
step = 0
for j in range(i, n, d):
total += max(a[j] - step, 0)
step += 1
return total >= m
l, r = 0, n+1
while l < r:
mid = (l + r) // 2
if possible(mid):
r = mid
else:
l = mid + 1
if possible(l):
print(l)
else:
print(-1)
``` | instruction | 0 | 82,639 | 24 | 165,278 |
Yes | output | 1 | 82,639 | 24 | 165,279 |
Evaluate the correctness of the submitted Python 2 solution to the coding contest problem. Provide a "Yes" or "No" response.
The only difference between easy and hard versions is the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
from sys import stdin, stdout
from collections import Counter, defaultdict
from itertools import permutations, combinations
raw_input = stdin.readline
pr = stdout.write
def in_arr():
return map(int,raw_input().split())
def pr_num(n):
stdout.write(str(n)+'\n')
def pr_arr(arr):
for i in arr:
stdout.write(str(i)+' ')
stdout.write('\n')
range = xrange # not for python 3.0+
# main code
def check(n,m,l,mid):
temp=0
c=0
k=mid
for i in range(0,n,k):
for j in range(i,min(n,i+k)):
#print mid,i,j,l[j]-c
temp+=max(0,l[j]-c)
c+=1
#print temp,m
if temp>=m:
return 1
return 0
n,m=in_arr()
l=in_arr()
if sum(l)<m:
print -1
exit()
l.sort(reverse=True)
l1=1
r1=n
ans=n
while l1<=r1:
mid=(l1+r1)/2
if check(n,m,l,mid):
ans=mid
r1=mid-1
else:
l1=mid+1
pr_num(ans)
``` | instruction | 0 | 82,640 | 24 | 165,280 |
Yes | output | 1 | 82,640 | 24 | 165,281 |
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 the constraints.
Polycarp has to write a coursework. The coursework consists of m pages.
Polycarp also has n cups of coffee. The coffee in the i-th cup has a_i caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days).
Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work.
Let's consider some day of Polycarp's work. Consider Polycarp drinks k cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are a_{i_1}, a_{i_2}, ..., a_{i_k}. Then the first cup he drinks gives him energy to write a_{i_1} pages of coursework, the second cup gives him energy to write max(0, a_{i_2} - 1) pages, the third cup gives him energy to write max(0, a_{i_3} - 2) pages, ..., the k-th cup gives him energy to write max(0, a_{i_k} - k + 1) pages.
If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day.
Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible.
Input
The first line of the input contains two integers n and m (1 β€ n β€ 100, 1 β€ m β€ 10^4) β the number of cups of coffee and the number of pages in the coursework.
The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 100), where a_i is the caffeine dosage of coffee in the i-th cup.
Output
If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it.
Examples
Input
5 8
2 3 1 1 2
Output
4
Input
7 10
1 3 4 2 1 4 2
Output
2
Input
5 15
5 5 5 5 5
Output
1
Input
5 16
5 5 5 5 5
Output
2
Input
5 26
5 5 5 5 5
Output
-1
Note
In the first example Polycarp can drink fourth cup during first day (and write 1 page), first and second cups during second day (and write 2 + (3 - 1) = 4 pages), fifth cup during the third day (and write 2 pages) and third cup during the fourth day (and write 1 page) so the answer is 4. It is obvious that there is no way to write the coursework in three or less days in this test.
In the second example Polycarp can drink third, fourth and second cups during first day (and write 4 + (2 - 1) + (3 - 2) = 6 pages) and sixth cup during second day (and write 4 pages) so the answer is 2. It is obvious that Polycarp cannot write the whole coursework in one day in this test.
In the third example Polycarp can drink all cups of coffee during first day and write 5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15 pages of coursework.
In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write 5 + (5 - 1) + (5 - 2) + (5 - 3) = 14 pages of coursework and during second day he will write 5 pages of coursework. This is enough to complete it.
In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so the answer is -1.
Submitted Solution:
```
class Solution():
def __init__(self):
firstline=input().split()
n=int(firstline[0])
m=int(firstline[1])
a=input().split()
for i in range(n):
a[i]=int(a[i])
a.sort(key=None,reverse=True)
# print(a[0])
l=1
r=m+1
while l<r:
mid=int(l+r>>1)
sum=0
mod=int(n/mid)
less=n%mid
if less!=0:
mod+=1
cnt=0
for i in range(n):
sum+=max(0,a[i]-cnt)
cnt+=1
if cnt>=mod:
less-=1
if less<=0:
less=1000000000
mod-=1
cnt=0
if sum>=m:
r=mid
else:
l=mid+1
if r==m+1:
print('-1')
else:
print(r)
if __name__ == '__main__':
Solution()
``` | instruction | 0 | 82,641 | 24 | 165,282 |
No | output | 1 | 82,641 | 24 | 165,283 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.