output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s509180500
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) n_list = list(map(int,input().split()) n_list.sort() print(n_list[-1] - n_list[0])
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s415031183
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) S = list(map(int,input().split()) a=soretd(S) print(max(a)-min(a))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s385035577
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = list(map(intm input().split())) print(max(A) - min(A))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s200984798
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input().split()) an = list(map(int, input().split())) print(max(an) - min(an))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s561148751
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) S = list(map(int,input().split()) a=soretd(S) print(a[-1]-a[1])
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s264080382
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = input() A = list(map(int, input().split()) print(int(max(A))-int(min(A)))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s953937888
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = sorted(list(map(int, input().split()))) print(A[N+-]-A[0])
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s514373874
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) ls = list(map(int, input().split()) print(max(ls) - min(ls))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s830020890
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) A=list(map(int,input().split())) print(abs((max(A)-min(A))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s457157790
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=list(map(int,input().split()) a.sort() print(a[-1]-a[0])
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s795056281
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=list(map(int,input().split()) print(max(a)-min(a))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s129708632
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) A = list(map(int,input().split()) print(max(A)-min(A))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s228627638
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
H = list(map(int, input().split()) print(max(H)-min(H))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s377568976
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=list(map(int,input().split())) ma=max(a)-min(a) print(ma
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s082929439
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=map(int,input().split() print(max(a)-min(a))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s402233766
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
input() n=sorted(list(map(int,input().split()))) print(n[-1]- n[0])
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s000580695
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) l=list(map(int ,input().split())) print((max(l)-min(l))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s560076632
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
4 1 4 6 3
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s314179976
Accepted
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
_ = int(input()) nums = list(map(int, input().split())) max_n = 0 min_n = 100000000000000000000000 for i in nums: if max_n < i: max_n = i if min_n > i: min_n = i print(max_n - min_n)
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s091487036
Accepted
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
str_n = input() n = int(str_n) str_a = input() arr_a = str_a.split(" ") arr_ia = [] for item in arr_a: arr_ia.append(int(item)) arr_ia.sort() print(int(arr_ia[-1]) - int(arr_ia[0]))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s090459330
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) lst = [int(n) for n in input().split(" ")] val_max = 0 val_min = 0 for i in range(0,N): if val_max < i: val_max = i elseif val_min > i: val_min = i print(val_max-val_min)
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s937140030
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = input() A = [int(i) for input().split()] int(max) = 0 int(min) = 0 for i in N: if int(max) < A[i]: max = A[i] for i in N: if int(min) > A[i]: min = A[i] abs = max - min print(int(abs))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s966059635
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
import numpy as npo a=input() a=(map(int,input().split())) a=npo.array(a) a=npo.sort.() print(a[-1]-a[0]) print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("") print("")
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s934885888
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) row = input().split() max = row[0] min = row[0] for i in range(n-1): if(max < row[n-1]): max = row[n-1] for i in range(n-1): if(min > row[n-1]): min = row[n-1] print (min)
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s089994298
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input().strip()) A = map(int, input().strip().split()) max_abs_sum = 0 for i in range(len(A) - 1): for j in (i + 1, range(A)): if max_abs_sum < abs(A[i] - A[j]): max_abs_sum = abs(A[i] - A[j]) print(max_abs_sum)
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s992636995
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
N = int(input()) a = list(map(int,input().split()) print(abs(max(a)-min(a))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s188056669
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) a = list(map(int, input().split())) a.sort() print(a[n - 1]=a[0])
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s641910661
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
list = [int(i) for i in input()] print(max(max(list) - min(list)))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s692548967
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=list(map(int,input().split())) print(abs(a.max()-a.min())
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s434317429
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n=int(input()) a=list(map(int,input().split())) print(abs(max(a)-min(a))
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print the maximum absolute difference of two elements (with different indices) in A. * * *
s006647180
Runtime Error
p03308
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N
n = int(input()) nums = [int(num) for num in input().split()] num_min = nums[0] num_max = nums[0] for item in nums: if item < num_min: num_min = item elif item > num_max: num_max = item else: print(num_max - num_min)
Statement You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A.
[{"input": "4\n 1 4 6 3", "output": "5\n \n\nThe maximum absolute difference of two elements is A_3-A_1=6-1=5.\n\n* * *"}, {"input": "2\n 1000000000 1", "output": "999999999\n \n\n* * *"}, {"input": "5\n 1 1 1 1 1", "output": "0"}]
Print Q integers S_{i} to Standard Output in the following format: S_{1} S_{2} \vdots S_{Q} Note that S_{i} may not fit into a 32-bit integer. * * *
s123452375
Runtime Error
p02630
Input is given from Standard Input in the following format: N A_{1} A_{2} \cdots A_{N} Q B_{1} C_{1} B_{2} C_{2} \vdots B_{Q} C_{Q}
N = int(input()) seq = [int(x) for x in input().split()] Q = int(input()) somme = [] for i in range(Q): l = [int(x) for x in input().split()] a = l[0] b = l[1] if a in seq: e = [ b if x == a else x for x in seq] else: e = seq[:] somme.append(sum(e)) seq.clear() seq = e[:] e.clear() for i in somme: print(i) I love this game
Statement You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}. You will now successively do the following Q operations: * In the i-th operation, you replace every element whose value is B_{i} with C_{i}. For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
[{"input": "4\n 1 2 3 4\n 3\n 1 2\n 3 4\n 2 4", "output": "11\n 12\n 16\n \n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n * 2, 2, 3, 4\n * 2, 2, 4, 4\n * 4, 4, 4, 4\n\n* * *"}, {"input": "4\n 1 1 1 1\n 3\n 1 2\n 2 1\n 3 5", "output": "8\n 4\n 4\n \n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\n* * *"}, {"input": "2\n 1 2\n 3\n 1 100\n 2 100\n 100 1000", "output": "102\n 200\n 2000"}]
Print Q integers S_{i} to Standard Output in the following format: S_{1} S_{2} \vdots S_{Q} Note that S_{i} may not fit into a 32-bit integer. * * *
s120799947
Runtime Error
p02630
Input is given from Standard Input in the following format: N A_{1} A_{2} \cdots A_{N} Q B_{1} C_{1} B_{2} C_{2} \vdots B_{Q} C_{Q}
def main(): n, *i = map(int, open(0).read().split()) a = i[:n]  #数列Aのリスト _ = i[n]   #Qのこと s = sum(a)  #数列Aの総和 m = [0] * (10 ** 5 + 1)  #Aは1<A<10^5なのでラベル用リストを作成 for x in a:         #Aの個数をラベル化。リストmは個数を記録している m[x] += 1 ans = [] for b, c in zip(*[iter(i[n + 1:])] * 2): m[c] += m[b]      #cの個数にbの個数を足し算 s += (c - b) * m[b]  #s:数列Aの総和に、(c-b)×(bの個数)を足し算 m[b] = 0         #bの個数はゼロに ans.append(s)      #リストansにSの変化を記録していく print("\n".join(map(str, ans))) if __name__ == '__main__': main()
Statement You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}. You will now successively do the following Q operations: * In the i-th operation, you replace every element whose value is B_{i} with C_{i}. For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
[{"input": "4\n 1 2 3 4\n 3\n 1 2\n 3 4\n 2 4", "output": "11\n 12\n 16\n \n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n * 2, 2, 3, 4\n * 2, 2, 4, 4\n * 4, 4, 4, 4\n\n* * *"}, {"input": "4\n 1 1 1 1\n 3\n 1 2\n 2 1\n 3 5", "output": "8\n 4\n 4\n \n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\n* * *"}, {"input": "2\n 1 2\n 3\n 1 100\n 2 100\n 100 1000", "output": "102\n 200\n 2000"}]
Print Q integers S_{i} to Standard Output in the following format: S_{1} S_{2} \vdots S_{Q} Note that S_{i} may not fit into a 32-bit integer. * * *
s087422022
Runtime Error
p02630
Input is given from Standard Input in the following format: N A_{1} A_{2} \cdots A_{N} Q B_{1} C_{1} B_{2} C_{2} \vdots B_{Q} C_{Q}
# -*- coding: utf-8 -*- import collections N = int(input()) A = list(map(int, input().split())) A_amount = collections.Counter(A) result = sum(A) Q = int(input()) for q in range(Q): B, C = map(int, input().split()) B_elem = A_amount.get(B, None) if B_elem is not None: C_elem = A_amount.get(C, None) if C_elem is not None: A_amount.pop(B_elem) A_amount[C] = (C, B_elem[1]+C_elem[1]) else: A_amount.pop(B_elem) A_amount[C] = (C, B_elem[1]) result += (C-B)*B_elem[1] print(result)
Statement You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}. You will now successively do the following Q operations: * In the i-th operation, you replace every element whose value is B_{i} with C_{i}. For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
[{"input": "4\n 1 2 3 4\n 3\n 1 2\n 3 4\n 2 4", "output": "11\n 12\n 16\n \n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n * 2, 2, 3, 4\n * 2, 2, 4, 4\n * 4, 4, 4, 4\n\n* * *"}, {"input": "4\n 1 1 1 1\n 3\n 1 2\n 2 1\n 3 5", "output": "8\n 4\n 4\n \n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\n* * *"}, {"input": "2\n 1 2\n 3\n 1 100\n 2 100\n 100 1000", "output": "102\n 200\n 2000"}]
Print Q integers S_{i} to Standard Output in the following format: S_{1} S_{2} \vdots S_{Q} Note that S_{i} may not fit into a 32-bit integer. * * *
s472818845
Runtime Error
p02630
Input is given from Standard Input in the following format: N A_{1} A_{2} \cdots A_{N} Q B_{1} C_{1} B_{2} C_{2} \vdots B_{Q} C_{Q}
# -*- coding: utf-8 -*- def cal_xor(xor_list, rm_ind): ans = None for i, xi in enumerate(xor_list): if i != rm_ind: if ans is not None: ans = ans ^ xi else: ans = xi return ans (N,) = map(int, input().split()) a = list(map(int, input().split())) ans_str = "" if N == 2: print("{} {}".format(a[1], a[0])) else: xors = [] for i in range(N // 2): xors.append(a[2 * i] ^ a[2 * i + 1]) for i, ai in enumerate(a): sum_xor = cal_xor(xors, i // 2) if i % 2 == 0: ind = i + 1 else: ind = i - 1 ans = sum_xor ^ a[ind] ans_str += str(ans) + " " print(ans_str[:-1])
Statement You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}. You will now successively do the following Q operations: * In the i-th operation, you replace every element whose value is B_{i} with C_{i}. For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
[{"input": "4\n 1 2 3 4\n 3\n 1 2\n 3 4\n 2 4", "output": "11\n 12\n 16\n \n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n * 2, 2, 3, 4\n * 2, 2, 4, 4\n * 4, 4, 4, 4\n\n* * *"}, {"input": "4\n 1 1 1 1\n 3\n 1 2\n 2 1\n 3 5", "output": "8\n 4\n 4\n \n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\n* * *"}, {"input": "2\n 1 2\n 3\n 1 100\n 2 100\n 100 1000", "output": "102\n 200\n 2000"}]
Print Q integers S_{i} to Standard Output in the following format: S_{1} S_{2} \vdots S_{Q} Note that S_{i} may not fit into a 32-bit integer. * * *
s170103134
Wrong Answer
p02630
Input is given from Standard Input in the following format: N A_{1} A_{2} \cdots A_{N} Q B_{1} C_{1} B_{2} C_{2} \vdots B_{Q} C_{Q}
n, *bc = map(int, open(0).read().split()) a = [bc.pop(0) for _ in range(n)] q = bc.pop(0)
Statement You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}. You will now successively do the following Q operations: * In the i-th operation, you replace every element whose value is B_{i} with C_{i}. For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
[{"input": "4\n 1 2 3 4\n 3\n 1 2\n 3 4\n 2 4", "output": "11\n 12\n 16\n \n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n * 2, 2, 3, 4\n * 2, 2, 4, 4\n * 4, 4, 4, 4\n\n* * *"}, {"input": "4\n 1 1 1 1\n 3\n 1 2\n 2 1\n 3 5", "output": "8\n 4\n 4\n \n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\n* * *"}, {"input": "2\n 1 2\n 3\n 1 100\n 2 100\n 100 1000", "output": "102\n 200\n 2000"}]
Print Q integers S_{i} to Standard Output in the following format: S_{1} S_{2} \vdots S_{Q} Note that S_{i} may not fit into a 32-bit integer. * * *
s710346162
Wrong Answer
p02630
Input is given from Standard Input in the following format: N A_{1} A_{2} \cdots A_{N} Q B_{1} C_{1} B_{2} C_{2} \vdots B_{Q} C_{Q}
N = int(input()) A = list(map(int, input().split())) n = sum(A) M = [] P = [] for _ in range(int(input())): B, C = map(int, input().split()) if P.count(B) > 0: n = n - P.count(B) * M[P.index(B)] * (B - C) else: n = n - A.count(B) * (B - C) if A.count(B) > 0: M.append(A.count(B)) P.append(C) print(n)
Statement You have a sequence A composed of N positive integers: A_{1}, A_{2}, \cdots, A_{N}. You will now successively do the following Q operations: * In the i-th operation, you replace every element whose value is B_{i} with C_{i}. For each i (1 \leq i \leq Q), find S_{i}: the sum of all elements in A just after the i-th operation.
[{"input": "4\n 1 2 3 4\n 3\n 1 2\n 3 4\n 2 4", "output": "11\n 12\n 16\n \n\nInitially, the sequence A is 1,2,3,4.\n\nAfter each operation, it becomes the following:\n\n * 2, 2, 3, 4\n * 2, 2, 4, 4\n * 4, 4, 4, 4\n\n* * *"}, {"input": "4\n 1 1 1 1\n 3\n 1 2\n 2 1\n 3 5", "output": "8\n 4\n 4\n \n\nNote that the sequence A may not contain an element whose value is B_{i}.\n\n* * *"}, {"input": "2\n 1 2\n 3\n 1 100\n 2 100\n 100 1000", "output": "102\n 200\n 2000"}]
Print the maximum number of pairs that can be created. * * *
s839595875
Wrong Answer
p03922
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
n, m = map(int, input().split()) x = list(map(int, input().split())) data = [[] for i in range(m)] def mod(x): return x % m - 1 def insert(x): y = mod(x) data[y].append(x) for i in x: insert(i) ans = len(data[m - 1]) // 2 for i in range(m // 2): p = len(data[i]) q = len(data[m - i - 2]) if p == q: if i != m - i - 2: ans += p else: ans += p // 2 elif p > q: ans += q r = (p - q) // 2 set_i = len(set(data[i])) ans += min(r, (p - set_i) // 2) else: ans += p r = (q - p) // 2 set_j = len(set(data[m - i - 2])) ans += min(r, (q - set_j) // 2) print(ans)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the maximum number of pairs that can be created. * * *
s902952744
Wrong Answer
p03922
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
import sys def count_of_num(list, num): count = 0 for item in list: if item == num: count += 1 return count N, M = map(int, input().split()) nums = [n for n in map(int, input().split())] pairs = 0 rest = nums bFound = True while bFound: bFound = False for i in range(len(rest)): for j in range(i + 1, len(rest)): num1 = rest[i] num2 = rest[j] if (rest[i] + rest[j]) % M == 0: if (count_of_num(rest, rest[i]) % 2 == 1) or ( count_of_num(rest, rest[j]) % 2 == 1 ): pairs += 1 rest.remove(num1) rest.remove(num2) bFound = True break if bFound: break bFound = True while bFound: bFound = False for i in range(len(rest)): for j in range(i + 1, len(rest)): if rest[i] == rest[j]: num = rest[i] rest.remove(num) rest.remove(num) pairs += 1 bFound = True break if bFound: break print(pairs)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the maximum number of pairs that can be created. * * *
s802048702
Wrong Answer
p03922
The input is given from Standard Input in the following format: N M X_1 X_2 ... X_N
import math N, M = map(int, input().split()) X = list(map(int, input().split())) mod_arr = [{} for i in range(M)] for x in X: d = mod_arr[x % M] if x in d: d[x] += 1 else: d[x] = 1 ans = 0 if M == 1: print(N // 2) exit() def calc_only_one(d): sum_v = sum(d.values()) return sum_v // 2 ans += calc_only_one(mod_arr[0]) # even pattern if M % 2 == 0: ans += calc_only_one(mod_arr[M // 2]) def calc_two(d_S, d_T): res = 0 # print(d1, d2) if len(d_S) == 0: for v in d_S.values(): res += v // 2 return res elif len(d_T) == 0: for v in d_T.values(): res += v // 2 return res if sum(d_S.values()) < sum(d_T.values()): d_S, d_T = d_T, d_S cnt_S = sum(d_S.values()) cnt_T = sum(d_T.values()) remain_for_pair = cnt_S - cnt_T max_pair_cnt = sum([v // 2 for v in d_S.values()]) pair_cnt = min(remain_for_pair // 2, max_pair_cnt) res = cnt_T + pair_cnt # print(d_S, d_T) # print(remain_for_pair, max_pair_cnt, pair_cnt, res) return res for i in range(1, math.ceil(M / 2)): ans += calc_two(mod_arr[i], mod_arr[M - i]) print(ans)
Statement Takahashi is playing with N cards. The i-th card has an integer X_i on it. Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions: * The integers on the two cards are the same. * The sum of the integers on the two cards is a multiple of M. Find the maximum number of pairs that can be created. Note that a card cannot be used in more than one pair.
[{"input": "7 5\n 3 1 4 1 5 9 2", "output": "3\n \n\nThree pairs (3,2), (1,4) and (1,9) can be created.\n\nIt is possible to create pairs (3,2) and (1,1), but the number of pairs is not\nmaximized with this.\n\n* * *"}, {"input": "15 10\n 1 5 6 10 11 11 11 20 21 25 25 26 99 99 99", "output": "6"}]
Print the value of R_3. The output is considered correct if the absolute or relative error is at most 10^{-6}. * * *
s417980117
Accepted
p03888
The input is given from Standard Input in the following format: R_1 R_2
print(eval("1/" + input().replace(" ", "+1/")) ** -1)
Statement In an electric circuit, when two resistors R_1 and R_2 are connected in parallel, the equivalent resistance R_3 can be derived from the following formula: * \frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3} Given R_1 and R_2, find R_3.
[{"input": "2 3", "output": "1.2000000000\n \n\n* * *"}, {"input": "100 99", "output": "49.7487437186"}]
Print the value of R_3. The output is considered correct if the absolute or relative error is at most 10^{-6}. * * *
s517111930
Accepted
p03888
The input is given from Standard Input in the following format: R_1 R_2
import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**15 mod = 10**9 + 7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): a, b = LI() return 1 / (1 / a + 1 / b) print(main())
Statement In an electric circuit, when two resistors R_1 and R_2 are connected in parallel, the equivalent resistance R_3 can be derived from the following formula: * \frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3} Given R_1 and R_2, find R_3.
[{"input": "2 3", "output": "1.2000000000\n \n\n* * *"}, {"input": "100 99", "output": "49.7487437186"}]
Print the value of R_3. The output is considered correct if the absolute or relative error is at most 10^{-6}. * * *
s316742235
Accepted
p03888
The input is given from Standard Input in the following format: R_1 R_2
A, B = map(int, input().split()) print((A * B) / (A + B))
Statement In an electric circuit, when two resistors R_1 and R_2 are connected in parallel, the equivalent resistance R_3 can be derived from the following formula: * \frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3} Given R_1 and R_2, find R_3.
[{"input": "2 3", "output": "1.2000000000\n \n\n* * *"}, {"input": "100 99", "output": "49.7487437186"}]
Print the value of R_3. The output is considered correct if the absolute or relative error is at most 10^{-6}. * * *
s999609503
Runtime Error
p03888
The input is given from Standard Input in the following format: R_1 R_2
a, b = map(int, input()) print((a**-1 + b**-1) ** -1)
Statement In an electric circuit, when two resistors R_1 and R_2 are connected in parallel, the equivalent resistance R_3 can be derived from the following formula: * \frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3} Given R_1 and R_2, find R_3.
[{"input": "2 3", "output": "1.2000000000\n \n\n* * *"}, {"input": "100 99", "output": "49.7487437186"}]
Print the value of R_3. The output is considered correct if the absolute or relative error is at most 10^{-6}. * * *
s684233987
Runtime Error
p03888
The input is given from Standard Input in the following format: R_1 R_2
a, b, c = map(int, input().split()) print((a * b / (a + b)))
Statement In an electric circuit, when two resistors R_1 and R_2 are connected in parallel, the equivalent resistance R_3 can be derived from the following formula: * \frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3} Given R_1 and R_2, find R_3.
[{"input": "2 3", "output": "1.2000000000\n \n\n* * *"}, {"input": "100 99", "output": "49.7487437186"}]
Print the value of R_3. The output is considered correct if the absolute or relative error is at most 10^{-6}. * * *
s124648296
Accepted
p03888
The input is given from Standard Input in the following format: R_1 R_2
import math import sys def getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() array_temp = [] if data != "": array_result.append(data.split(" ")) flg = 1 else: flg = 0 finally: return array_result arr_data = getinputdata() r1 = int(arr_data[0][0]) r2 = int(arr_data[0][1]) print(1 / ((r2 + r1) / (r1 * r2)))
Statement In an electric circuit, when two resistors R_1 and R_2 are connected in parallel, the equivalent resistance R_3 can be derived from the following formula: * \frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3} Given R_1 and R_2, find R_3.
[{"input": "2 3", "output": "1.2000000000\n \n\n* * *"}, {"input": "100 99", "output": "49.7487437186"}]
Print the value of R_3. The output is considered correct if the absolute or relative error is at most 10^{-6}. * * *
s829196930
Wrong Answer
p03888
The input is given from Standard Input in the following format: R_1 R_2
s = input() rs = "".join( [ "d" if (c == "b") else "b" if (c == "d") else "q" if (c == "p") else "p" for c in s[::-1] ] ) ans = "Yes" if (s == rs) else "No" print(ans)
Statement In an electric circuit, when two resistors R_1 and R_2 are connected in parallel, the equivalent resistance R_3 can be derived from the following formula: * \frac{1}{R_1} + \frac{1}{R_2} = \frac{1}{R_3} Given R_1 and R_2, find R_3.
[{"input": "2 3", "output": "1.2000000000\n \n\n* * *"}, {"input": "100 99", "output": "49.7487437186"}]
The output consists of 2 lines. In the first line, please print the sorted sequence. Two contiguous elements of the sequence should be separated by a space character. In the second line, please print the number of swap operations.
s929455939
Accepted
p02260
The first line of the input includes an integer _N_ , the number of elements in the sequence. In the second line, _N_ elements of the sequence are given separated by space characters.
count = int(input()) data = [int(n) for n in input().split(" ")] def selection_sort(data): count = len(data) o = 0 for i in range(count): minI = i for j in range(i + 1, count): if data[j] < data[minI]: minI = j if minI != i: temp = data[i] data[i] = data[minI] data[minI] = temp o += 1 show(data) print(o) def show(data): print(" ".join(str(n) for n in data)) selection_sort(data)
Selection Sort Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
[{"input": "6\n 5 6 4 2 1 3", "output": "1 2 3 4 5 6\n 4"}, {"input": "6\n 5 2 4 6 1 3", "output": "1 2 3 4 5 6\n 3"}]
If it is impossible to have all the pieces on the same vertex, print `-1`. If it is possible, print the minimum number of operations required. * * *
s214257045
Wrong Answer
p03021
Input is given from Standard Input in the following format: N S a_1 b_1 a_2 b_2 : a_{N - 1} b_{N - 1}
print("wakaranai")
Statement You are given a tree with N vertices numbered 1, 2, ..., N. The i-th edge connects Vertex a_i and Vertex b_i. You are also given a string S of length N consisting of `0` and `1`. The i-th character of S represents the number of pieces placed on Vertex i. Snuke will perform the following operation some number of times: * Choose two pieces the distance between which is at least 2, and bring these pieces closer to each other by 1. More formally, choose two vertices u and v, each with one or more pieces, and consider the shortest path between them. Here the path must contain at least two edges. Then, move one piece from u to its adjacent vertex on the path, and move one piece from v to its adjacent vertex on the path. By repeating this operation, Snuke wants to have all the pieces on the same vertex. Is this possible? If the answer is yes, also find the minimum number of operations required to achieve it.
[{"input": "7\n 0010101\n 1 2\n 2 3\n 1 4\n 4 5\n 1 6\n 6 7", "output": "3\n \n\nWe can gather all the pieces in three operations as follows:\n\n * Choose the pieces on Vertex 3 and 5.\n * Choose the pieces on Vertex 2 and 7.\n * Choose the pieces on Vertex 4 and 6.\n\n* * *"}, {"input": "7\n 0010110\n 1 2\n 2 3\n 1 4\n 4 5\n 1 6\n 6 7", "output": "-1\n \n\n* * *"}, {"input": "2\n 01\n 1 2", "output": "0"}]
If it is impossible to have all the pieces on the same vertex, print `-1`. If it is possible, print the minimum number of operations required. * * *
s769301504
Wrong Answer
p03021
Input is given from Standard Input in the following format: N S a_1 b_1 a_2 b_2 : a_{N - 1} b_{N - 1}
# n,m=map(int,input().split()) from collections import deque n = int(input()) s = "_" + input() g = [[] for i in range(1 + n)] v = [0] * (1 + n) ans = [] for i in range(n - 1): a, b = map(int, input().split()) g[a].append(b) g[b].append(a) def bfs(x): r = 0 p = deque() p.append((x, 1)) while p: c, depth = p.popleft() if s[c] == "1": r += depth v[c] = 1 for i in g[c]: if v[i] == 0: p.append((i, depth + 1)) return r for x in range(1, n + 1): h = [] for nb in g[x]: v = [0] * (1 + n) v[x] = 1 h.append(bfs(nb)) d = sum(h) if d % 2 == 0 and max(h) <= d // 2: ans.append(d // 2) # print(x,d,h,ans) if ans: ans = min(ans) else: ans = -1 print(ans)
Statement You are given a tree with N vertices numbered 1, 2, ..., N. The i-th edge connects Vertex a_i and Vertex b_i. You are also given a string S of length N consisting of `0` and `1`. The i-th character of S represents the number of pieces placed on Vertex i. Snuke will perform the following operation some number of times: * Choose two pieces the distance between which is at least 2, and bring these pieces closer to each other by 1. More formally, choose two vertices u and v, each with one or more pieces, and consider the shortest path between them. Here the path must contain at least two edges. Then, move one piece from u to its adjacent vertex on the path, and move one piece from v to its adjacent vertex on the path. By repeating this operation, Snuke wants to have all the pieces on the same vertex. Is this possible? If the answer is yes, also find the minimum number of operations required to achieve it.
[{"input": "7\n 0010101\n 1 2\n 2 3\n 1 4\n 4 5\n 1 6\n 6 7", "output": "3\n \n\nWe can gather all the pieces in three operations as follows:\n\n * Choose the pieces on Vertex 3 and 5.\n * Choose the pieces on Vertex 2 and 7.\n * Choose the pieces on Vertex 4 and 6.\n\n* * *"}, {"input": "7\n 0010110\n 1 2\n 2 3\n 1 4\n 4 5\n 1 6\n 6 7", "output": "-1\n \n\n* * *"}, {"input": "2\n 01\n 1 2", "output": "0"}]
If it is impossible to have all the pieces on the same vertex, print `-1`. If it is possible, print the minimum number of operations required. * * *
s488815340
Wrong Answer
p03021
Input is given from Standard Input in the following format: N S a_1 b_1 a_2 b_2 : a_{N - 1} b_{N - 1}
n = int(input()) s = input() d = dict() ans = 10**9 if s.count("1") == 1: print(0) exit() for i in range(n): d[i] = [] for _ in range(n - 1): a, b = map(int, input().split()) d[a - 1].append(b - 1) d[b - 1].append(a - 1) for root in range(n): if len(d[root]) == 1: continue ll = [10**4] * n ll[root] = 0 curl = [] for x in d[root]: ll[x] = 1 q = [x] seen = set([root]) xs = int(s[x]) while q: cur = q.pop() if s[cur] == "1": xs += ll[cur] seen.add(cur) for i in set(d[cur]) - seen: ll[i] = ll[cur] + 1 q.append(i) curl.append(xs) if sum(curl) % 2: continue t = sum(curl) // 2 if all([j <= t for j in curl]): if ans > t: ans = t if ans > 10**8: ans = -1 print(ans)
Statement You are given a tree with N vertices numbered 1, 2, ..., N. The i-th edge connects Vertex a_i and Vertex b_i. You are also given a string S of length N consisting of `0` and `1`. The i-th character of S represents the number of pieces placed on Vertex i. Snuke will perform the following operation some number of times: * Choose two pieces the distance between which is at least 2, and bring these pieces closer to each other by 1. More formally, choose two vertices u and v, each with one or more pieces, and consider the shortest path between them. Here the path must contain at least two edges. Then, move one piece from u to its adjacent vertex on the path, and move one piece from v to its adjacent vertex on the path. By repeating this operation, Snuke wants to have all the pieces on the same vertex. Is this possible? If the answer is yes, also find the minimum number of operations required to achieve it.
[{"input": "7\n 0010101\n 1 2\n 2 3\n 1 4\n 4 5\n 1 6\n 6 7", "output": "3\n \n\nWe can gather all the pieces in three operations as follows:\n\n * Choose the pieces on Vertex 3 and 5.\n * Choose the pieces on Vertex 2 and 7.\n * Choose the pieces on Vertex 4 and 6.\n\n* * *"}, {"input": "7\n 0010110\n 1 2\n 2 3\n 1 4\n 4 5\n 1 6\n 6 7", "output": "-1\n \n\n* * *"}, {"input": "2\n 01\n 1 2", "output": "0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s195526463
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N, Y = map(int, input().split()) for x in range(0,N) for y in range(0,N-x) if N-x<0 break for z in range(0,N-x-y) if N-x-y<0 continue if Y==10000*x+5000*y+1000*z: print(x,y,z) break print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s537140028
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N, Y = map(int, input().split()) for x in range(0,N) for y in range(0,N-x) if N-x<0 break for z in range(0,N-x-y) if N-x-y<0 break if Y==10000*x+5000*y+1000*z: print(x,y,z) break print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s814398009
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n, y = map(int, input().split()) for i in range(n+1): for g in range(n-i): s = n-i-g if 10000*i + 5000*g 1000*s == y: print(i, g, s) exit() print('-1 -1 -1')
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s564715369
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
i = list(map(int, input().split())) a = i[1]%i[0] x = i[1] // 10000 y = i[1]%10000 // 5000 z = ((i[1]%10000)%5000) //1000 if a == 0 and (x+y+z) =< i[0]: print(x,',',y,',',z) elif (x+y+z) > i[0]: print('-1 -1 -1') elif a != 1: print('-1 -1 -1')
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s469919121
Accepted
p03471
Input is given from Standard Input in the following format: N Y
mycode = r""" # distutils: language=c++ # cython: language_level=3 # cython: boundscheck=False # cython: wraparound=False # cython: infer_types=True # cython: cdivision=True # False:Cython はCの型に対する除算・剰余演算子に関する仕様を、(被演算子間の符号が異なる場合の振る舞いが異なる)Pythonのintの仕様に合わせ、除算する数が0の場合にZeroDivisionErrorを送出します。この処理を行わせると、速度に 35% ぐらいのペナルティが生じます。 True:チェックを行いません。 ctypedef long long LL import numpy as np # 読み込みはpython側で行う import sys readline = sys.stdin.buffer.readline read = sys.stdin.readline #文字列読み込む時はこっち def exit(*argv,**kwarg): print(*argv,**kwarg) sys.exit() def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64) cdef LL i,j,k,_ cdef LL N,Y N,Y=ints() Y//=1000 cdef LL a,b,c #a+b+c=Nかつ10a+5b+c=Yを満たすa,b,cを見つけたい for a in range(N+1): for b in range(N+1): c = N-a-b if c<0 : break if 10*a+5*b+c==Y: exit(a,b,c) print(-1,-1,-1) """ import sys if sys.argv[-1] == "ONLINE_JUDGE": # コンパイル時 import os with open("mycode.pyx", "w") as f: f.write(mycode) os.system("cythonize -i -3 -b mycode.pyx") import mycode
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s180057713
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N,Y=map(int,input().split()) res=(-1,-1,-1) for x in range(N+1): for y in range(N+1-x); if N-x-y>=0 and 10000*x+5000*y+1000*(N-x-y)==Y: res=(x,y,N-x-y) print(res[0],res[1],res[2])
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s487589122
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n, y = (int(i) for i in input().split()) a=-1 b=-1 c=-1 for i in range(n+1): for j in range(n-i+1): if 10000*i+5000*j+1000*(n-i-j+1)==y: a=i b=j c=n-i+j+1 break print(a b c)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s828507266
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n,y=map(int,input().split()) for i in range(n+1): for j in range(n+1-i): z_m=y-(10000*i+5000*j) z_n=n-(i+j) if z_m>=0 and z_m//1000==z_n: print(i,j,z_n) exit() print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s002493854
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
import sys n,y = map(int, input().split()) for a in range(n+1): for b in range(n+1-a): # if (a * 10000 + b * 5000 + (n-a-b) * 1000 == y): # print(str(a) + ' ' + str(b) + ' ' + str(c)) # sys.exit() print('-1 -1 -1') sys.exit()
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s808942162
Wrong Answer
p03471
Input is given from Standard Input in the following format: N Y
print("-1 -1 -1")
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s755152314
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n, y = map(int, input().split()) ans = '-1 -1 -1' for i in range(n+1): for j in range(n-i+1): k = n - i + j: if i*10000 + j*5000 + k*1000 == y: ans = str(i) + ' ' + str(j) + ' ' + str(k) print(ans)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s190522788
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
import sys n,y = map(int, input().split()) for a in range(n+1): for b in range(n+1-a): if (a * 10000 + b * 5000 + (n-a-b) * 1000 == y): print(a) sys.exit() print('-1 -1 -1') sys.exit()
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s085318735
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
a,b =map(int,input().split()) for i in range(b//(10000*a))[::-1]: for j in range((b-10000*i)//(5000*(a-i))[::-1]: for k in range((b-10000*i-5000*j)//(1000*(a-i-j)))[::-1]: if b == i*10000+j*5000+k*1000: break if i==j==k==0: print(-1,-1,-1) else: print(i,j,k)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s236697906
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N, Y = map(int, input().split()) # x:10000円, y;5000円, z:1000円 for x in range(N+1): for y in range(N+1): z = N - (x + y) if (z >= 0) & (10000x + 5000y + 1000*z == Y): print(x, y, z) exit(0) print(-1, -1, -1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s238254092
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N,Y = map(int,input().split(" ")) K = Y//1000 -N l = int(-K/4) if l <= -2*K/9: a = K+4*l b = -2*K-9*l c = N-a-b if c >=0: print(a," ",b," ",c) else: print(-1," ",-1," ",-1) else: print(-1," ",-1," ",-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s483985298
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N,Y = map(int, input().split()) a = Y//10000 b = Y//5000 flag = False for i in range(a+1): if flag == True: break for j in range(b+1): if N-i-j<0: break: if i*10000+j*5000+(N-i-j)*1000 == Y: flag = True s = i t = j u = N-i-j break if flag == True: print(s,t,u) else: print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s057883159
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
import sys N,Y = map(int,input().split()) for i in range(N+1): if Y < i * 10000: continue for j in range(N+1): if N < i + j or Y < i * 10000 + 5000 * j: break for k in range(N+1): if N < i + j + k or Y < i * 10000 + j * 5000 + k * 1000: if N == i + j + k and Y == i * 10000 + j * 5000 + k * 1000: print(i,j,k) sys.exit() print("-1 -1 -1")
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s893899769
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
count,total = list(map(int,input().split())) ret1 = -1 ret2 = -1 ret3 = -1 NF = True if total <= count * 10000: for i in range(count + 1): rCount = count - i if total-10000*i <= rCount * 5000: for j in range(rCount + 1): if (i*10000 + j*5000 + (count-i-j)*1000) == total: ret1 = i ret2 = j ret3 = count-i-j NF = False break if NF: ret1 = -1 ret2 = -1 ret3 = -1 print(str(ret1) + " " + str(ret2) + " " + str(ret3))
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s891261343
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n, total = map(int, input().split()) x=0 y=0 z=0 while True: found = False while True: z = n - x - y sum = 10000 * x + 5000 * y + 1000 * z if sum == total found = True break elif sum > total break y =+ 1 if found == True break if 10000 * x > total x = -1 y = -1 z = -1 break x += 1 print("{} {} {}".format(x, y, z))
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s963130606
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
def main(): N,Y = map(int, input.split()) Y /= 1000 candidates = [] sen = 0; gosen = 0; itiman = 0 sen += amari_sen(Y); Y_amari = Y - amari if (Y_amari % 10 == 5): first_sen = sen; first_gosen = gosen+1; first_itiman = itiman second_sen = sen+5; second_gosen = gosen; second_itiman = itiman Y_amari -= 5 man = Y_amari / 10 for i in range(man): # i=itimanの数 sentogosen = man - i for j in range(sentogosen): # j=gosenの数 k = sentogosen - 5 * j # k=senの数 candidate.append([first_sen+k,first_gosen+j,first_itiman+i]) candidate.append([second_sen+k,second_gosen+j,second_itiman+i]) flag = 0 for i in range(len(candidate)): N_cand = candidate[i][0] + candidate[i][1] + candidate[i][2] if(N_cand == N): print(str(candidate[i][2]) + " " + str(candidate[i][1]) + " " + str(candidate[i][0])) flag = 1 break if(flag == 0): print("-1 -1 -1") def amari_sen(Y): amari = Y % 5 return amari if __name__ == "__main__": main()
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s276382305
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n, total = map(int, input().split()) x=0 y=0 z=0 found = False for i in range(int(total / 10000)): x = i for j in range(int((total - 10000 * i) / 5000)): y = j z = n - x - y sum = 10000 * x + 5000 * y + 1000 * z if sum == total found = True break if found == True break if found == False: x = -1 y = -1 z = -1 print("{} {} {}".format(x, y, z))
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s927755061
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n,m=list(map(int,input().split(" "))) j=0 if n*10000<m or n*1000>m: j=2 for z in range(n+1): for y in range(n+1): for x in range(n+1): ifx*1000+y*5000+z*10000>m: j=2 if x+y+z>n or j==2: break if x+y+z==n: if x*1000+y*5000+z*10000==m: print(z,y,x) j=1 break if x*1000+y*5000+z*10000==m or z+y>n or j==2: break if x*1000+y*5000+z*10000==m or z>n or j==2: break if j!=1: print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s387294838
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
,y = map(int,input().split()) ans = 0 for i in range(1000): if ans != 0: break else: for j in range(1000): for k in range(1000): if (i + k + j)== n and (10000*i + 5000*j + 1000*k) == y: print(i,j,k) ans +=1 else: continue if ans == 0: print('-1','-1','-1')
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s663350072
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
,y = map(int,input().split()) okane10000 = [i for i in range(n+1)] okane5000 = [i for i in range(n+1)] okane1000 = [i for i in range(n+1)] for a in okane10000: for b in okane5000: for c in okane1000: if a+b+c==n: if a*10000+b*5000+c*1000 == y: print(a,b,c) else: print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s644314215
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n, y = map(int, input().split(" ")) found = False for i in range(0, n + 1): for j in range(0, n + 1 - i): sum = 10000 * i + 5000 * j + 1000 * (n - i - j) if sum == y: found = True print(str(i) + " " + str(j) + " " + str(n - i - j)) if !found: print("-1 -1 -1")
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s180053263
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N, Y = map(int, input().split()) x = y = z = 0 for i in range(N, -1, -1): if i * 10000 <= Y: charge = Y - i * 10000 rest = N - i for j in range(rest, -1, -1): if j * 5000 <= charge: if charge - j * 50000 - (rest - j) * 1000 == 0: print(f"{i} {j} {rest-j}") exit(0) print("-1 -1 -1 ")
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s438069115
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
a,b = map(int,input().split()) t = b f = False for i in range(t//10+1): for j in range((t-i*10)//5+1): if a == t - i*9 - j*4 and b == i*10+j*5+(a-i-j) and a-i-j>=0: f = True break if f: break if f: print(i,j,a-i-j) else: print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s327466363
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n=int(input()) y=int(input()) a=-1 b=-1 c=-1 for i in range(n+1): for j in range(n+1): for k in range(n+1): if n==i+j+k and 10000*i+5000*j+1000*k==y: a=i b=j c=k break print(a b c)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s030031490
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
n. y = map(int, input().split()) ans = 0 for i in range(n+1): for j in range(n+1-i): for k in range(n+1-i-j): if y == 10000*i + 5000*j + 1000*k: print(i j k) ans += 1 if ans == 0: print("-1 -1 -1")
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s197029313
Accepted
p03471
Input is given from Standard Input in the following format: N Y
[N, Y] = list(map(int, input().split())) x = [0, 0, 0] x[0] = Y // 10000 x[1] = (Y - (10000 * x[0])) // 5000 x[2] = (Y - (10000 * x[0]) - (5000 * x[1])) // 1000 ans = [-1, -1, -1] for i in range(x[0] + 1): for j in range(x[1] + (2 * i) + 1): N_temp = (x[0] - i) + (x[1] + 2 * i - j) + (x[2] + 5 * j) if N_temp == N: ans = [(x[0] - i), ((x[1] + 2 * i - j)), (x[2] + 5 * j)] print("{0[0]} {0[1]} {0[2]}".format(ans)) exit() elif N_temp > N: break print("{0[0]} {0[1]} {0[2]}".format(ans))
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s580693653
Wrong Answer
p03471
Input is given from Standard Input in the following format: N Y
N, Y = map(int, input().split()) ichiman = 0 gosen = 0 sen = -1 se_ichi = -1 go_ichi = -1 sen_go_ichi = -1 mismatch = 0 max_ichiman = int(2 * (10**7) / (10**4)) for i in range(max_ichiman): if i * 10**4 > Y: ichiman = i - 1 break Y = Y - ichiman * 10**4 for j in range(2): if j * 5 * 10**3 >= Y: gosen = j break Y = Y - gosen * 5 * 10**3 for k in range(5): if k * 10**3 == Y: sen = k min_N = ichiman + gosen + sen for i2 in range(N - min_N + 1): if i2 * 9 > N - min_N: se_ichi = i2 - 1 break N = N - se_ichi * 9 for j2 in range(N - min_N + 1): if j2 * 5 > N - min_N: sen_go_ichi = j2 - 1 break N = N - sen_go_ichi * 5 for k2 in range(N - min_N + 1): if N - min_N < 0: mismatch = 1 if k2 == N - min_N: go_ichi = k2 break ichiman = ichiman - se_ichi - sen_go_ichi - go_ichi gosen = gosen + 2 * go_ichi + sen_go_ichi sen = sen + 5 * sen_go_ichi + 10 * se_ichi if mismatch == 1: sen = -1 ichiman = -1 gosen = -1 print(ichiman, gosen, sen)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s143171423
Wrong Answer
p03471
Input is given from Standard Input in the following format: N Y
def gen_range(N, Y, reverse=False): for i in range(N, 0 - 1, -1): for j in range(N - i + 1): if reverse and i * 10000 + j * 1000 < Y: break elif reverse is False and i * 1000 + j * 10000 > Y: break for k in range(N - i - j + 1): if reverse: yield (j, i, k) else: yield (i, j, k) def calc(N, Y): if 10000 * N < Y or Y < 1000 * N: return [-1, -1, -1] if Y % 10000 == 0 and Y // 10000 == N: return (Y // 10000, 0, 0) if Y % 5000 == 0 and Y // 5000 == N: return (0, Y // 5000, 0) if Y % 1000 == 0 and Y // 1000 == N: return (0, 0, Y // 1000) if (Y - 1000 * N) % 4000 == 0: k5 = (Y - 1000 * N) // 4000 if k5 >= 0 and N - k5 >= 0: return [0, k5, N - k5] elif (Y - 1000 * N) % 9000 == 0: k10 = (Y - 1000 * N) // 9000 if k10 >= 0 and N - k10 >= 0: return [k10, 0, N - k10] if 5000 * N < Y: for k10, k1, k5 in gen_range(N, Y, reverse=True): if k10 * 10000 + k1 * 1000 + k5 * 5000 == Y: return (k10, k5, k1) # # for k1 in range(N, 0 - 1, -1): # for k10 in range(N - k1 + 1): # if k1 * 1000 + k10 * 10000 > Y: # break # for k5 in range(N - k1 - k10 + 1): # print(k10, k5, k1) # if k1 * 1000 + k5 * 5000 + k10 * 10000 == Y: # return [k10, k5, k1] return (-1, -1, -1) def main(): N, Y = list(map(int, input().split())) print(*calc(N, Y)) if __name__ == "__main__": main()
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s161543979
Accepted
p03471
Input is given from Standard Input in the following format: N Y
N, Y = list(map(int, input().split())) Y = Y / 1000 Z = Y - N A = 9 * N - Z if Z < 0 or Z > 9 * N: X = [-1, -1, -1] elif 24 <= Z <= 9 * N - 32: X = [ (Z - 27) // 9 + ((Z % 9) % 4 - 1) % 4, (9 - 2 * (Z % 9)) % 9, N - ((Z - 27) // 9 + ((Z % 9) % 4 - 1) % 4 + (9 - 2 * (Z % 9)) % 9), ] X = list(map(int, X)) elif 0 <= Z <= 23: if Z % 4 == 0: X = [0, Z / 4, N - (Z / 4)] elif Z % 9 == 0: X = [Z / 9, 0, N - (Z / 9)] elif Z == 13 or Z == 17 or Z == 21: X = [1, (Z - 9) / 4, N - ((Z - 5) / 4)] elif Z == 22: X = [2, 1, N - 3] else: X = [-1, -1, -1] X = list(map(int, X)) else: if A % 5 == 0: X = [N - (A / 5), A / 5, 0] elif A % 9 == 0: X = [N - (A / 9), 0, A / 9] elif A == 14 or A == 19 or A == 24 or A == 29: X = [N - ((A - 4) / 5), (A - 9) / 5, 1] elif A == 23 or A == 28: X = [N - ((A - 8) / 5), (A - 18) / 5, 2] else: X = [-1, -1, -1] X = list(map(int, X)) print(X[0], X[1], X[2])
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s723893325
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
l = list(map(int, input().split())) N = l[0] Y = l[1] ans = [-1,-1,-1] if Y/10000 < N: for i in range(int(Y/10000)+1): a = i n = N - a Y1 = Y - (a * 10000) if Y1/5000 < n: for j in range(int(Y1/5000)+1): b = j c = n - j if 10000 * a + 5000 * b + 1000 * c == Y: ans = [a,b,c] print(ans)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s753584522
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
N,Y = map(int,input().split(" ")) t = int(Y/10000) end=False for x in range(1,t+1): for y in range(1,20001): for z in range(1,20001): ans = x*10000+y*5000+z*1000 if ans==Y and x+y+z==N: print(str(x)+" "+str(y)+" "+str(z)) end=True break if end: break if end: break if end==False: print("-1 -1 -1")
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s771750387
Wrong Answer
p03471
Input is given from Standard Input in the following format: N Y
# -*- coding: utf-8 -*- # 整数値入力 1文字の入力 def input_one_number(): return int(input()) # 整数値龍力 複数の入力 def input_multiple_number(): return map(int, input().split()) # 整数値龍力 複数の入力(配列) def input_multiple_number_as_list(): return list(map(int, input().split())) # 整数値龍力 複数の入力(配列で1つずつ渡される) def input_multiple_number_as_list_sep(N): ins = [] for i in range(N): ins.append(input()) return ins # 2次元配列入力 def input_map(): return [list(map(int, list(input()))) for i in range(h)] # リスト出力 def print_list(list): print(*list) return # 2次元配列出力 def print_map(maplist): for i in maplist: print(*i, sep="") return # 素数生成 def generate_primenums(): n = 100 primes = set(range(2, n + 1)) for i in range(2, int(n**0.5 + 1)): primes.difference_update(range(i * 2, n + 1, i)) primes = list(primes) return primes def memo(): a = [0] * 5 b = a # 良くない配列のコピー b2 = a[:] # 1次元のときはコピーはこれで良い a[1] = 3 print("b:{}, b2:{}".format(b, b2)) # b:[0, 3, 0, 0, 0], b2:[0, 0, 0, 0, 0] import copy a = [[0] * 3 for i in range(5)] # 2次元配列はこう準備、[[0]*3]*5だとだめ b = copy.deepcopy(a) # 2次元配列はこうコピーする # 内包表記奇数のみ odd = [i for i in range(100) if i % 2 == 1] # [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] # 二部探索 import bisect a = [1, 2, 3, 5, 6, 7, 8, 9] b = bisect.bisect_left(a, 8) # combinations、組み合わせ、順列 from itertools import ( permutations, combinations, combinations_with_replacement, product, ) a = ["a", "b", "C"] print(list(permutations(a))) print(list(combinations(a, 2))) print(list(combinations_with_replacement(a, 3))) # 階乗 def kaijo(n): import math return math.factorial(n) # 選び方(コンビネーション nCr) def num_combination(n, r): import math return math.factorial(n) // math.factorial(n - r) # 最大公約数、最小公倍数 def calc_gcd(a, b): import fractions GCD = fractions.gcd(a, b) lcm = a * b // gcd return gcd, lcm # 複数の最大公約数 def calc_gcd_list(l): gcd = l[0] for i in range(1, N): gcd = fractions.gcd(gcd, l[i]) return gcd # 各桁の和 def sum_digit(n): sum = 0 while n > 0: sum += n % 10 n //= 10 return sum N, Y = input_multiple_number() p = Y - 1000 * N x, y, z = 0, 0, 0 for i in range(2001): if ( (p - i * 4000) % 9000 == 0 and (p - i * 4000) >= 0 and (p - i * 4000) / 9000 <= 2000 ): y = i x = (p - i * 4000) // 9000 z = N - x - y if 0 <= z and z <= 2000: break if z < 0 or 2000 < z: print("-1 -1 -1") print(x, y, z) else: print(x, y, z)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s938413879
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
from typing import * def main(N, Y): # type: (int, int) -> None """ 次の方程式 x + y + z = N 10x + 5y + z = Y の解を探索する.zを消去すると 9x + 4y = Y - N where x >= 0 y >= 0 x + y <= N w = 2x+y と置くと x + 4w = Y - N where x >= 0 w >= 0 w - x <= Y xを消去すると条件は w >= 0 4w <= Y - N 9w >= 2(Y - N) であり x = Y - N - 4w y = w - 2x z = N - x - y """ Y = Y // 1000 lb = (2 * (Y - N) - 1) // 9 + 1 ub = (Y - N) // 4 ans = None for w in range(lb, ub + 1): x = Y - N - 4 * w y = w - 2 * x z = N - x - y assert x >= 0 and y >= 0 and z >= 0 ans = (x, y, z) break if ans is not None: print("{0} {1} {2}".format(x, y, z)) else: print("{0} {1} {2}".format(-1, -1, -1)) return if __name__ == "__main__": N, Y, *_ = map(int, input().split()) main(N, Y)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s800347395
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
a,b = map(int,input().split()) b1 = 0 b2 = 0 b3 = 0 s = 0 s1 = 0 s2 = 0 t = 0 t1 = 0 u = 0 if b>=10000: s = b // 10000 b1 = b - s*10000 if 5000<=b1<10000: b2 = b1 - 5000 s1 = b2 // 1000 if (s + 1 + s1) <= a: print(s,1,s1) else: print(-1,-1,-1) elif 5000<=b<10000: t = b // 5000 b3 = b - t*5000 t1 = b3 // 1000 if (t + t1) <= a: print(0,t,t1) else: print(-1,-1,-1) elif b<5000: u = b // 1000 if u <= a: print(0,0,u) else: print(-1,-1,-1)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s983411391
Wrong Answer
p03471
Input is given from Standard Input in the following format: N Y
def a(): return input() # s def ai(): return int(input()) # a,n or k def ma(): return map(int, input().split()) # a,b,c,d or n,k def ms(): return map(str, input().split()) # ,a,b,c,d def lma(): return list(map(int, input().split())) # x or y def lms(): return list(map(str, input().split())) # x or y a, b = ma() c = d = e = -1 b = b // 1000 for i in range(a): for j in range(a - i): if b == i * 10 + j * 5 + (a - i - j): c, d, e = i, j, a - i - j break print(c, d, e)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s956543605
Accepted
p03471
Input is given from Standard Input in the following format: N Y
# _*_ coding:utf-8 _*_ # Atcoder_Beginners_Contest085-C # TODO https://atcoder.jp/contests/abc085/tasks/abc085_c def solveProblem(AllSheet, GivenMoney): cash1000 = 0 cash5000 = 0 cash10000 = 0 searchFlag = False for cash1000 in range(0, AllSheet + 1, +1): for cash5000 in range(0, AllSheet + 1 - cash1000): cash10000 = AllSheet - cash1000 - cash5000 nowTotal = cash10000 * 10000 + cash5000 * 5000 + cash1000 * 1000 if nowTotal == GivenMoney: answer = [cash10000, cash5000, cash1000] searchFlag = True break if searchFlag != True: answer = [-1, -1, -1] return answer if __name__ == "__main__": N, Y = map(int, input().strip().split(" ")) solution = solveProblem(N, Y) print("{} {} {}".format(solution[0], solution[1], solution[2]))
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s673717232
Runtime Error
p03471
Input is given from Standard Input in the following format: N Y
x = input() otoshi = x.split(" ") N = int(otoshi[0]) Y = int(otoshi[1]) ten_t = Y // 10000 if ten_t > N: ansa = -1 ansb = -1 ansc = -1 elif ten_t == N: if Y == 100000 * N: ansa = N ansb = 0 ansc = 0 else: ansa = -1 ansb = -1 ansc = -1 elif 0 <= ten_t < N: for i in range(0, ten_t + 1): ra = Y - 10000 * (ten_t - i) fiv_t = ra // 5000 if fiv_t + ten_t - i > N: ansa = -1 ansb = -1 ansc = -1 break elif 0 <= fiv_t + ten_t - i <= N: if ra == 5000 * (N - ten_t + i): ansa = ten_t - i ansb = N - ten_t + i ansc = 0 break else: for j in range(0, fiv_t + 1): rb = ra - 5000 * (fiv_t - j) if rb == 1000 * (N - ten_t + i - fiv_t + j): ansa = ten_t - i ansb = fiv_t - j ansc = N - ten_t + i - fiv_t + j break else: ansa = -1 ansb = -1 ansc = -1 print(ansa, ansb, ansc)
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s574421666
Accepted
p03471
Input is given from Standard Input in the following format: N Y
def isValidNumOfBill(x, y, z, N): return x + y + z == N def isValidSumOfMoney(x, y, z, Y): return 10000 * x + 5000 * y + 1000 * z == Y def outputResult(x, y, z): print("{x:d} {y:d} {z:d}".format(x=x, y=y, z=z)) def outputFailure(): print("-1 -1 -1") def searchA(N, Y): # define range xlim = range(0, Y // 10000 + 1) ylim = range(0, Y // 5000 + 1) zlim = range(0, Y // 1000 + 1) for x in xlim: for y in ylim: for z in zlim: # print(x, y, z) if not isValidNumOfBill(x, y, z, N): continue if isValidSumOfMoney(x, y, z, Y): return (x, y, z) def searchB(N, Y): # 最初に金額を合わせる calcX = lambda Y: Y // 10000 calcY = lambda x, Y: (Y - 10000 * x) // 5000 calcZ = lambda x, y, Y: (Y - 10000 * x - 5000 * y) // 1000 x = calcX(Y) y = calcY(x, Y) z = calcZ(x, y, Y) while x >= 0: while y >= 0: # print(x, y, z) if sum((x, y, z)) == N: return (x, y, z) y -= 1 z = calcZ(x, y, Y) x -= 1 y = calcY(x, Y) z = calcZ(x, y, Y) def main(): # read 'N Y' args = input().split(" ") N = int(args[0]) Y = int(args[1]) # search for 10000x + 5000y + 1000z = Y # result = searchA(N, Y) result = searchB(N, Y) if result is not None: x, y, z = result outputResult(x, y, z) else: outputFailure() if __name__ == "__main__": main()
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
If the total value of N bills cannot be Y yen, print `-1 -1 -1`. If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed. * * *
s545465215
Wrong Answer
p03471
Input is given from Standard Input in the following format: N Y
maisu, goukei = map(int, input().split()) cou = 0 for i in range(maisu + 1): for r in range(maisu + 1): if i + r > maisu: break if i * 10000 + r * 5000 + (maisu - i - r) * 1000 == goukei: cou = 1 print(i, r, maisu - i - r) break if cou == 1: break
Statement The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
[{"input": "9 45000", "output": "4 0 5\n \n\nIf the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9\nbills and 45000 yen in total. It is also possible that the envelope contained\n9 5000-yen bills, so the output `0 9 0` is also correct.\n\n* * *"}, {"input": "20 196000", "output": "-1 -1 -1\n \n\nWhen the envelope contained 20 bills in total, the total value would be 200000\nyen if all the bills were 10000-yen bills, and would be at most 195000 yen\notherwise, so it would never be 196000 yen.\n\n* * *"}, {"input": "1000 1234000", "output": "14 27 959\n \n\nThere are also many other possibilities.\n\n* * *"}, {"input": "2000 20000000", "output": "2000 0 0"}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s636899511
Runtime Error
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
INF = 10**9 + 7 def main(): N, W = (int(i) for i in input().split()) A = [[int(i) for i in input().split()] for j in range(N)] dp = [[INF]*(10**4+1) for _ in range(N+1)] dp[0][0] = 0 for i in range(N): for j in range(10**4 + 1): dp[i+1][j] = min(dp[i+1][j], dp[i][j]) if 0 <= j - A[i][1] and dp[i][j - A[i][1]] + A[i][0] <= W: dp[i+1][j] = min(dp[i+1][j], dp[i][j - A[i][1]] + A[i][0]) ans = 0 for j in range(10**4+1)[::-1]: if dp[N][j] <= W: ans = break print(ans) if __name__ == '__main__': main()
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s837118348
Accepted
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
def knapsack_price(single=True): """ 重さが小さい時のナップサックDP :param single: True = 重複なし """ """ dp[price <= V] = 価値を固定した時の最小重量 """ V = sum(price_list) dp_max = W + 1 dp = [dp_max] * (V + 1) dp[0] = 0 # 境界条件: 価値0 の時は重さは0 for item in range(N): if single: S = reversed(range(price_list[item], V + 1)) else: S = range(price_list[item], V + 1) for price in S: dp[price] = min2( dp[price], dp[price - price_list[item]] + weight_list[item] ) return max(price for price in range(V + 1) if dp[price] <= W) ####################################################################################################### import sys input = sys.stdin.readline def max2(x, y): """pythonの組み込み関数 max は2変数に対しては遅い!!""" if x > y: return x else: return y def min2(x, y): """pythonの組み込み関数 min は2変数に対しては遅い!!""" if x < y: return x else: return y N, W = map(int, input().split()) # N: 品物の種類 W: 重量制限 price_list = [] weight_list = [] for _ in range(N): """price と weight が逆転して入力されている場合有り""" weight, price = map(int, input().split()) price_list.append(price) weight_list.append(weight) print(knapsack_price(single=True))
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s554320055
Runtime Error
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
N, W = [int(x) for x in input().split()] w, v = [], [] MAX_V = 10100 INF = 100000000001 for i in range(N): wi, vi = [int(x) for x in input().split()] w.append(wi) v.append(vi) dp = [] for i in range(N+1): dp.append([INF] * MAX_V) dp[0][0] = 0 for i in range(N): for sum_v in range(MAX_V): if sum_v - v[i] >= 0: dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]) dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]) res = 0 for sum_v in range(MAX_V): if dp[N][sum_v] <= W: res = sum_v print(res
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s775068516
Runtime Error
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
#!/usr/bin/env python3 import sys def solve(N: int, W: int, w: "List[int]", v: "List[int]"): maxv=sum(v)+1 dp=[[2**60]*maxv for _ in range(N+1)] dp[0][0]=0 for i in range(N): for j in range(maxv): if j>=v[i]: dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]) else: empla dp[i+1][j]=dp[i][j] te) ans=0 for j in range(maxv): if W >= dp[N][j]: ans=j empla print(ans) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int W = int(next(tokens)) # type: int empla w = [int()] * (N) # type: "List[int]" v = [int()] * (N) # type: "List[int]" 15292 for i in range(N): 46976 w[i] = int(next(tokens)) 04606 v[i] = int(next(tokens)) 52921 solve(N, W, w, v) 76, 1 46068 if __name__ == '__main__': 29215 main()
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s908307164
Runtime Error
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() #define TM_T template <class T> using namespace std; typedef long long ll; TM_T T inp(){T it;cin >> it;return it;} int N, W; vector<ll> w; vector<ll> v; vector<ll> dp; int input(){ cin >> N >> W; REP(i,N) { w.push_back( inp<ll>() ); v.push_back( inp<ll>() ); } } int main() { input(); REP(i,202000+2) dp.push_back( INF ); //v dp[0] = 0; REP(i,N){ ll iw = w[i]; ll iv = v[i]; REPR(j,200000+2){ dp[j+iv] = min( dp[j+iv], dp[j] + iw ); } } ll maxv = 0; REP(i,202000){ if (dp[i]<=W){ maxv = i; } } cout << maxv << endl; }
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]
Print the maximum possible sum of the values of items that Taro takes home. * * *
s492599499
Runtime Error
p03164
Input is given from Standard Input in the following format: N W w_1 v_1 w_2 v_2 : w_N v_N
# coding: utf-8 import numpy as np """ 20191120 test: 6 8 2 3 1 2 3 6 2 1 1 3 5 85 """ def main(): N, W = map(int, input().split()) ws = [None for _ in range(N)] vs = [None for _ in range(N)] for i in range(N): ws[i], vs[i] = map(int, input().split()) V = sum(vs) # initialize dp = [[None for _ in range(V + 1)] for _ in range(N)] dp[0][0] = 0 existance = [set([]) for _ in range(N)] existance[0].add(0) dp[0][vs[0]] = ws[0] existance[0].add(vs[0]) for n in range(N - 1): for v in existance[n]: # not-use-update # if dp[n+1][v] is None: # dp[n+1][v] = dp[n][v] # else: # dp[n+1][v] = min(dp[n][v], dp[n+1][v]) dp[n + 1][v] = dp[n][v] existance[n + 1].add(v) # use-update if dp[n + 1][v + vs[n + 1]] is None: if dp[n][v] + ws[n + 1] <= W: dp[n + 1][v + vs[n + 1]] = dp[n][v] + ws[n + 1] existance[n + 1].add(v + vs[n + 1]) else: dp[n + 1][v + vs[n + 1]] = min( dp[n][v] + vs[n + 1], dp[n + 1][v + vs[n + 1]] ) existance[n + 1].add(v + vs[n + 1]) ans = 0 for v in range(V, 0, -1): if dp[-1][v] is not None: ans = v break return ans def miss_main(): N, W = map(int, input().split()) ws = [None for _ in range(N)] vs = [None for _ in range(N)] for i in range(N): ws[i], vs[i] = map(int, input().split()) # initialize dp = [[None for _ in range(W + 1)] for _ in range(N)] dp[0][0] = 0 existance = [set([]) for _ in range(N)] existance[0].add(0) if W >= ws[0]: dp[0][ws[0]] = vs[0] existance[0].add(ws[0]) for n in range(N - 1): for w in existance[n]: # not-use-update if dp[n + 1][w] is None: dp[n + 1][w] = dp[n][w] else: dp[n + 1][w] = max(dp[n][w], dp[n + 1][w]) existance[n + 1].add(w) # use-update if w + ws[n + 1] <= W: if dp[n + 1][w + ws[n + 1]] is None: dp[n + 1][w + ws[n + 1]] = dp[n][w] + vs[n + 1] else: dp[n + 1][w + ws[n + 1]] = max( dp[n][w] + vs[n + 1], dp[n + 1][w + ws[n + 1]] ) existance[n + 1].add(w + ws[n + 1]) # print(np.array(dp)) ans = 0 for w in range(1, W + 1): if dp[-1][w] is not None and dp[-1][w] > ans: ans = dp[-1][w] return ans if __name__ == "__main__": print(main())
Statement There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
[{"input": "3 8\n 3 30\n 4 50\n 5 60", "output": "90\n \n\nItems 1 and 3 should be taken. Then, the sum of the weights is 3 + 5 = 8, and\nthe sum of the values is 30 + 60 = 90.\n\n* * *"}, {"input": "1 1000000000\n 1000000000 10", "output": "10\n \n\n* * *"}, {"input": "6 15\n 6 5\n 5 6\n 6 4\n 6 6\n 3 5\n 7 2", "output": "17\n \n\nItems 2, 4 and 5 should be taken. Then, the sum of the weights is 5 + 6 + 3 =\n14, and the sum of the values is 6 + 6 + 5 = 17."}]