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 number of days for which the forecast was correct.
* * *
|
s497570317
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
print(sum(s == t for s, t in zip(input(), input())))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s153254633
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
ST = [input(), input()]
ST = [int(i) for i in range(3) if ST[0][i] == ST[1][i]]
print(len(ST))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s729927816
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
print(sum([1 for s, t in zip(input(), input()) if s == t]))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s906855645
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
print(sum(x == y for x, y in zip(input(), input())))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s656249888
|
Wrong Answer
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
0
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s592667997
|
Runtime Error
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
a = [deque([x for x in list(map(int, input().split()))]) for _ in range(n)]
f = True
day = 1
while f:
if day > 2500:
print(-1)
sys.exit()
done = set()
nokori_games = 0
for m in range(n):
la = len(a[m])
nokori_games += la
if m in done:
pass
elif la:
teki = a[m][0]
jibun = m + 1
if a[teki - 1][0] == jibun and teki - 1 not in done:
a[m].popleft()
a[teki - 1].popleft()
done.add(m)
done.add(teki - 1)
nokori_games -= 1
elif not len(a[teki - 1]):
print(-1)
sys.exit()
if nokori_games:
if not len(done):
print(-1)
sys.exit()
else:
print(day)
sys.exit()
day += 1
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s980270918
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
S, T = input(), input()
print(sum(1 if s == t else 0 for s, t in zip(S, T)))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s169783596
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
print(sum(a == b for a, b in zip(list(input()), list(input()))))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s045971681
|
Runtime Error
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
a, b = [int(c) for c in input().split(" ")]
num = 0
bdash = b
if b == 1:
num = 0
bdash = -1
while bdash > 0:
if bdash == a:
num = num + 1
break
elif bdash > a:
num = num + 1
bdash = bdash - (a - 1)
elif bdash < a:
num = num + 1
break
print(num)
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s978288657
|
Wrong Answer
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
s, t = open(0)
a = [i == j for i, j in zip(s, t)]
print(sum(a))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s242824977
|
Wrong Answer
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
l1 = list(map(str, input().split()))
l2 = list(map(str, input().split()))
w = len(l1)
all = 0
for i in range(0, w):
if l1[i] == l2[i]:
all = all + 1
print(all)
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s128079522
|
Runtime Error
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
a, b = list(map(int, input().split()))
number = 1
outlet_number = a
while outlet_number <= b:
outlet_number += a - 1
number += 1
print(number)
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s289459968
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
s, t = input(), input()
print(sum([s[i] == t[i] for i in range(3)]))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s364183230
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
print(sum([1 for x, y in zip(input(), input()) if x == y]))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s967742733
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
print(sum([a == b for a, b in zip(input(), input())]))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s898354664
|
Accepted
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
print(sum(i == j for i, j in zip(input(), input())))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s619292962
|
Wrong Answer
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
# 139 Tenki
print(len(list(set(input()) & set(input()))))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s297735146
|
Runtime Error
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
s = [input() for i in range(3)]
print(s)
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s655552053
|
Runtime Error
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
s, t = map(int, open(0).read().split())
print(sum([j == i for i in s for j in t]))
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the number of days for which the forecast was correct.
* * *
|
s183491017
|
Runtime Error
|
p02921
|
Input is given from Standard Input in the following format:
S
T
|
N = int(input())
A = []
c = 0
f = True
for i in range(N):
A.append(list(map(int, input().split())))
idx = [0 for i in range(N)]
a = 0
cc = 0
ccc = 0
btlf = [False for i in range(N)] # その周回ですでにバトルしたかどうかのフラグです
m = (N * (N - 1)) // 2
n = 100000
for i in range(min(m, n)): # 周回
btlf = [False for i in range(N)] # リセット
ccc = 0
for j in range(N):
# print(idx)
if idx[j] != N - 1:
a = A[j][idx[j]]
if a > j:
if (
A[a - 1][idx[a - 1]] - 1 == j
and btlf[a - 1] == False
and btlf[j] == False
):
idx[a - 1] += 1
btlf[a - 1] = True
idx[j] += 1
btlf[j] = True
cc += 1
ccc += 1
if cc == m: # idx == [N-1 for i in range(N)]:
print(i + 1)
f = False
break
if ccc == 0: # 対戦が一度もなければ打ち切ります
break
if f:
print(-1)
|
Statement
You will be given a string S of length 3 representing the weather forecast for
three days in the past.
The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th
day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
You will also be given a string T of length 3 representing the actual weather
on those three days.
The i-th character (1 \leq i \leq 3) of S represents the actual weather on the
i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively.
Print the number of days for which the forecast was correct.
|
[{"input": "CSS\n CSR", "output": "2\n \n\n * For the first day, it was forecast to be cloudy, and it was indeed cloudy.\n * For the second day, it was forecast to be sunny, and it was indeed sunny.\n * For the third day, it was forecast to be sunny, but it was rainy.\n\nThus, the forecast was correct for two days in this case.\n\n* * *"}, {"input": "SSR\n SSR", "output": "3\n \n\n* * *"}, {"input": "RRR\n SSS", "output": "0"}]
|
Print the sum in a line.
|
s075898236
|
Wrong Answer
|
p02472
|
Two integers $A$ and $B$ separated by a space character are given in a line.
|
sum([int(i) for i in input().split()])
|
Addition of Big Integers
Given two integers $A$ and $B$, compute the sum, $A + B$.
|
[{"input": "5 8", "output": "13"}, {"input": "100 25", "output": "125"}, {"input": "-1 1", "output": "0"}, {"input": "12 -3", "output": "9"}]
|
Print the sum in a line.
|
s751620785
|
Accepted
|
p02472
|
Two integers $A$ and $B$ separated by a space character are given in a line.
|
if __name__ == "__main__":
a, b = list(map(lambda x: int(x), input().split()))
print(a + b)
|
Addition of Big Integers
Given two integers $A$ and $B$, compute the sum, $A + B$.
|
[{"input": "5 8", "output": "13"}, {"input": "100 25", "output": "125"}, {"input": "-1 1", "output": "0"}, {"input": "12 -3", "output": "9"}]
|
Print the answer.
* * *
|
s281015340
|
Wrong Answer
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
n, k = map(int, input().split())
a = [None] * n
m = 0
lian = 0
a0 = int(input())
a[0] = a0
for i in range(1, n):
a1 = int(input())
a[i] = a1
if a1 - a0 > k:
pass
elif a0 - a1 > k:
pass
else:
lian += 1
if lian > m:
m = lian
a0 = int(a1)
m1 = 0
lian = 0
a0 = a[n - 1]
for i in range(2, n + 1):
a1 = a[n - i]
if a1 - a0 > k:
pass
elif a0 - a1 > k:
pass
else:
lian += 1
if lian > m1:
m1 = lian
a0 = int(a1)
if m > m1:
print(m + 1)
else:
print(m1 + 1)
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s572013010
|
Wrong Answer
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
N, K = input().split()
K = int(K)
count = 1 # 最初は必ず含む
A1 = int(input())
l = []
l.append(A1)
for i in range(int(N) - 1):
A2 = int(input())
if abs(A1 - A2) <= K:
l.append(A2)
count += 1
A1 = A2
else:
pass
print(count)
# print(l)
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s518226149
|
Wrong Answer
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
import sys
sys.setrecursionlimit(10**6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def SI():
return sys.stdin.readline()[:-1]
class SegtreeMax:
def __init__(self, aa):
self.inf = 10**16
self.n = n = len(aa)
self.tree_width = tree_width = 1 << (n - 1).bit_length()
self.tree = [-self.inf] * (tree_width * 2 - 1)
self.tree[tree_width - 1 : tree_width - 1 + n] = aa
for u in range(tree_width - 2, -1, -1):
self.tree[u] = max(self.tree[u * 2 + 1], self.tree[u * 2 + 2])
def update(self, i, a):
seg_i = self.tree_width - 1 + i
self.tree[seg_i] = a
while seg_i != 0:
seg_i = (seg_i - 1) // 2
self.tree[seg_i] = max(self.tree[seg_i * 2 + 1], self.tree[seg_i * 2 + 2])
def element(self, i):
return self.tree[self.tree_width - 1 + i]
# [l,r)の最大値
def max(self, l, r, seg_i=0, segL=0, segR=-1):
if segR == -1:
segR = self.tree_width
if r <= segL or segR <= l:
return -self.inf
if l <= segL and segR <= r:
return self.tree[seg_i]
segM = (segL + segR) // 2
ret0 = self.max(l, r, seg_i * 2 + 1, segL, segM)
ret1 = self.max(l, r, seg_i * 2 + 2, segM, segR)
return max(ret0, ret1)
# [l,r)でrから左を見たとき、初めにaを超える値のインデックス
def OverL(self, l, r, a, u=0, ul=0, ur=-1):
if ur == -1:
ur = self.tree_width
if r <= ul or ur <= l or self.tree[u] <= a:
return -1
if ur - ul == 1:
return ul
um = (ul + ur) // 2
ret = self.OverL(l, r, a, u * 2 + 2, um, ur)
if ret != -1:
return ret
return self.OverL(l, r, a, u * 2 + 1, ul, um)
# [l,r)でlから右を見たとき、初めにaを超える値のインデックス
def OverR(self, l, r, a, u=0, ul=0, ur=-1):
if ur == -1:
ur = self.tree_width
if r <= ul or ur <= l or self.tree[u] <= a:
return self.n
if ur - ul == 1:
return ul
um = (ul + ur) // 2
ret = self.OverR(l, r, a, u * 2 + 1, ul, um)
if ret != self.n:
return ret
return self.OverR(l, r, a, u * 2 + 2, um, ur)
mx = 300005
n, k = MI()
st = SegtreeMax([0] * mx)
for _ in range(n):
a = II()
val = st.max(max(0, a - k), min(n, a + k + 1))
st.update(a, val + 1)
print(st.tree[0])
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s852686249
|
Wrong Answer
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10**9 + 1 # sys.maxsize # float("inf")
MOD = 10**9 + 7
def debug(*x):
print(*x, file=sys.stderr)
def solve(N, K, AS):
candidates = [[0]]
for i in range(1, N):
A = AS[i]
new_candidates = []
for c in candidates:
if abs(AS[c[-1]] - A) <= K:
new_candidates.append(c[:])
c.append(i)
new_candidates.append(c)
break
else:
new_candidates.append(c)
else:
new_candidates.append([i])
candidates = new_candidates
candidates.sort(key=len, reverse=True)
# debug("candidates", candidates)
return len(candidates[0])
def main():
# parse input
N, K = map(int, input().split())
AS = []
for i in range(N):
AS.append(int(input()))
print(solve(N, K, AS))
# tests
T1 = """
10 3
1
5
4
3
8
6
9
7
2
4
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
7
"""
T2 = """
6 2
5
7
3
3
3
3
"""
TEST_T2 = """
>>> as_input(T2)
>>> main()
5
"""
def _test():
import doctest
doctest.testmod()
g = globals()
for k in sorted(g):
if k.startswith("TEST_"):
doctest.run_docstring_examples(g[k], g, name=k)
def as_input(s):
"use in test, use given string as input file"
import io
f = io.StringIO(s.strip())
g = globals()
g["input"] = lambda: bytes(f.readline(), "ascii")
g["read"] = lambda: bytes(f.read(), "ascii")
input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
if sys.argv[-1] == "-t":
print("testing")
_test()
sys.exit()
main()
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s516392648
|
Wrong Answer
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
a, b = map(int, input().split())
s = [int(input()) for i in range(a)]
w = []
t = []
for i in range(a):
w.append(s[i])
for j in range(i + 1, a):
if abs(w[-1] - s[j]) <= b:
w.append(s[j])
t.append(len(w))
w.clear()
if len(t) == 50:
print(max(t))
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s643607374
|
Accepted
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x + "\n")
### セグメント木
class SegmentTree:
def __init__(self, n, a=None):
"""初期化
num : n以上の最小の2のべき乗
"""
num = 1
while num <= n:
num *= 2
self.num = num
self.seg = [ninf] * (2 * self.num - 1)
if a is not None:
# O(n)で初期化
assert len(a) == n
for i in range(n):
self.seg[num - 1 + i] = a[i]
for k in range(num - 2, -1, -1):
self.seg[k] = op(self.seg[2 * k + 1], self.seg[2 * k + 2])
def update(self, i, x):
"""update(i,x):Aiをxに更新する"""
k = i + (self.num - 1)
self.seg[k] = x
k = (k - 1) // 2
while k >= 0:
self.seg[k] = op(self.seg[2 * k + 1], self.seg[2 * k + 2])
k = (k - 1) // 2
def query(self, a, b):
k = 0
l = 0
r = self.num
q = [(k, l, r)]
ans = ninf
# 重なる区間を深さ優先探索
while q:
k, l, r = q.pop()
if r <= a or b <= l:
pass
elif a <= l and r <= b:
ans = op(ans, self.seg[k])
else:
q.append((2 * k + 1, l, (l + r) // 2))
q.append((2 * k + 2, (l + r) // 2, r))
return ans
def find_right(self, a, b, x=None, f=None):
"""[a,b)で値がx以上のインデックスの最大
存在しない場合-1を返す
"""
if f is None:
f = lambda y: y >= x
k = 0
l = 0
r = self.num
q = [(k, l, r, True)] # 行きがけかどうか
ans = -1
while q:
k, l, r, flg = q.pop()
if flg:
if (
not f(self.seg[k]) or r <= a or b <= l
): # 条件を満たせない or 区間が重複しない
pass
elif k >= self.num - 1: # 自身が葉
ans = max(ans, k - (self.num - 1))
return ans
else:
# 左への探索を予約
q.append((2 * k + 1, l, (l + r) // 2, False))
# 右への探索
q.append((2 * k + 2, (l + r) // 2, r, True))
else:
if ans >= 0:
return ans
q.append((k, l, r, True))
return ans
def find_left(self, a, b, x=None, f=None):
"""[a,b)で値がx以上のインデックス(0,1,...,self.num-1)の最小
条件を満たすものが存在しないとき、self.numを返す
"""
if f is None:
f = lambda y: y >= x
k = 0
l = 0
r = self.num
q = [(k, l, r, True)] # 行きがけかどうか
ans = self.num
while q:
k, l, r, flg = q.pop()
if flg:
if (
not f(self.seg[k]) or r <= a or b <= l
): # x以上を満たせない or 区間が重複しない
continue
elif k >= self.num - 1: # 自身が葉
ans = min(ans, k - (self.num - 1))
return ans
else:
# 右への探索を予約
q.append((2 * k + 2, (l + r) // 2, r, False))
# 左への探索
q.append((2 * k + 1, l, (l + r) // 2, True))
else:
if ans < self.num:
return ans
q.append((k, l, r, True))
return ans
def query_index(self, a, b, k=0, l=0, r=None):
"""query(a,b,0,0,num):[a,b)の最大値
最大値を与えるインデックスも返す
"""
if r is None:
r = self.num
if r <= a or b <= l:
return (ninf, None)
elif a <= l and r <= b:
return (self.seg[k], self._index(k))
else:
return op(
self.query_index(a, b, 2 * k + 1, l, (l + r) // 2),
self.query_index(a, b, 2 * k + 2, (l + r) // 2, r),
)
def _index(self, k):
if k >= self.num:
return k - (self.num - 1)
else:
if self.seg[2 * k + 1] >= self.seg[2 * k + 2]:
return self._index(2 * k + 1)
else:
return self._index(2 * k + 2)
ninf = -(10**9)
op = max
n, k = list(map(int, input().split()))
a = [int(input()) for _ in range(n)]
size = max(a) + 2
sg = SegmentTree(size)
for i in range(n):
v = a[i]
m, M = max(0, v - k), min(v + k, size - 1)
val = sg.query(m, M + 1)
if val < 0:
val = 0
sg.update(v, val + 1)
ans = sg.query(0, size)
print(ans)
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s311615888
|
Wrong Answer
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
san = 300000
N, K = [int(a) for a in input().split()]
l = [0] * 300000
for _ in range(N):
a = int(input())
M = 0
for i in range(-3, 4):
if a + i >= 0 and a + i < san:
M = max(M, l[a + i - 1])
l[a - 1] = M + 1
print(max(l))
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s227122839
|
Runtime Error
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
from functools import lru_cache
@lru_cache(maxsize=40000)
def subsolve(i):
a = As[i]
l = None
r = None
for j in range(i, 0, -1):
if a - k <= As[j - 1] <= a and l == None:
l = subsolve(j - 1) + 1
if a < As[j - 1] <= a + k and r == None:
r = subsolve(j - 1) + 1
if l != None and r != None:
break
if l == None:
l = 1
if r == None:
r = 1
return max(l, r)
def solve(n, k, xs):
return max(subsolve(i) for i in range(n))
if __name__ == "__main__":
n, k = map(int, input().split())
(*As,) = [int(input()) for _ in range(n)]
print(solve(n, k, As))
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the answer.
* * *
|
s600136166
|
Runtime Error
|
p02537
|
Input is given from Standard Input in the following format:
N K
A_1
A_2
:
A_N
|
r=input().split()
N=int(r[0])
Q=int(r[1])
data="1"*N
d=[input().split() for i in range(Q)]
for i in range(Q):
data=data[0:int(d[i][0])-1]+d[i][2]*(int(d[i][1])-int(d[i][0])+1)+data[int(d[i][1]):N]
print(int(data)%998244353)
|
Statement
You are given a sequence A_1, A_2, ..., A_N and an integer K.
Print the maximum possible length of a sequence B that satisfies the following
conditions:
* B is a (not necessarily continuous) subsequence of A.
* For each pair of adjacents elements of B, the absolute difference of the elements is at most K.
|
[{"input": "10 3\n 1\n 5\n 4\n 3\n 8\n 6\n 9\n 7\n 2\n 4", "output": "7\n \n\nFor example, B = (1, 4, 3, 6, 9, 7, 4) satisfies the conditions.\n\n * It is a subsequence of A = (1, 5, 4, 3, 8, 6, 9, 7, 2, 4).\n * All of the absolute differences between two adjacent elements (|1-4|, |4-3|, |3-6|, |6-9|, |9-7|, |7-4|) are at most K = 3."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s589682272
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda: int(input())
inl = lambda: list(map(int, input().split()))
inm = lambda: map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7
def ddprint(x):
if DBG:
print(x)
n, m = inm()
u0 = []
u1 = []
u2 = []
u3 = []
u4 = []
u5 = []
u6 = []
u7 = []
for i in range(n):
x, y, z = inm()
u0.append(x + y + z)
u1.append(x - y + z)
u2.append(x + y - z)
u3.append(x - y - z)
u4.append(-x + y + z)
u5.append(-x - y + z)
u6.append(-x + y - z)
u7.append(-x - y - z)
u0.sort(reverse=True)
u1.sort(reverse=True)
u2.sort(reverse=True)
u3.sort(reverse=True)
u4.sort(reverse=True)
u5.sort(reverse=True)
u6.sort(reverse=True)
u7.sort(reverse=True)
s0 = sum(u0[0:m])
s1 = sum(u1[0:m])
s2 = sum(u2[0:m])
s3 = sum(u3[0:m])
s4 = sum(u4[0:m])
s5 = sum(u5[0:m])
s6 = sum(u6[0:m])
s7 = sum(u7[0:m])
print(max([s0, s1, s2, s3, s4, s5, s6, s7]))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s127372342
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
def d_patisserie_abc():
N, M = [int(i) for i in input().split()]
Cake = [[int(i) for i in input().split()] for j in range(N)]
# 変数の意味は,左から順に, 綺麗さ, おいしさ, 人気度 をそれぞれ
# 正の方向 (p) に最大化する場合と負の方向 (n) に最大化する場合である.
# なお,nnn, nnp, npn, npp は,ppp, ppn, pnp, pnn を
# 逆にすることで得られる.
ppp, ppn, pnp, pnn = [], [], [], []
for x, y, z in Cake:
ppp.append(x + y + z)
ppn.append(x + y - z)
pnp.append(x - y + z)
pnn.append(x - y - z)
ppp.sort()
ppn.sort()
pnp.sort()
pnn.sort()
# 値が大きなものを M 個取って足して絶対値をとる
pts = map(
lambda x: abs(sum(x)),
(ppp[:M], ppn[:M], pnp[:M], pnn[:M], ppp[-M:], ppn[-M:], pnp[-M:], pnn[-M:]),
)
return max(pts)
print(d_patisserie_abc())
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s006959514
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import sys
N,M=map(int,input().split())
if M=0:
print(0)
sys.exit(0)
xyzlist=[]
for i in range(N):
x,y,z=map(int,input().split())
xyzlist.append((x,y,z))
#print(xyzlist)
selected_list1=[False]*N
pt_list=[0,0,0]
for _ in range(M):
max_ind=-1
max_point=-10**20
for i in range(N):
if selected_list1[i]:
continue
x,y,z=xyzlist[i]
point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])
if max_point<point:
max_ind=i
max_point=point
#print(max_ind+1,xyzlist[max_ind])
selected_list1[max_ind]=True
mx,my,mz=xyzlist[max_ind]
pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]
#print(pt_list)
#print(selected_list1)
#print(pt_list)
answer1=0
for i in range(3):
answer1+=abs(pt_list[i])
#print(answer1)
maxabs_ind=[-1,-1,-1]
maxabs=[-1,-1,-1]
for i in range(N):
x,y,z=xyzlist[i]
if abs(x)>maxabs[0]:
maxabs_ind[0]=i
maxabs[0]=abs(x)
if abs(y)>maxabs[1]:
maxabs_ind[1]=i
maxabs[1]=abs(y)
if abs(z)>maxabs[2]:
maxabs_ind[2]=i
maxabs[2]=abs(z)
#print(maxabs_ind)
selected_list2=[False]*N
selected_list2[maxabs_ind[0]]=True
pt_list=list(xyzlist[maxabs_ind[0]])
#print(pt_list)
for _ in range(M-1):
max_ind=-1
max_point=-10**20
for i in range(N):
if selected_list2[i]:
continue
x,y,z=xyzlist[i]
point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])
if max_point<point:
max_ind=i
max_point=point
#print(max_ind+1,xyzlist[max_ind])
selected_list2[max_ind]=True
mx,my,mz=xyzlist[max_ind]
pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]
#print(pt_list)
#print(selected_list2)
#print(pt_list)
answer2=0
for i in range(3):
answer2+=abs(pt_list[i])
#print(answer2)
selected_list3=[False]*N
selected_list3[maxabs_ind[1]]=True
pt_list=list(xyzlist[maxabs_ind[1]])
#print(pt_list)
for _ in range(M-1):
max_ind=-1
max_point=-10**20
for i in range(N):
if selected_list3[i]:
continue
x,y,z=xyzlist[i]
point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])
if max_point<point:
max_ind=i
max_point=point
#print(max_ind+1,xyzlist[max_ind])
selected_list3[max_ind]=True
mx,my,mz=xyzlist[max_ind]
pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]
#print(pt_list)
#print(selected_list3)
#print(pt_list)
answer3=0
for i in range(3):
answer3+=abs(pt_list[i])
#print(answer3)
selected_list4=[False]*N
selected_list4[maxabs_ind[2]]=True
pt_list=list(xyzlist[maxabs_ind[2]])
#print(pt_list)
for _ in range(M-1):
max_ind=-1
max_point=-10**20
for i in range(N):
if selected_list4[i]:
continue
x,y,z=xyzlist[i]
point=abs(pt_list[0]+x)-abs(pt_list[0])+abs(pt_list[1]+y)-abs(pt_list[1])+abs(pt_list[2]+z)-abs(pt_list[2])
if max_point<point:
max_ind=i
max_point=point
#print(max_ind+1,xyzlist[max_ind])
selected_list4[max_ind]=True
mx,my,mz=xyzlist[max_ind]
pt_list=[pt_list[0]+mx,pt_list[1]+my,pt_list[2]+mz]
#print(pt_list)
#print(selected_list3)
#print(pt_list)
answer4=0
for i in range(3):
answer4+=abs(pt_list[i])
#print(answer4)
print(answer1,answer2,answer3,answer4)
print(max(answer1,answer2,answer3,answer4))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s813388968
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n, m = map(int, input().split())
l = []
li = []
lis = []
for i in range(n):
a, b, c = map(int, input().split())
l.append(a)
li.append(b)
lis.append(c)
ans = []
l11 = list(l)
l1 = sorted(list(l))
li1 = list(li)
lis1 = list(lis)
cou1 = 0
l22 = list(l)
l2 = sorted(list(l), reverse=True)
li2 = list(li)
lis2 = list(lis)
cou2 = 0
l3 = list(l)
li33 = list(li)
li3 = sorted(list(li))
lis3 = list(lis)
cou3 = 0
l4 = list(l)
li44 = list(li)
li4 = sorted(list(li), reverse=True)
lis4 = list(lis)
cou4 = 0
l5 = list(l)
li5 = list(li)
lis55 = list(lis)
lis5 = sorted(list(lis))
cou5 = 0
l6 = list(l)
li6 = list(li)
lis66 = list(lis)
lis6 = sorted(list(lis), reverse=True)
cou6 = 0
cou1 += abs(sum(l1[0:m]))
lili1 = []
lislis1 = []
for i in range(m):
lili1.append(li[l11.index(l1[i])])
lislis1.append(lis[l11.index(l1[i])])
l11[l11.index(l1[i])] = "inf"
cou1 += abs(sum(lili1)) + abs(sum(lislis1))
ans.append(cou1)
cou2 += abs(sum(l2[0:m]))
lili2 = []
lislis2 = []
for i in range(m):
lili2.append(li[l22.index(l2[i])])
lislis2.append(lis[l22.index(l2[i])])
l22[l22.index(l2[i])] = "inf"
cou2 += abs(sum(lili2)) + abs(sum(lislis2))
ans.append(cou2)
cou3 += abs(sum(li3[0:m]))
ll3 = []
lislis3 = []
for i in range(m):
ll3.append(l[li33.index(li3[i])])
lislis3.append(lis[li33.index(li3[i])])
li33[li33.index(li3[i])] = "inf"
cou3 += abs(sum(ll3)) + abs(sum(lislis3))
ans.append(cou3)
cou4 += abs(sum(li4[0:m]))
ll4 = []
lislis4 = []
for i in range(m):
ll4.append(l[li44.index(li4[i])])
lislis4.append(lis[li44.index(li4[i])])
li44[li44.index(li4[i])] = "inf"
cou4 += abs(sum(ll4)) + abs(sum(lislis4))
ans.append(cou4)
cou5 += abs(sum(lis5[0:m]))
ll5 = []
lili5 = []
for i in range(m):
ll5.append(l[lis55.index(lis5[i])])
lili5.append(li[lis55.index(lis5[i])])
lis55[lis55.index(lis5[i])] = "inf"
cou5 += abs(sum(ll5)) + abs(sum(lili5))
ans.append(cou5)
cou6 += abs(sum(lis6[0:m]))
ll6 = []
lili6 = []
for i in range(m):
ll6.append(l[lis66.index(lis6[i])])
lili6.append(li[lis66.index(lis6[i])])
lis66[lis66.index(lis6[i])] = "inf"
cou6 += abs(sum(ll6)) + abs(sum(lili6))
ans.append(cou6)
print(max(ans))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s273984304
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')
#A
def A():
a, b = LI()
if a <= 8 and b <= 8:
print("Yay!")
else:
print(":(")
return
#B
def B():
d, n = LI()
print(str(n * (n != 100) or n + 1) + "00" * d)
return
#C
def C():
II()
ans = 0
a = LI()
for ai in a:
while not ai % 2:
ans += 1
ai = ai // 2
print(ans)
return
#D
# 自力ACだが別解がイミフ
# https://ja.wikipedia.org/wiki/%E4%B8%AD%E5%A4%AE%E5%80%A4%E3%81%AE%E4%B8%AD%E5%A4%AE%E5%80%A4
# 中央値の中央値?理解できず。
# PS: 理解した
# https://naoyat.hatenablog.jp/entry/median-of-medians
# https://techblog.nhn-techorus.com/archives/15289
def D():
n, m = LI()
l = LIR(n)
dp = [[-inf] * 8 for i in range(m+1)]
for i in range(8):
dp[0][i] = 0
for i in range(n):
for k in range(m, 0, -1):
for x in range(8):
t = 0
for j in range(3):
t += l[i][j] if (x >> j) & 1 else -1 * l[i][j]
dp[k][x] = max(dp[k][x], dp[k - 1][x] + t)
print(max(dp[-1]))
return
def D_():
# 配列arrayのk番目に大きい要素を計算する
# ただし、探索範囲はstart番目からend番目まで
def Select_kth(array, start, end, k):
length = end - start
if length == 1:
return array[start]
elif length <= 10:
return Select_kth_small(array, start, end, k - start)
pivot_value = -1
while start < end:
p[0] += 1
# ピボット値を計算する
pivot_value = Pivot(array, start, end)
#print(start, end, pivot_value)
# 領域を分割してピボットの値を位置を計算する
pivotIndex = Partipition(array, start, end, pivot_value)
#print(array,start, end, k, pivotIndex, pivot_value)
# 最終的にピボットの位置がk番目になったら完了
if pivotIndex == k: break
# ピボット値がk番目より左にあったら
# k番目の要素はピボット値の位置より右にあるので
# 次の探索開始地点はピボット値の右隣から
elif pivotIndex < k:
start = pivotIndex + 1
# ピボット値がk番目より右にあったら
# k番目の要素はピボット値の位置より左にあるので
# 次の探索終了地点はピボット値の左隣まで
elif pivotIndex > k:
end = pivotIndex
#print(start, end)
return array[k]
# 配列arrayのstart番目からend番目までの中でピボット値を計算する
def Pivot(array, start, end):
medians = []
a = (end - start + 4) // 5
# 先頭から5個ずつの小配列に分割する
for i in range(start, end, 5):
# 小配列の開始地点と終了地点
subStart = i
subEnd = min(i + 5, end)
# 小配列(5要素)の中央値を計算する
median = Median5(array, subStart, subEnd)
# 結果を格納する
medians.append(median)
# 各小配列の中央値を集めた配列の中で、さらに中央値を計算する(中央値の中央値)
if a == 1: return medians[0]
return Select_kth(medians, 0, a, a // 2)
# 小配列(5要素)のarrayyのstart番目からend番目までをsortして中央値を計算する
def Median5(array, start, end):
return Select_kth_small(array, start, end, (end - start - 1) // 2)
def Select_kth_small(array, start, end, k):
tmp = array[start:end]
tmp.sort()
for i, t in enumerate(tmp):
array[start + i] = t
#print(tmp, array, start, end, k, "a")
return array[start+k]
# 領域を分割してピボットの値を位置を計算する
# クイックソート
def Partipition(array, start, end, pivot):
i = start
j = end - 1
while i < j:
while i < end and array[i] < pivot: i += 1
while start <= j and pivot <= array[j]: j -= 1
if i >= j: break
array[i], array[j] = array[j], array[i]
i += 1
j -= 1
#print(array, i - 1, j + 1)
#print(array)
return i
n, m = LI()
ans = inf
xyz = LIR(n)
for full in range(8):
p = [0]
tmp = [None] * n
for fulli in range(n):
res = 0
for fullj in range(3):
res += xyz[fulli][fullj] if full >> fullj & 1 else - 1 * xyz[fulli][fullj]
tmp[fulli] = res
Select_kth(tmp, 0, n, m-1)
ans = min(ans, sum(tmp[:m]))
print(-1*ans)
#Solve
if __name__ == '__main__':
D_()
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s031295466
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
N,M = map(int, input().split())
X = [ [int(j) for j in input().split()] for _ in range(N)]
ans = 0
for i in range(1<<3):
if M=0:
break
dp = [ [0] * (M+1) for _ in range(N+1)]
for n in range(0,N):
x,y,z = X[n]
s = (x if (i & (1<<2)) else -x) \
+ (y if (i & (1<<1)) else -y) \
+ (z if (i & (1<<0)) else -z) \
for m in range(min(n,M-1), -1, -1 ):
dp[n+1][m+1] = max(dp[n+1][m+1], s + dp[n][m] )
dp[n+1][m] = max(dp[n+1][m], dp[n][m])
dp[n+1][M] = max(dp[n+1][M], dp[n][M])
ans = max(ans, dp[N][M])
print(ans)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s062209206
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import sys
def input():
return sys.stdin.readline().strip()
def quickSelect(A, k):
"""
長さnの配列Aの中からk番目(1-indexed)に小さい値を線形時間で求めるアルゴリズム。
動作原理は次を参照:http://www.flint.jp/blog/?entry=109
処理の流れは次を参照:https://naoyat.hatenablog.jp/entry/median-of-medians
使用例:quickSelect([2,7,1,8,2], 5, 3) => 2
"""
n = len(A)
while True:
B = A
m = n
# 1.配列からmedian of mediansにより適切なpivotを選択(25%~75%に収まる)
while m > 5:
medians = []
rem = 0
for i in range(m // 5):
sortB = sorted(B[i * 5 : (i + 1) * 5])
medians.append(sortB[2])
if m % 5 != 0:
sortB = sorted(B[(m // 5) * 5 :])
medians.append(sortB[(m - (m // 5) * 5) // 2])
rem = 1
B = medians
m = m // 5 + rem
B.sort()
pivot = B[m // 2]
# 2.pivotを軸に大小で左右に分ける
left = []
right = []
left_num = 0
right_num = 0
for a in A:
if a < pivot:
left.append(a)
left_num += 1
elif a > pivot:
right.append(a)
right_num += 1
if left_num < k <= n - right_num:
return pivot
elif left_num < k:
A = right
k -= n - right_num
n = right_num
else:
A = left
n = left_num
def main():
N, M = map(int, input().split())
cakes = [(0, 0, 0)]
for _ in range(N):
x, y, z = map(int, input().split())
cakes.append((x, y, z))
"""
quickSelectによりO(N)で解ける別解を実装。
x+y+zやx-y-z等のそれぞれに対してcakesをソートして大きい値から取れば良い。
"""
ans = 0
for i in range(8):
sorted_cakes = []
for j in range(1, N + 1):
S = 0
for k in range(3): # iの立っているビットでx, y, zの符号を管理している!!
if i & (1 << k):
S += cakes[j][k]
else:
S -= cakes[j][k]
sorted_cakes.append(S)
# ここでsorted_cakesのM番目に大きな値(=(N - M + 1)番目に小さな値)をquickSelectで求める
# あとはその数以上なら評価に加算すれば良い
val = 0
bound = quickSelect(sorted_cakes, N - M + 1)
cnt = 0
for c in sorted_cakes:
if c > bound:
val += c
cnt += 1
val += bound * (M - cnt)
ans = max(ans, val)
print(ans)
if __name__ == "__main__":
main()
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s986435099
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import sys
temp = input().split(" ")
n = int(temp[0])
k = int(temp[1])
cakes = []
m = 0
for i in range(n):
temp = list(map(int, input().split(" ")))
cakes.append(temp)
x = [0, 1, 2]
y = [1, 2, 0]
z = [2, 0, 1]
aax = [-1, 1]
aay = [-1, 1]
aaz = [-1, 1]
for j in range(3):
for ax in aax:
for ay in aay:
for az in aaz:
ans = [0, 0, 0]
cakes.sort(key=lambda p: (ax * p[x[j]], ay * p[y[j]], az * p[z[j]]))
temp = cakes[:k]
for cake in temp:
ans[0] += cake[0]
ans[1] += cake[1]
ans[2] += cake[2]
if abs(ans[0]) + abs(ans[1]) + abs(ans[2]) > m:
m = abs(ans[0]) + abs(ans[1]) + abs(ans[2])
# ans = [0, 0, 0]
# cakes.reverse()
# temp = cakes[:k]
# for cake in temp:
# ans[0] += cake[0]
# ans[1] += cake[1]
# ans[2] += cake[2]
# if abs(ans[0]) + abs(ans[1]) + abs(ans[2]) > m:
# m = abs(ans[0]) + abs(ans[1]) + abs(ans[2])
# for j in range(3):
# ans = [0, 0, 0]
# cakes.sort(key=lambda p: -p[j])
# temp = cakes[:k]
# for cake in temp:
# ans[0] += cake[0]
# ans[1] += cake[1]
# ans[2] += cake[2]
# if abs(ans[0]) + abs(ans[1]) + abs(ans[2]) > m:
# m = abs(ans[0]) + abs(ans[1]) + abs(ans[2])
print(m)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s521254217
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n, m = map(int, input().split())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
z = [0 for i in range(n)]
op = ["+", "-"]
vals = {}
for i in range(n):
x[i], y[i], z[i] = map(int, input().split())
for o1 in op:
term1 = o1 + str(x[i])
for o2 in op:
term2 = o2 + str(y[i])
for o3 in op:
term3 = o3 + str(z[i])
eq = term1 + term2 + term3
key = o1 + o2 + o3
if key not in vals:
vals[key] = []
vals[key].append(eval(eq))
vl = []
for key in vals.keys():
vals[key].sort(reverse=True)
vl.append(abs(sum(vals[key][:m])))
print(max(vl))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s577468522
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
###############################################################################
from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict
mod = 1
def intin():
input_tuple = input().split()
if len(input_tuple) <= 1:
return int(input_tuple[0])
return tuple(map(int, input_tuple))
def intina():
return [int(i) for i in input().split()]
def intinl(count):
return [intin() for _ in range(count)]
def modadd(x, y):
global mod
return (x + y) % mod
def modmlt(x, y):
global mod
return (x * y) % mod
def lcm(x, y):
while y != 0:
z = x % y
x = y
y = z
return x
def combination(x, y):
assert x >= y
if y > x // 2:
y = x - y
ret = 1
for i in range(0, y):
j = x - i
i = i + 1
ret = ret * j
ret = ret // i
return ret
def get_divisors(x):
retlist = []
for i in range(1, int(x**0.5) + 3):
if x % i == 0:
retlist.append(i)
retlist.append(x // i)
return retlist
def get_factors(x):
retlist = []
for i in range(2, int(x**0.5) + 3):
while x % i == 0:
retlist.append(i)
x = x // i
retlist.append(x)
return retlist
def make_linklist(xylist):
linklist = {}
for a, b in xylist:
linklist.setdefault(a, [])
linklist.setdefault(b, [])
linklist[a].append(b)
linklist[b].append(a)
return linklist
def calc_longest_distance(linklist, v=1):
distance_list = {}
distance_count = 0
distance = 0
vlist_previous = []
vlist = [v]
nodecount = len(linklist)
while distance_count < nodecount:
vlist_next = []
for v in vlist:
distance_list[v] = distance
distance_count += 1
vlist_next.extend(linklist[v])
distance += 1
vlist_to_del = vlist_previous
vlist_previous = vlist
vlist = list(set(vlist_next) - set(vlist_to_del))
max_distance = -1
max_v = None
for v, distance in distance_list.items():
if distance > max_distance:
max_distance = distance
max_v = v
return (max_distance, max_v)
def calc_tree_diameter(linklist, v=1):
_, u = calc_longest_distance(linklist, v)
distance, _ = calc_longest_distance(linklist, u)
return distance
###############################################################################
def f(slist, m):
slist.sort()
xsum = ysum = zsum = 0
for _, x, y, z in slist[:m]:
xsum += x
ysum += y
zsum += z
return abs(xsum) + abs(ysum) + abs(zsum)
def main():
n, m = intin()
xyzlist = intinl(n)
ans = -float("inf")
slist = [(x + y + z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
slist = [(-x + y + z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
slist = [(x - y + z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
slist = [(x + y - z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
slist = [(-x - y + z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
slist = [(x - y - z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
slist = [(-x + y - z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
slist = [(-x - y - z, x, y, z) for x, y, z in xyzlist]
ans = max(ans, f(slist, m))
print(ans)
if __name__ == "__main__":
main()
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s085338455
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n, m = map(int, input().split())
cake = [[int(i) for i in input().split()] for j in range(n)]
a = sum(sorted([sum(i) for i in cake], reverse=True)[:m])
b = sum(
sorted([cake[i][0] + cake[i][1] - cake[i][2] for i in range(n)], reverse=True)[:m]
)
c = sum(
sorted([cake[i][0] - cake[i][1] - cake[i][2] for i in range(n)], reverse=True)[:m]
)
d = sum(
sorted([cake[i][0] - cake[i][1] + cake[i][2] for i in range(n)], reverse=True)[:m]
)
e = sum(
sorted([0 - cake[i][0] + cake[i][1] - cake[i][2] for i in range(n)], reverse=True)[
:m
]
)
f = sum(
sorted([0 - cake[i][0] + cake[i][1] + cake[i][2] for i in range(n)], reverse=True)[
:m
]
)
g = sum(
sorted([0 - cake[i][0] - cake[i][1] - cake[i][2] for i in range(n)], reverse=True)[
:m
]
)
h = sum(
sorted([0 - cake[i][0] - cake[i][1] - cake[i][2] for i in range(n)], reverse=True)[
:m
]
)
print(max(a, b, c, d, e, f, g, h))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s238927525
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
def read():
return int(input())
def readlist():
return list(map(int, input().split()))
def readmap():
return map(int, input().split())
N, M = readmap()
cake = []
for _ in range(N):
x, y, z = readmap()
cake.append((x, y, z))
ans_candidate = []
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] + x[1] + x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] + x[1] - x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] - x[1] + x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] + x[1] + x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: x[0] - x[1] - x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] + x[1] - x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] - x[1] + x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
point0 = 0
point1 = 0
point2 = 0
cake.sort(key=lambda x: -x[0] - x[1] - x[2], reverse=True)
for i in range(M):
point0 += cake[i][0]
point1 += cake[i][1]
point2 += cake[i][2]
ans_candidate.append(abs(point0) + abs(point1) + abs(point2))
print(max(ans_candidate))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s995866265
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 16 21:53:05 2018
@author: Riichi_Yokoyama
"""
import numpy as np
N, M = map(int, input().split())
a = []
for i in range(N):
a.append(list(map(int, input().split())))
ar = np.array(a)
print(ar)
b = np.zeros((N, 8))
for i in range(0, N):
b[i, 0] = ar[i, 0] + ar[i, 1] + ar[i, 2]
b[i, 1] = ar[i, 0] + ar[i, 1] - ar[i, 2]
b[i, 2] = ar[i, 0] - ar[i, 1] + ar[i, 2]
b[i, 3] = ar[i, 0] - ar[i, 1] - ar[i, 2]
b[i, 4] = -ar[i, 0] + ar[i, 1] + ar[i, 2]
b[i, 5] = -ar[i, 0] + ar[i, 1] - ar[i, 2]
b[i, 6] = -ar[i, 0] - ar[i, 1] + ar[i, 2]
b[i, 7] = -ar[i, 0] - ar[i, 1] - ar[i, 2]
e0 = np.asarray([0, 0, 0, 0, 0, 0, 0, 0])
c0 = b[:, 0]
d0 = np.sort(c0)[::-1]
e0[0] = sum(d0[:M])
c1 = b[:, 1]
d1 = np.sort(c1)[::-1]
e0[1] = sum(d1[:M])
c2 = b[:, 2]
d2 = np.sort(c2)[::-1]
e0[2] = sum(d2[:M])
c3 = b[:, 3]
d3 = np.sort(c3)[::-1]
e0[3] = sum(d3[:M])
c4 = b[:, 4]
d4 = np.sort(c4)[::-1]
e0[4] = sum(d4[:M])
c5 = b[:, 5]
d5 = np.sort(c5)[::-1]
e0[5] = sum(d5[:M])
c6 = b[:, 6]
d6 = np.sort(c6)[::-1]
e0[6] = sum(d6[:M])
c7 = b[:, 7]
d7 = np.sort(c7)[::-1]
e0[7] = sum(d7[:M])
e1 = np.sort(e0)[::-1]
print(e1[0])
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s406220067
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import sys
from array import array
N, M = [int(n) for n in input().split()]
# XYZs = [[int(x) for x in input().split()] for _ in range(N)]
XYZs = [[int(x) for x in line.split()] for line in sys.stdin.readlines()]
def score(xyz, signs):
return sum(x * s for (x, s) in zip(xyz, signs))
def index(n, m):
return n + m * N
neginf = -float("inf")
s = 0
DP = array("q", [0] * ((N + 1) * (M + 1)))
# DP = [[neginf for _ in range(M+1)] for _ in range(N+1)]
for signs in [(x, y, z) for x in (1, -1) for y in (1, -1) for z in (1, -1)]:
# select m form XYZs[:n]
scores = [score(XYZs[n], signs) for n in range(N)]
scores = array("q", scores)
for n in range(N + 1):
DP[index(n, 0)] = 0
for n in range(1, N + 1):
score_n_1 = scores[n - 1]
for m in range(1, M + 1):
DP[index(n, m)] = max(
DP[index(n - 1, m - 1)] + score_n_1, DP[index(n - 1, m)]
)
# DP_n[m] = max(DP_n_1[m-1] + score_n_1, DP_n_1[m])
s = max(s, DP[index(N, M)])
print(s)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s771854506
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import numpy
inp = input().split()
l = list()
for i in range(int(inp[0])):
l1 = input().split()
l1 = [int(s) for s in l1]
l.append(l1)
l3 = []
a1 = []
a2 = []
a3 = []
a4 = []
a5 = []
a6 = []
a7 = []
a8 = []
for ll in l:
a1.append(ll[0] + ll[1] + ll[2])
a2.append(ll[0] + ll[1] - ll[2])
a3.append(ll[0] - ll[1] + ll[2])
a4.append(ll[0] - ll[1] - ll[2])
a5.append(-ll[0] + ll[1] + ll[2])
a6.append(-ll[0] + ll[1] - ll[2])
a7.append(-ll[0] - ll[1] + ll[2])
a8.append(-ll[0] - ll[1] - ll[2])
def temp(li):
li.sort()
li.reverse()
count = 0
for i in range(int(inp[1])):
count += li[i]
l3.append(count)
temp(a1)
temp(a2)
temp(a3)
temp(a4)
temp(a5)
temp(a6)
temp(a7)
temp(a8)
print(max(l3))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s071354575
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import sys
def input():
return sys.stdin.readline().strip()
def main():
N, M = map(int, input().split())
cakes = [(0, 0, 0)]
for _ in range(N):
x, y, z = map(int, input().split())
cakes.append((x, y, z))
"""
dp[n][m][t] = (1~n番目までのケーキからm個のケーキをタイプtで選んだ時の合計の最大値)
と定める。ここでタイプとは
t=0 -> val = x + y + z
t=1 -> val = x + y - z
t=2 -> val = x - y + z
t=3 -> val = x - y - z
t=4 -> val = -x + y + z
t=5 -> val = -x + y - z
t=6 -> val = -x - y + z
t=7 -> val = -x - y - z
どのタイプにせよ更新式は同じで、dp[n][m] = max(dp[n-1][m], dp[n-1][m-1] + (n番目のdp = [0]aaa))
"""
dp = [[[0] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for n in range(1, N + 1):
x, y, z = cakes[n]
for m in range(1, min(M + 1, n + 1)):
if n == m:
dp[n][m][0] = dp[n - 1][m - 1][0] + (x + y + z)
dp[n][m][1] = dp[n - 1][m - 1][1] + (x + y - z)
dp[n][m][2] = dp[n - 1][m - 1][2] + (x - y + z)
dp[n][m][3] = dp[n - 1][m - 1][3] + (x - y - z)
dp[n][m][4] = dp[n - 1][m - 1][4] + (-x + y + z)
dp[n][m][5] = dp[n - 1][m - 1][5] + (-x + y - z)
dp[n][m][6] = dp[n - 1][m - 1][6] + (-x - y + z)
dp[n][m][7] = dp[n - 1][m - 1][7] + (-x - y - z)
else:
dp[n][m][0] = max(dp[n - 1][m][0], dp[n - 1][m - 1][0] + (x + y + z))
dp[n][m][1] = max(dp[n - 1][m][1], dp[n - 1][m - 1][1] + (x + y - z))
dp[n][m][2] = max(dp[n - 1][m][2], dp[n - 1][m - 1][2] + (x - y + z))
dp[n][m][3] = max(dp[n - 1][m][3], dp[n - 1][m - 1][3] + (x - y - z))
dp[n][m][4] = max(dp[n - 1][m][4], dp[n - 1][m - 1][4] + (-x + y + z))
dp[n][m][5] = max(dp[n - 1][m][5], dp[n - 1][m - 1][5] + (-x + y - z))
dp[n][m][6] = max(dp[n - 1][m][6], dp[n - 1][m - 1][6] + (-x - y + z))
dp[n][m][7] = max(dp[n - 1][m][7], dp[n - 1][m - 1][7] + (-x - y - z))
print(max(dp[N][M]))
if __name__ == "__main__":
main()
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s560804610
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [[c] * b for i in range(a)]
def list3d(a, b, c, d):
return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1):
return int(-(-x // y))
def INT():
return int(input())
def MAP():
return map(int, input().split())
def LIST(N=None):
return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes():
print("Yes")
def No():
print("No")
def YES():
print("YES")
def NO():
print("NO")
sys.setrecursionlimit(10**9)
INF = 10**18
MOD = 10**9 + 7
N, M = MAP()
XYZ = []
for i in range(N):
x, y, z = MAP()
XYZ.append((x, y, z))
# dp[i][j][S] := i個目まで見て、j個選んだ状態で、3つの値をそれぞれ+とみなすか-とみなすかの2^3通りを集合Sで表した時の最大値
dp = list3d(N + 1, M + 1, 1 << 3, -INF)
for S in range(1 << 3):
dp[0][0][S] = 0
for i in range(N):
for j in range(M + 1):
if i < j:
break
for S in range(1 << 3):
# このケーキを選ばない遷移
dp[i + 1][j][S] = max(dp[i + 1][j][S], dp[i][j][S])
if j < M:
nxt = 0
for k in range(3):
if S & 1 << k:
# この値は+とみなす
nxt += XYZ[i][k]
else:
# この値は-とみなす
nxt += -XYZ[i][k]
# このケーキを選ぶ遷移
dp[i + 1][j + 1][S] = max(dp[i + 1][j + 1][S], dp[i][j][S] + nxt)
# N個見てM個選び終わって、+-をどう扱ったかの2^3通りから最大を取る
print(max(dp[N][M]))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s501276287
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
N, M = map(int, input().split())
C1, C2, C3, C4, C5, C6, C7, C8 = [], [], [], [], [], [], [], []
def calc(L):
p, q, r = 0, 0, 0
for k in range(M):
p += L[k][0]
q += L[k][1]
r += L[k][2]
return abs(p) + abs(q) + abs(r)
for k in range(N):
s, t, u = map(int, input().split())
C1.append([s, t, u])
C2.append([s, -t, u])
C3.append([s, t, -u])
C4.append([-s, t, u])
C5.append([-s, -t, u])
C6.append([-s, t, -u])
C7.append([s, -t, -u])
C8.append([s, -t, -u])
ans = 0
D = sorted(C1, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C1, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C1, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C1, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C1, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C1, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
D = sorted(C2, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C2, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C2, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C2, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C2, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C2, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
D = sorted(C3, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C3, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C3, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C3, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C3, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C3, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
D = sorted(C4, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C4, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C4, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C4, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C4, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C4, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
D = sorted(C5, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C5, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C5, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C5, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C5, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C5, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
D = sorted(C6, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C6, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C6, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C6, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C6, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C6, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
D = sorted(C7, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C7, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C7, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C7, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C7, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C7, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
D = sorted(C8, key=lambda x: (-x[0], -x[1], -x[2]))
E = sorted(C8, key=lambda x: (-x[1], -x[0], -x[2]))
F = sorted(C8, key=lambda x: (-x[2], -x[1], -x[0]))
G = sorted(C8, key=lambda x: (-x[0], -x[2], -x[1]))
H = sorted(C8, key=lambda x: (-x[1], -x[2], -x[0]))
I = sorted(C8, key=lambda x: (-x[2], -x[0], -x[1]))
ans = max(ans, calc(D), calc(E), calc(F), calc(G), calc(H), calc(I))
print(ans)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s876954009
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n[0])]
c = n[0]
d = n[1]
e = [1, -1]
f = []
for i in e:
for j in e:
for k in e:
f.append([i, j, k])
ans = []
for i in f:
g = []
for j in a:
g.append(sum([j[k] * i[k] for k in range(3)]))
g.sort()
g.reverse()
ans.append(sum(g[:3]))
print(max(ans))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s468588425
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
N, M = map(int, input().split(" "))
evaluate = [list(map(int, input().split(" "))) for _ in range(N)]
dp = [[-1, -1, -1] for _ in range(M + 1)]
dp[0] = [0, 0, 0]
for i in range(M + 1):
if dp[i] == [-1, -1, -1]:
tmp = 0
cand_i = -1
for k, v in enumerate(evaluate):
x = max(
sum(map(abs, dp[i - 1])),
sum([abs(dp[i - 1][j] + v[j]) for j in range(3)]),
)
if x > tmp:
tmp = x
cand_i = k
dp[i] = [dp[i - 1][j] + evaluate[cand_i][j] for j in range(3)]
del evaluate[cand_i]
print(sum(map(abs, dp[M])))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s568499275
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
N, M = map(int, input().split())
L = [list(map(int, input().split())) for i in range(N)]
x = [0] * N
x1 = [0] * N
a1 = 0
for i in range(N):
x[i] = sum(L[i])
x1 = sorted(x, reverse=True)
for i in range(M):
a1 += x1[i]
# print(a1)
x2 = [0] * N
a2 = 0
for i in range(N):
x[i] = L[i][0] + L[i][1] - L[i][2]
x2 = sorted(x, reverse=True)
for i in range(M):
a2 += x2[i]
# print(a2)
x3 = [0] * N
a3 = 0
for i in range(N):
x[i] = L[i][0] - L[i][1] + L[i][2]
x3 = sorted(x, reverse=True)
for i in range(M):
a3 += x3[i]
# print(a3)
x4 = [0] * N
a4 = 0
for i in range(N):
x[i] = L[i][0] - L[i][1] - L[i][2]
x4 = sorted(x, reverse=True)
for i in range(M):
a4 += x4[i]
# print(a4)
x5 = [0] * N
a5 = 0
for i in range(N):
x[i] = -L[i][0] + L[i][1] + L[i][2]
x5 = sorted(x, reverse=True)
for i in range(M):
a5 += x5[i]
# print(a5)
x6 = [0] * N
a6 = 0
for i in range(N):
x[i] = -L[i][0] + L[i][1] - L[i][2]
x6 = sorted(x, reverse=True)
for i in range(M):
a6 += x6[i]
# print(a6)
x7 = [0] * N
a7 = 0
for i in range(N):
x[i] = -L[i][0] - L[i][1] + L[i][2]
x7 = sorted(x, reverse=True)
for i in range(M):
a7 += x7[i]
# print(a7)
x8 = [0] * N
a8 = 0
for i in range(N):
x[i] = -L[i][0] - L[i][1] - L[i][2]
x8 = sorted(x, reverse=True)
for i in range(M):
a8 += x8[i]
# print(a8)
print(max(a1, a2, a3, a4, a5, a6, a7, a8))
# 8通り試せばいいかな
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s218180217
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
# データ読み込み
import sys
from collections import deque
def input_data(d=""):
t = sys.stdin.read()
if t:
return t
else:
if d[0] == "\n":
d = d[1:]
if d[-1] == "\n":
d = d[:-1]
return d
A, AA, *B = map(int, input_data().split())
m = []
out = 0
t = [[] for i in range(8)]
for a, b, c in zip(*[iter(B)] * 3):
t[0].append(a + b + c)
t[1].append(a + b - c)
t[2].append(a - b + c)
t[3].append(a - b - c)
t[4].append(-a + b + c)
t[5].append(-a + b - c)
t[6].append(-a - b + c)
t[7].append(-a - b - c)
for i in range(8):
t[i].sort(reverse=True)
if out < sum(t[i][:AA]):
out = sum(t[i][:AA])
print(out)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s491476184
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
N, M = map(int, input().split())
X = [0 for i in range(N)]
Y = [0 for i in range(N)]
Z = [0 for i in range(N)]
PPP = [0 for i in range(N)]
PPM = [0 for i in range(N)]
PMP = [0 for i in range(N)]
PMM = [0 for i in range(N)]
MPP = [0 for i in range(N)]
MPM = [0 for i in range(N)]
MMP = [0 for i in range(N)]
MMM = [0 for i in range(N)]
for i in range(0, N):
X[i], Y[i], Z[i] = map(int, input().split())
PPP[i] = X[i] + Y[i] + Z[i]
PPM[i] = X[i] + Y[i] - Z[i]
PMP[i] = X[i] - Y[i] + Z[i]
PMM[i] = X[i] - Y[i] - Z[i]
MPP[i] = -X[i] + Y[i] + Z[i]
MPM[i] = -X[i] + Y[i] - Z[i]
MMP[i] = -X[i] - Y[i] + Z[i]
MMM[i] = -X[i] - Y[i] - Z[i]
nPPP = sorted(PPP, reverse=True)
nPPM = sorted(PPM, reverse=True)
nPMP = sorted(PMP, reverse=True)
nPMM = sorted(PMM, reverse=True)
nMPP = sorted(MPP, reverse=True)
nMPM = sorted(MPM, reverse=True)
nMMP = sorted(MMP, reverse=True)
nMMM = sorted(MMM, reverse=True)
mPPP = 0
mPPM = 0
mPMP = 0
mPMM = 0
mMPP = 0
mMPM = 0
mMMP = 0
mMMM = 0
for i in range(0, M):
mPPP += nPPP[i]
mPPM += nPPM[i]
mPMP += nPMP[i]
mPMM += nPMM[i]
mMPP += nMPP[i]
mMPM += nMPM[i]
mMMP += nMMP[i]
mMMM += nMMM[i]
print(max(mPPP, mPPM, mPMP, mPMM, mMPP, mMPM, mMMP, mMMM))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s495438311
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
# 要素が3つあるかと思いきや評価方法はそれらの総和だけなので結局1つだけじゃんね
# と思ったら問題を読み違えていた 合計値の絶対値なので最後までわからんということか 最後までやってると当然間に合わない これどうすんの 前回の計算結果も流用できないのでは
# -> ぜんぶためす でした 死
# "8通り"?????「基準が正方向と負方向の2つで、3つの要素のうち1つの基準が決まれば残りも決まる」から6通りじゃね??????????????
n, m = map(int, input().split())
dp = {}
beauties, yammies, favorities = [], [], []
for i in range(n):
b, y, f = map(int, input().split())
beauties.append([i, b])
yammies.append([i, y])
favorities.append([i, f])
def gen_indicies(base, reverse):
return list(
map(lambda x: x[0], sorted(base, key=lambda x: x[1], reverse=reverse)[:m])
)
def sum_by_indicies(arr, indicies):
ret = 0
for i in indices:
ret += arr[i][1]
return ret
ans = -(10**10)
# 綺麗さ降順
indices = gen_indicies(beauties, True)
b_tmp, y_tmp, f_tmp = (
sum_by_indicies(beauties, indices),
sum_by_indicies(yammies, indices),
sum_by_indicies(favorities, indices),
)
ans = max(ans, abs(b_tmp) + abs(y_tmp) + abs(f_tmp))
# 綺麗さ昇順
indices = gen_indicies(beauties, False)
b_tmp, y_tmp, f_tmp = (
sum_by_indicies(beauties, indices),
sum_by_indicies(yammies, indices),
sum_by_indicies(favorities, indices),
)
ans = max(ans, abs(b_tmp) + abs(y_tmp) + abs(f_tmp))
# 旨さ降順
indices = gen_indicies(beauties, True)
b_tmp, y_tmp, f_tmp = (
sum_by_indicies(beauties, indices),
sum_by_indicies(yammies, indices),
sum_by_indicies(favorities, indices),
)
ans = max(ans, abs(b_tmp) + abs(y_tmp) + abs(f_tmp))
# 旨さ昇順
indices = gen_indicies(beauties, False)
b_tmp, y_tmp, f_tmp = (
sum_by_indicies(beauties, indices),
sum_by_indicies(yammies, indices),
sum_by_indicies(favorities, indices),
)
ans = max(ans, abs(b_tmp) + abs(y_tmp) + abs(f_tmp))
# 人気さ降順
indices = gen_indicies(favorities, True)
b_tmp, y_tmp, f_tmp = (
sum_by_indicies(beauties, indices),
sum_by_indicies(yammies, indices),
sum_by_indicies(favorities, indices),
)
ans = max(ans, abs(b_tmp) + abs(y_tmp) + abs(f_tmp))
# 人気さ昇順
indices = gen_indicies(beauties, False)
b_tmp, y_tmp, f_tmp = (
sum_by_indicies(beauties, indices),
sum_by_indicies(yammies, indices),
sum_by_indicies(favorities, indices),
)
ans = max(ans, abs(b_tmp) + abs(y_tmp) + abs(f_tmp))
print(ans)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s148276156
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import bisect
import collections
s = input().rstrip()
t = input().rstrip()
counter_s = collections.Counter(s)
counter_t = collections.Counter(t)
for c in counter_t.keys():
if c not in counter_s.keys():
print(-1)
exit()
s_indices = collections.defaultdict(list)
for i, c in enumerate(s):
if c in counter_t.keys():
s_indices[c].append(i)
index = 0
count = 0
offset = 0
while index < len(t):
c = t[index]
i = bisect.bisect_left(s_indices[c], offset)
if i == len(s_indices[c]):
count += 1
offset = 0
else:
offset = s_indices[c][i]
index += 1
print(len(s) * count + offset + 1)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s636869587
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
# # n = int(input())
# a, b = map(int, input().split())
# # c = list(map(int, input().split()))
# # d = [list(map(int, input().split())) for _ in range(n)]
# # s = input()
#
# ans = "Yey!"
#
# if a <= 8 and b <= 8:
# ans ="Yey!"
# else:
# ans = ":("
#
# print(ans)
# D, N = map(int, input().split())
#
# ans = pow(100,D)*N
#
# if D == 0:
# print(N)
# else:
# print(ans)
# n = int(input())
# a = list(map(int, input().split()))
#
# sum_count = 0
#
# for a_i in a:
# while 1:
# a_i = a_i / 2
# if a_i.is_integer():
# sum_count += 1
# continue
# else:
# break
#
# print(sum_count)
N, M = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]
x_value = []
for x_i in x:
x_value.append(x_i[0] + x_i[1] + x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = sum_value
x_value = []
for x_i in x:
x_value.append(0 - x_i[0] + x_i[1] + x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = max(ans, sum_value)
x_value = []
for x_i in x:
x_value.append(0 + x_i[0] - x_i[1] + x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = max(ans, sum_value)
x_value = []
for x_i in x:
x_value.append(0 - x_i[0] - x_i[1] + x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = max(ans, sum_value)
x_value = []
for x_i in x:
x_value.append(0 + x_i[0] + x_i[1] - x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = max(ans, sum_value)
x_value = []
for x_i in x:
x_value.append(0 - x_i[0] + x_i[1] - x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = max(ans, sum_value)
x_value = []
for x_i in x:
x_value.append(0 + x_i[0] - x_i[1] - x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = max(ans, sum_value)
x_value = []
for x_i in x:
x_value.append(0 - x_i[0] - x_i[1] - x_i[2])
x_value.sort()
x_value.reverse()
sum_value = sum(x_value[:M])
ans = max(ans, sum_value)
print(ans)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s726024696
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
#!/usr/bin/env python3
def main():
na = list(map(int, input().split()))
N, M = na[0], na[1]
x = []
y = []
z = []
for i in range(N):
na = list(map(int, input().split()))
x.append(na[0])
y.append(na[1])
z.append(na[2])
a = []
b = []
c = []
d = []
for i in range(N):
a.append(x[i] + y[i] + z[i])
b.append(x[i] + y[i] - z[i])
c.append(x[i] - y[i] + z[i])
d.append(-x[i] + y[i] + z[i])
a.sort()
b.sort()
c.sort()
d.sort()
sa = sb = sc = sd = 0
ra = rb = rc = rd = 0
for i in range(M):
sa += a[i]
ra += a[N - 1 - i]
sb += b[i]
rb += b[N - 1 - i]
sc += c[i]
rc += c[N - 1 - i]
sd += d[i]
rd += d[N - 1 - i]
s = max(abs(sa), abs(sb), abs(sc), abs(sd), abs(ra), abs(rb), abs(rc), abs(rd))
print(s)
if __name__ == "__main__":
main()
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s730679408
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
#!/usr/bin/env python3
import sys
# import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict # subclass of dict. defaultdict(facroty)
# from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(nlgk)=O(n).
# from itertools import accumulate # accumulate(iter[, f])
# from functools import reduce # reduce(f, iter[, init])
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from fractions import gcd # for Python3.4.3
from itertools import product
def main():
mod = 10000007 # 10^9+7
inf = float("inf")
input = sys.stdin.readline # 改行文字が残ることに注意
sys.setrecursionlimit(10**6) # 1000 -> 1000000
def ii():
return int(input())
def mi():
return map(int, input().rstrip().split())
def lmi():
return list(map(int, input().rstrip().split()))
def li():
return list(input().rstrip())
n, m = mi()
x = [0] * n
y = [0] * n
z = [0] * n
for i in range(n):
L = lmi()
x[i] = L[0]
y[i] = L[1]
z[i] = L[2]
ans = 0
cost = [0] * n
for f_list in product([lambda x: x, lambda x: -x], repeat=3):
for i in range(n):
cost[i] = f_list[0](x[i]) + f_list[1](y[i]) + f_list[2](z[i])
cost.sort(reverse=True)
ans = max(ans, sum(cost[:m]))
print(ans)
if __name__ == "__main__":
main()
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s328855330
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]
xyz_sx = list(sorted(xyz, key=lambda t: t[0]))
xyz_sy = list(sorted(xyz, key=lambda t: t[1]))
xyz_sz = list(sorted(xyz, key=lambda t: t[2]))
maxc = None
sx, sy, sz = 0, 0, 0
for x, y, z in xyz_sx[:m]:
sx += x
sy += y
sz += z
maxc = abs(sx) + abs(sy) + abs(sz)
sx, sy, sz = 0, 0, 0
for x, y, z in xyz_sx[::-1][:m]:
sx += x
sy += y
sz += z
maxc = max(maxc, abs(sx) + abs(sy) + abs(sz))
sx, sy, sz = 0, 0, 0
for x, y, z in xyz_sy[:m]:
sx += x
sy += y
sz += z
maxc = max(maxc, abs(sx) + abs(sy) + abs(sz))
sx, sy, sz = 0, 0, 0
for x, y, z in xyz_sy[::-1][:m]:
sx += x
sy += y
sz += z
maxc = max(maxc, abs(sx) + abs(sy) + abs(sz))
sx, sy, sz = 0, 0, 0
for x, y, z in xyz_sz[:m]:
sx += x
sy += y
sz += z
maxc = max(maxc, abs(sx) + abs(sy) + abs(sz))
sx, sy, sz = 0, 0, 0
for x, y, z in xyz_sz[::-1][:m]:
sx += x
sy += y
sz += z
maxc = max(maxc, abs(sx) + abs(sy) + abs(sz))
print(maxc)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s096652599
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, j, n) for (int i = j; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
struct cake{
ll a;
ll b;
ll c;
};
int main(){
ll n,m;
cin >> n >> m;
vector<cake> cakes;
rep(i,n){
cake c;
ll x,y,z;
cin >> x >> y >> z;
c.a = x;c.b = y;c.c = z;
cakes.push_back(cake);
}
ll ans =0;
rep(i,n){
stringstream ss;
ss << bitset<12>(i);
string bit = ss.str();
reverse(bit.begin(), bit.end());
int bit_count = 0;
ll sum = 0;
rep(j,bit.length()){
if(bit[j] =='1'){
bit_count++;
if(bit_count > m) continue;
sum+=cakes[j].a+cakes[j].b+cakes[j].c;
}
}
ans = max(ans,sum);
}
cout <<ans<<endl;
}
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s983013214
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n,m = map(int,input().split())
l = []
for i in range(n):
x,y,z = map(int,input().split())
l.append([x,y,z])
xsum = 0
ysum = 0
zsum = 0
count = 0
if True:
while count < m:
count += 1
nowsum = abs(xsum) + abs(ysum) + abs(zsum)
kouho = []
for i in range(len(l)):
kouho.append([i,abs(xsum + l[i][0]) + abs(ysum + l[i][1]) + abs(zsum + l[i][2])])
kouho.append([i,abs(xsum -l[i][0]) + abs(ysum + l[i][1]) + abs(zsum + l[i][2])])
kouho.append([i,abs(xsum + l[i][0]) + abs(ysum -l[i][1]) + abs(zsum - l[i][2])])
kouho.append([i,abs(xsum + l[i][0]) + abs(ysum + l[i][1]) + abs(zsum -l[i][2])])
kouho.append([i,abs(xsum - l[i][0]) + abs(ysum + l[i][1]) + abs(zsum -l[i][2])])
kouho.append([i,abs(xsum - l[i][0]) + abs(ysum - l[i][1]) + abs(zsum +l[i][2])])
kouho.append([i,abs(xsum + l[i][0]) + abs(ysum - l[i][1]) + abs(zsum - l[i][2])])
kouho.append([i,abs(xsum - l[i][0]) + abs(ysum - l[i][1]) + abs(zsum - l[i][2])])
kouho = list(sorted(kouho, key = lambda x:x[1]))
nowsum < kouho[-1][1]:
xsum += l[kouho[-1][0]][0]
ysum += l[kouho[-1][0]][1]
zsum += l[kouho[-1][0]][2]
del l[kouho[-1][0]]
print(abs(xsum) + abs(ysum) + abs(zsum))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s183723023
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n,m = [int(i) for i in input().split()]
cakes = []
ranking = [[] for i in range(8)]
ranking2 = []
for i in range(n):
cakes.append(list(map(int,input().split())))
a = 0
for i in range(2):
for j in range(2):
for k in range(2):
for x in range(n):
kirei = cakes[x][0]
oisii = cakes[x][1]
ninki = cakes[x][2]
if i ==1:
kirei = (-1)*kirei
if j ==1:
oisii = (-1) * oisii
if k==1:
ninki = (-1)*ninki
sum = kirei + oisii + ninki
ranking[a].append(sum)
a += 1
for i in ranking:
i = sorted(i)
i = i[::-1]
ranking2.append(i)
ans = 0
maxi = 0
for x in ranking2:
ans = 0
for i in range(m):
ans += x[i]
maxi = max(maxi,ans)
print(maxi)n,m = [int(i) for i in input().split()]
cakes = []
ranking = [[] for i in range(8)]
ranking2 = []
for i in range(n):
cakes.append(list(map(int,input().split())))
a = 0
for i in range(2):
for j in range(2):
for k in range(2):
for x in range(n):
kirei = cakes[x][0]
oisii = cakes[x][1]
ninki = cakes[x][2]
if i ==1:
kirei = (-1)*kirei
if j ==1:
oisii = (-1) * oisii
if k==1:
ninki = (-1)*ninki
sum = kirei + oisii + ninki
ranking[a].append(sum)
a += 1
for i in ranking:
i = sorted(i)
i = i[::-1]
ranking2.append(i)
ans = 0
maxi = 0
for x in ranking2:
ans = 0
for i in range(m):
ans += x[i]
maxi = max(maxi,ans)
print(maxi)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s867240263
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
N, M = [int(elem) for elem in input().split(" ")]
coord_list = [[int(elem) for elem in input().split(" ")] for _ in range(N)]
assert len(coord_list) == N
assert len(coord_list[0]) == 3
def search_max(sorted_coord_list, M, key):
len_list = len(sorted_coord_list)
if M == len_list:
total_x, total_y, total_z = 0, 0, 0
for x, y, z in sorted_coord_list:
total_x += x
total_y += y
total_z += z
total = abs(total_x) + abs(total_y) + abs(total_z)
return total
elif M == 1:
x, y, z = sorted_coord_list[0]
total = abs(x) + abs(y) + abs(z)
return total
# 2 <= M < N
else:
if sorted_coord_list[M - 1][key] == sorted_coord_list[M][key]:
considering_val = coord_list[M - 1][key]
current_idx = M - 1
candidate_list = list()
while coord_list[current_idx][key] == considering_val:
candidate_list.append(sorted_coord_list[current_idx])
current_idx += 1
if current_idx == len_list:
break
total_x, total_y, total_z = 0, 0, 0
for x, y, z in sorted_coord_list[: M - 1]:
total_x += x
total_y += y
total_z += z
max_total = 0
for x, y, z in candidate_list:
total = abs(total_x + x) + abs(total_y + y) + abs(total_z + z)
max_total = max(max_total, total)
return max_total
else:
total_x, total_y, total_z = 0, 0, 0
for x, y, z in sorted_coord_list[:M]:
total_x += x
total_y += y
total_z += z
total = abs(total_x) + abs(total_y) + abs(total_z)
return total
max_candidates = [0] * 6
for i in range(3):
# sort coord_list: O(NlogN)
sorted_coord_list = sorted(coord_list, key=lambda x: x[i])
max_candidates[2 * i] = search_max(sorted_coord_list, M, i)
max_candidates[2 * i + 1] = search_max(sorted_coord_list[::-1], M, i)
print(max(max_candidates))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s012438644
|
Accepted
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
s = input().split()
n, m = int(s[0]), int(s[1])
arr = [[], [], [], [], [], [], [], []]
for i in range(n):
s = input().split()
x, y, z = int(s[0]), int(s[1]), int(s[2])
arr[0].append(x + y + z)
arr[1].append(x + y - z)
arr[2].append(x - y + z)
arr[3].append(x - y - z)
arr[4].append(-x + y + z)
arr[5].append(-x + y - z)
arr[6].append(-x - y + z)
arr[7].append(-x - y - z)
for i in range(8):
arr[i].sort(reverse=True)
print(max([sum(arr[i][:m]) for i in range(8)]))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s061477500
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
n, m = map(int, input().split())
bs = []
ds = []
ps = []
abs_max = 0
abs_max_index = 0
for ni in range(n):
i, j, k = map(int, input().split())
bs += [i]
ds += [j]
ps += [k]
a = abs(i) + abs(j) + abs(k)
if abs_max < a:
abs_max = a
abs_max_index = ni
signs = [[-1, 1][vs[abs_max_index] >= 0] for vs in [bs, ds, ps]]
signed_sum = []
for b, d, p in zip(bs, ds, ps):
tmp = 0
for sign, v in zip(signs, [b, d, p]):
tmp += sign * v
signed_sum += [tmp]
sum(sorted(signed_sum)[-m:])
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s827136124
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import itertools
n, m = map(int, input().split())
hyoka = [""] * n
for i in range(n):
hyoka[i] = input().split()
for i in range(n):
hyoka[i] = [int(s) for s in hyoka[i]]
hyou = [""]
for iroiro in list(itertools.combination(hyoka, m)):
sum_1 = sum[beau[1] for beau in iroiro]
sum_1 = abs(sum_1)
sum_2 = sum[beau[2] for beau in iroiro]
sum_2 = abs(sum_2)
sum_3 = sum[beau[3] for beau in iroiro]
sum_3 = abs(sum_3)
som = sum_1 + sum_2 + sum_3
hyou = hyou.append(som)
print(max(hyou))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s373828329
|
Wrong Answer
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
def abs_sum(w, m):
tmpx = 0
tmpy = 0
tmpz = 0
for i in range(m):
tmpx += w[i][0]
tmpy += w[i][1]
tmpz += w[i][2]
return abs(tmpx) + abs(tmpy) + abs(tmpz)
n, m = map(int, input().split())
w = [list(map(int, input().split())) for _ in range(n)]
w.sort(key=lambda x: x[0])
ans = max(abs_sum(w, m), abs_sum(w[::-1], m))
w.sort(key=lambda x: x[1])
ans = max(ans, abs_sum(w, m))
ans = max(ans, abs_sum(w[::-1], m))
w.sort(key=lambda x: x[2])
ans = max(ans, abs_sum(w, m))
ans = max(ans, abs_sum(w[::-1], m))
print(ans)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s103015459
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
, M = list(map(int, input().split()))
cakes = []
for _ in range(N):
cakes.append(list(map(int, input().split())))
memo = dict()
def pick_cake(picked):
key = ','.join([str(p) for p in sorted(picked)])
if key in memo:
return memo[key]
if len(picked) == M:
memo[key] = sum([abs(sum([cakes[i][j] for i in picked])) for j in range(3)])
return memo[key]
answer = 0
for i in range(N):
if i in picked:
continue
answer = max(answer, pick_cake(picked + [i]))
return answer
print(pick_cake([]))
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s859209295
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
import functools # Python3
N,M = map(int,input().split())
x, y, z = [0] * N, [0] * N, [0] * N
for i in range(N):
x[i], y[i], z[i] = map(int,input().split())
ppp = sorted([ x[i]+y[i]+z[i] for i in range(N)])[-M:]
pmp = sorted([ x[i]-y[i]+z[i] for i in range(N)])[-M:]
ppm = sorted([ x[i]+y[i]-z[i] for i in range(N)])[-M:]
pmm = sorted([ x[i]-y[i]-z[i] for i in range(N)])[-M:]
mpp = sorted([-x[i]+y[i]+z[i] for i in range(N)])[-M:]
mpm = sorted([-x[i]+y[i]-z[i] for i in range(N)])[-M:]
mmp = sorted([-x[i]-y[i]+z[i] for i in range(N)])[-M:]
mmm = sorted([-x[i]-y[i]-z[i] for i in range(N)])[-M:]
MAX = 0
for lis in [ppp,pmp,ppm,pmm,mpp,mpm,mmp,mmm]:
cur = functools.reduce(lambda x,y: x+y,lis)
MAX = cur
print(MAX)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
* * *
|
s196161243
|
Runtime Error
|
p03326
|
Input is given from Standard Input in the following format:
N M
x_1 y_1 z_1
x_2 y_2 z_2
: :
x_N y_N z_N
|
N,M=map(int,input().split())
cake=[list(map(int,input().split())) for _ in range(N)]
ans=0
if M=0:
print(ans)
exit()
for i in range(1<<3):
point=[0]*N
for j in range(N):
for k in range(3):
point[j]+=(-1+(i>>k & 1)*2)*cake[j][k]
point.sort()
ans=max(ans,sum(point[-M:]))
print(ans)
|
Statement
Takahashi became a pastry chef and opened a shop _La Confiserie d'ABC_ to
celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.
Each kind of cake has three parameters "beauty", "tastiness" and "popularity".
The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the
popularity of z_i.
These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of
cakes as follows:
* Do not have two or more pieces of the same kind of cake.
* Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) +
(the absolute value of the total tastiness) + (the absolute value of the total
popularity) for the set of cakes that Ringo chooses.
|
[{"input": "5 3\n 3 1 4\n 1 5 9\n 2 6 5\n 3 5 8\n 9 7 9", "output": "56\n \n\nConsider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 3 + 9 = 13\n * Tastiness: 5 + 5 + 7 = 17\n * Popularity: 9 + 8 + 9 = 26\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 13\n+ 17 + 26 = 56. This is the maximum value.\n\n* * *"}, {"input": "5 3\n 1 -2 3\n -4 5 -6\n 7 -8 -9\n -10 11 -12\n 13 -14 15", "output": "54\n \n\nConsider having the 1-st, 3-rd and 5-th kinds of cakes. The total beauty,\ntastiness and popularity will be as follows:\n\n * Beauty: 1 + 7 + 13 = 21\n * Tastiness: (-2) + (-8) + (-14) = -24\n * Popularity: 3 + (-9) + 15 = 9\n\nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is 21\n+ 24 + 9 = 54. This is the maximum value.\n\n* * *"}, {"input": "10 5\n 10 -80 21\n 23 8 38\n -94 28 11\n -26 -2 18\n -69 72 79\n -26 -86 -54\n -72 -50 59\n 21 65 -32\n 40 -94 87\n -62 18 82", "output": "638\n \n\nIf we have the 3-rd, 4-th, 5-th, 7-th and 10-th kinds of cakes, the total\nbeauty, tastiness and popularity will be -323, 66 and 249, respectively. \nThe value (the absolute value of the total beauty) + (the absolute value of\nthe total tastiness) + (the absolute value of the total popularity) here is\n323 + 66 + 249 = 638. This is the maximum value.\n\n* * *"}, {"input": "3 2\n 2000000000 -9000000000 4000000000\n 7000000000 -5000000000 3000000000\n 6000000000 -1000000000 8000000000", "output": "30000000000\n \n\nThe values of the beauty, tastiness and popularity of the cakes and the value\nto be printed may not fit into 32-bit integers."}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s809992469
|
Wrong Answer
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
import collections as c
import copy
import math
n, a, b = map(int, input().split())
v0 = list(map(int, input().split()))
v = sorted(c.Counter(v0).items(), key=lambda x: -x[0])
v1 = copy.deepcopy(v)
v2 = copy.deepcopy(v)
avg1, avg2, a1, b1, w1, w2 = (
0,
0,
a,
b,
{},
{},
)
while a:
for i in range(len(v1)):
for j in range(v1[i][1]):
avg1 += v1[i][0]
if v1[i][0] in w1:
w1[v1[i][0]] += 1
else:
w1[v1[i][0]] = 1
a -= 1
if a == 0:
break
if a == 0:
break
avg1 = avg1 / a1
while b:
for i in range(len(v2)):
for j in range(v2[i][1]):
avg2 += v2[i][0]
if v2[i][0] in w2:
w2[v2[i][0]] += 1
else:
w2[v2[i][0]] = 1
b -= 1
if b == 0:
break
if b == 0:
break
avg2 = avg2 / b1
n1, n2 = [], []
for i, j in w1.items():
t = v0.count(i)
if t == j:
n1.append(1)
else:
n1.append(math.factorial(t) // (math.factorial(j) * math.factorial(t - j)))
for i, j in w2.items():
t = v0.count(i)
if t == j:
n2.append(1)
else:
n2.append(math.factorial(t) // (math.factorial(j) * math.factorial(t - j)))
result = max(avg1, avg2)
print(result)
print([max(n2), max(n1)][result == avg1])
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s333147633
|
Accepted
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range
def Golf():
n, *t = map(int, open(0).read().split())
def I():
return int(input())
def S_():
return input()
def IS():
return input().split()
def LS():
return [i for i in input().split()]
def MI():
return map(int, input().split())
def LI():
return [int(i) for i in input().split()]
def LI_():
return [int(i) - 1 for i in input().split()]
def NI(n):
return [int(input()) for i in range(n)]
def NI_(n):
return [int(input()) - 1 for i in range(n)]
def StoLI():
return [ord(i) - 97 for i in input()]
def ItoS(n):
return chr(n + 97)
def LtoS(ls):
return "".join([chr(i + 97) for i in ls])
def RA():
return map(int, open(0).read().split())
def GI(V, E, ls=None, Directed=False, index=1):
org_inp = []
g = [[] for i in range(V)]
FromStdin = True if ls == None else False
for i in range(E):
if FromStdin:
inp = LI()
org_inp.append(inp)
else:
inp = ls[i]
if len(inp) == 2:
a, b = inp
c = 1
else:
a, b, c = inp
if index == 1:
a -= 1
b -= 1
aa = (a, c)
bb = (b, c)
g[a].append(bb)
if not Directed:
g[b].append(aa)
return g, org_inp
def GGI(
h, w, search=None, replacement_of_found=".", mp_def={"#": 1, ".": 0}, boundary=1
):
# h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
mp = [boundary] * (w + 2)
found = {}
for i in R(h):
s = input()
for char in search:
if char in s:
found[char] = (i + 1) * (w + 2) + s.index(char) + 1
mp_def[char] = mp_def[replacement_of_found]
mp += [boundary] + [mp_def[j] for j in s] + [boundary]
mp += [boundary] * (w + 2)
return h + 2, w + 2, mp, found
def TI(n):
return GI(n, n - 1)
def accum(ls):
rt = [0]
for i in ls:
rt += [rt[-1] + i]
return rt
def bit_combination(n, base=2):
rt = []
for tb in R(base**n):
s = [tb // (base**bt) % base for bt in R(n)]
rt += [s]
return rt
def gcd(x, y):
if y == 0:
return x
if x % y == 0:
return y
while x % y != 0:
x, y = y, x % y
return y
def YN(x):
print(["NO", "YES"][x])
def Yn(x):
print(["No", "Yes"][x])
def show(*inp, end="\n"):
if show_flg:
print(*inp, end=end)
# mo=10**9+7
mo = 2305843009213693951
inf = float("inf")
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip("WENS", FourNb))
cursol = dict(zip("LRUD", FourNb))
l_alp = string.ascii_lowercase
# sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda: sys.stdin.readline().rstrip()
########################################################################################################################################################################
class Comb:
def __init__(self, n, mo=2305843009213693951):
self.fac = [0] * (n + 1)
self.inv = [1] * (n + 1)
self.fac[0] = 1
self.fact(n)
for i in range(1, n + 1):
self.fac[i] = i * self.fac[i - 1] % mo
self.inv[n] *= i
self.inv[n] %= mo
self.inv[n] = pow(self.inv[n], mo - 2, mo)
for i in range(1, n):
self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo
return
def fact(self, n):
return self.fac[n]
def invf(self, n):
return self.inv[n]
def comb(self, x, y):
if y < 0 or y > x:
return 0
return self.fac[x] * self.inv[x - y] * self.inv[y] % mo
show_flg = False
show_flg = True
ans = 0
F = [1]
for i in range(110):
F += (F[i] * -~i,)
C = lambda A, B: (A >= B >= 0) * F[A] // F[A - B] // F[B]
n, a, b = LI()
v = LI()
v = sorted(v)[::-1]
print(sum(v[:a]) / a)
m = v[a - 1]
x = v[:a].count(m)
y = v[a:].count(m)
ans = 1
if x != a:
ans = C(x + y, x)
print(ans)
else:
ans = 0
for i in range(a, min(b, x + y) + 1):
ans += C(x + y, i)
print(ans)
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s557485618
|
Runtime Error
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
signed main() {
int n, a, b;
cin >> n >> a >> b;
double v[n];
map<double, int, greater<double>> mp;
rep (i, 0, n) {
cin >> v[i];
mp[v[i]]++;
}
int cnt = 0;
double sum = 0;
ll ans = 1;
double ave = 0;
for (auto p : mp) {
if (cnt + p.second < a) {
sum += p.second * p.first;
cnt += p.second;
} else if (a <= cnt + p.second) {
if (cnt == 0) {
ans=0;
rep(k,A,min(B,p.second)+1){
ll tmp=1;
rep (i, 1, p.second + 1) tmp *= i;
rep (i, 1, k + 1) tmp /= i;
rep (i, 1, p.second - k + 1) tmp /= i;
ans+=tmp;
}
ave = p.first;
} else {
int cnt2 = a - cnt;
rep (i, 1, p.second + 1) ans *= i;
rep (i, 1, cnt2 + 1) ans /= i;
rep (i, 1, p.second - cnt2 + 1) ans /= i;
ave = (sum + cnt2 * p.first) / a;
}
break;
}
}
cout << fixed << setprecision (15) << ave << "\n" << ans << "\n";
}
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s763780935
|
Accepted
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate
def read_ints():
return list(map(int, read().split()))
def read_a_int():
return int(read())
def read_tuple(H):
"""
H is number of rows
"""
ret = []
for _ in range(H):
ret.append(tuple(map(int, read().split())))
return ret
def read_col(H):
"""
H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合
"""
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return tuple(map(list, zip(*ret)))
def read_matrix(H):
"""
H is number of rows
"""
ret = []
for _ in range(H):
ret.append(list(map(int, read().split())))
return ret
# return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため
def combination_mod(n, r):
# mod取りながらcombination
if r > n:
return 0 # このような通りの数は無いため便宜上こう定義する
r = min(r, n - r)
nf = rf = 1
for i in range(r):
nf = nf * (n - i)
rf = rf * (i + 1)
return nf // rf
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
# https://atcoder.jp/contests/abc057/tasks/abc057_d
# ソートしておけば、平均の最大化は簡単 (上位A個選べばよい)
# 通りの数は?
# もし単調増加なら必ず1通り
# 平均の最大化が変わらないとは...?
# 大きい方からA個目の数(cとする)が複数ある場合は別のを選らべる(通りが増える)
# 具体的にはn_c C rの通りの数が存在する(rは上位A個の中に存在するcの数)
# 三種類の場合があるな
# 単調増加のときは簡単
N, A, B = read_ints()
V = read_ints()
V.sort(reverse=True)
V_A = V[:A]
ans1 = sum(V_A) / A
# 単調増加の場合
if V[A] != V[A - 1]:
print(ans1)
print(1)
exit()
# A個選ぶのが最適の場合
if V_A[0] != V_A[-1]:
c = V_A[-1]
n_c = V.count(c)
r = V_A.count(c)
# print(n_c, r)
ans2 = combination_mod(n_c, r)
print(ans1)
print(ans2)
exit()
# 全部同じ場合
n_same = V.count(V[0])
if n_same > A:
ans2 = 0
r_max = min(n_same, B) # 最大これだけ選べる
for i in ra(A, r_max + 1):
ans2 += combination_mod(n_same, i)
print(ans1)
print(ans2)
exit()
raise ValueError("CE出てほしい")
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s466126951
|
Runtime Error
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
import sys
from collections import deque
import math
import numpy as np
def main():
def perm(n, r):
return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
input = sys.stdin.readline
N, A, B = map(int, input().split())
d = [0] * N
q = []
d[:] = map(int, input().split())
dic = {}
dic_d = {}
k = 0
d.sort(reverse=True)
s = sum(d[:A])
m = s / A
for i in set(d):
dic_d[i] = d.count(i)
print(m)
for i in set(d):
l = len(q)
if l > 0:
for j in range(l):
for h in range(len(dic[q[j]])):
if dic[q[j]][h][0] >= B:
break
s = q[j] * dic[q[j]][h][0] + i
ave = s / (dic[q[j]][h][0] + 1)
if not ave in q:
dic[ave] = []
q.append(ave)
dic[ave].append(
[dic[q[j]][h][0] + 1, dic[q[j]][h][1]]
) # [j]][g][1]] for g in range(len(dic[q[j]]))]
elif ave in q:
for g in range(len(dic[q[j]])):
ave_j = np.array(dic[ave])
if not dic[q[j]][g][0] + 1 in ave_j[:, 0]:
dic[ave].append([dic[q[j]][h][0] + 1, dic[q[j]][h][1]])
else:
for f in range(len(dic[ave])):
if dic[ave][f][0] == dic[q[j]][g][0] + 1:
dic[ave][f][1] += 1
if not i in q:
q.append(i)
dic[i] = []
for h in range(1, dic_d[i] + 1):
dic[i].append([h, int(perm(dic_d[i], h))])
elif i in q:
for h in range(1, dic_d[i] + 1):
if dic[i][h][0] <= dic_d[i]:
dic[i][h][1] += perm(dic_d[i], dic[i][h][0])
else:
dic[i].append([h, perm(dic_d[i], h)])
ave_np = np.array(dic[m])
for i in range(len(dic[m])):
if ave_np[i, 0] <= B:
ave_count = sum(ave_np[: i + 1, 1])
print(ave_count)
if __name__ == "__main__":
main()
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s311805688
|
Runtime Error
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
import sys
import math
import collections
import itertools
import array
import inspect
from scipy.special import comb
# Set max recursion limit
sys.setrecursionlimit(1000000)
# Debug output
def chkprint(*args):
names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
print(", ".join(names.get(id(arg), "???") + " = " + repr(arg) for arg in args))
# Binary converter
def to_bin(x):
return bin(x)[2:]
def li_input():
return [int(_) for _ in input().split()]
def gcd(n, m):
if n % m == 0:
return m
else:
return gcd(m, n % m)
def gcd_list(L):
v = L[0]
for i in range(1, len(L)):
v = gcd(v, L[i])
return v
def lcm(n, m):
return (n * m) // gcd(n, m)
def lcm_list(L):
v = L[0]
for i in range(1, len(L)):
v = lcm(v, L[i])
return v
# Width First Search (+ Distance)
def wfs_d(D, N, K):
"""
D: 隣接行列(距離付き)
N: ノード数
K: 始点ノード
"""
dfk = [-1] * (N + 1)
dfk[K] = 0
cps = [(K, 0)]
r = [False] * (N + 1)
r[K] = True
while len(cps) != 0:
n_cps = []
for cp, cd in cps:
for i, dfcp in enumerate(D[cp]):
if dfcp != -1 and not r[i]:
dfk[i] = cd + dfcp
n_cps.append((i, cd + dfcp))
r[i] = True
cps = n_cps[:]
return dfk
# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
"""
v: 現在のノード
pre: 1つ前のノード
dist: 現在の距離
以下は別途用意する
D: 隣接リスト(行列ではない)
D_dfs_d: dfs_d関数で用いる,始点ノードから見た距離リスト
"""
global D
global D_dfs_d
D_dfs_d[v] = dist
for next_v, d in D[v]:
if next_v != pre:
dfs_d(next_v, v, dist + d)
return
def sigma(N):
ans = 0
for i in range(1, N + 1):
ans += i
return ans
class Combination:
def __init__(self, n, mod=10**100):
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range(2, n + 1):
g1.append((g1[-1] * i) % mod)
inverse.append((-inverse[mod % i] * (mod // i)) % mod)
g2.append((g2[-1] * inverse[-1]) % mod)
self.MOD = mod
self.N = n
self.g1 = g1
self.g2 = g2
self.inverse = inverse
def __call__(self, n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD
# --------------------------------------------
dp = None
def main():
N, A, B = li_input()
V = li_input()
V.sort(reverse=True)
maxavg = sum(V[:A]) / A
V_ = V[:A]
if V_[0] == V_[-1]:
n = V.count(V_[0])
ans = 0
for r in range(A, min(n + 1, B + 1)):
ans += comb(n, r)
print(maxavg)
print(int(ans))
else:
n = V.count(V_[-1])
r = V_.count(V_[-1])
ans = comb(n, r)
print(maxavg)
print(int(ans))
main()
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s068756627
|
Accepted
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
N, A, B = map(int, input().split())
v = list(map(int, input().split()))
dp = [[-1 for _ in range(N + 1)] for _ in range(N + 1)]
cnt = [[0 for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0] = 0
cnt[0][0] = 1
for i in range(N):
for j in range(N - 1, -1, -1):
if dp[i][j] == -1:
continue
dp[i + 1][j] = dp[i][j]
cnt[i + 1][j] = cnt[i][j]
ncost = dp[i][j] + v[i]
if dp[i + 1][j + 1] < ncost:
dp[i + 1][j + 1] = ncost
cnt[i + 1][j + 1] = cnt[i][j]
elif dp[i + 1][j + 1] == ncost:
cnt[i + 1][j + 1] += cnt[i][j]
maxVal = 0
maxCnt = 0
for i in range(A, B + 1):
if maxVal < dp[N][i] / i:
maxVal = dp[N][i] / i
maxCnt = cnt[N][i]
elif maxVal == dp[N][i] / i:
maxCnt += cnt[N][i]
print(maxVal)
print(maxCnt)
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s336205526
|
Wrong Answer
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in range(n + 1)]
d = [[0] * (n + 1) for _ in range(n + 1)]
d[0][0] = 1
for i in range(n):
for j in range(i + 1):
if dp[i + 1][j] < dp[i][j]:
d[i + 1][j] = d[i][j]
dp[i + 1][j] = dp[i][j]
elif dp[i + 1][j] == dp[i][j]:
d[i + 1][j] += d[i][j]
if dp[i + 1][j + 1] < dp[i][j] + v[i]:
d[i + 1][j + 1] = d[i][j]
dp[i + 1][j + 1] = dp[i][j] + v[i]
elif dp[i + 1][j + 1] == dp[i][j] + v[i]:
d[i + 1][j + 1] += d[i][j]
ans = 0
idx = 0
cnt = 0
for i in range(a, b + 1):
if dp[n][i] > ans * i:
ans = dp[n][i]
idx = i
cnt = d[n][i]
elif dp[n][i] == ans * i:
cnt += d[n][i]
print(ans / idx)
print(cnt)
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s120563290
|
Wrong Answer
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
n, a, b = map(int, input().split())
data = sorted(map(int, input().split()), reverse=True)
s = sum(data[:a])
k = a
r = 1
if a < n and data[a - 1] == data[a]:
last = data[a]
p = sum(map(lambda x: x == last, data[:a]))
q = sum(map(lambda x: x == last, data[a : b + 1]))
for i in range(p):
r *= p + q - i
r //= i + 1
print(s / k)
print(r)
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s436311035
|
Accepted
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
N, A, B = map(int, input().split())
L = list(map(int, input().split()))
num = [0 for x in range(N)]
total = [0 for x in range(N)]
for i, v in enumerate(L):
for j in reversed(range(1, i + 1)):
new_v = total[j - 1] + v
if new_v > total[j]:
total[j] = new_v
num[j] = num[j - 1]
elif new_v == total[j]:
num[j] = num[j] + num[j - 1]
if v > total[0]:
total[0] = v
num[0] = 1
elif v == total[0]:
num[0] = num[0] + 1
total = [x / (i + 1) for i, x in enumerate(total)]
total = total[(A - 1) : B]
num = num[(A - 1) : B]
maxV = max(total)
maxNum = sum([j for i, j in zip(total, num) if i == maxV])
print(maxV)
print(maxNum)
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s244880329
|
Accepted
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
X.sort(reverse=True)
M = sum(X[i] for i in range(A)) / A
print(M)
cntl, cntr = 0, 0
if X[A - 1] == X[N - 1]:
cntr = N - A
else:
cntr = A - 1
while X[A - 1] == X[cntr]:
cntr += 1
cntr -= A
if X[0] == X[A - 1]:
cntl = A
else:
cntl = A - 1
while X[A - 1] == X[cntl]:
cntl -= 1
cntl = A - 1 - cntl
F = 0
c = cntl + cntr
if cntl == A:
t = 1
for m in range(A):
t *= c - m
t //= m + 1
for m in range(A, min(B, c) + 1):
F += t
t *= c - m
t //= m + 1
print(F)
else:
# calc comb(cntl + cntr, cntl)
t = 1
for m in range(cntl):
t *= c - m
t //= m + 1
F = t
print(F)
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print two lines.
The first line should contain the maximum possible arithmetic mean of the
values of selected items. The output should be considered correct if the
absolute or relative error is at most 10^{-6}.
The second line should contain the number of ways to select items so that the
mean of the values of selected items is maximized.
* * *
|
s824986801
|
Runtime Error
|
p03776
|
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N
|
from math import factorial
n, a, b = map(int, input().split())
v = list(map(int, input().split()))
v.sort(reverse=True)
n1 = v.count(v[a - 1])
n2 = v[:a].count(v[:a][a - 1])
print(sum(v[:a]) / a)
if len(set(v[:a])) != 1:
if n1 == n2:
print(1)
else:
print(int(factorial(n1) / (factorial(n2) * factorial(n1 - n2))))
else:
ans = 0
if n1 == 1:
print(1)
else:
for i in range(a, min(n1, b + 1)):
if
ans += int(factorial(n1) / (factorial(i) * factorial(n1 - i)))
print(int(ans))
|
Statement
You are given N items.
The _value_ of the i-th item (1 \leq i \leq N) is v_i.
Your have to select at least A and at most B of these items.
Under this condition, find the maximum possible arithmetic mean of the values
of selected items.
Additionally, find the number of ways to select items so that the mean of the
values of selected items is maximized.
|
[{"input": "5 2 2\n 1 2 3 4 5", "output": "4.500000\n 1\n \n\nThe mean of the values of selected items will be maximized when selecting the\nfourth and fifth items. Hence, the first line of the output should contain\n4.5. \nThere is no other way to select items so that the mean of the values will be\n4.5, and thus the second line of the output should contain 1.\n\n* * *"}, {"input": "4 2 3\n 10 20 10 10", "output": "15.000000\n 3\n \n\nThere can be multiple ways to select items so that the mean of the values will\nbe maximized.\n\n* * *"}, {"input": "5 1 5\n 1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996", "output": "1000000000000000.000000\n 1"}]
|
Print the minimum number of operations required.
* * *
|
s143157379
|
Runtime Error
|
p02864
|
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
|
N, K = map(int, input().split())
H = list(map(int, input().split()))
HSorted = sorted(H)
HIndexToHeight = []
HHeightToIndex = {}
for i in range(N):
if i != 0 and HSorted[i] == HSorted[i - 1]:
continue
HIndexToHeight.append(HSorted[i])
HHeightToIndex[HSorted[i]] = len(HIndexToHeight) - 1
INF = 10**12
heightCount = len(HIndexToHeight)
DP = []
for i in range(N):
DP.append([])
for j in range(K + 1):
DP[i].append([])
for k in range(heightCount):
DP[i][j].append(INF)
for k in range(heightCount):
if k == HHeightToIndex[H[0]]:
DP[0][0][k] = H[0]
else:
DP[0][1][k] = HIndexToHeight[k]
for i in range(1, N):
currentHeight = HHeightToIndex[H[i]]
for j in range(K + 1):
for k in range(heightCount):
if currentHeight > k:
if j > 0:
DP[i][j][k] = min(DP[i - 1][j - 1][k], DP[i][j][k])
DP[i][j][currentHeight] = min(
DP[i - 1][j][k] + HIndexToHeight[currentHeight] - HIndexToHeight[k],
DP[i][j][currentHeight],
)
elif currentHeight == k:
DP[i][j][currentHeight] = min(DP[i - 1][j][k], DP[i][j][currentHeight])
else:
if j > 0:
DP[i][j][k] = min(DP[i - 1][j - 1][k], DP[i][j][k])
DP[i][j][currentHeight] = min(DP[i - 1][j][k], DP[i][j][currentHeight])
ans = INF
for j in range(K + 1):
for k in range(heightCount):
if ans > DP[N - 1][j][k]:
ans = DP[N - 1][j][k]
print(ans)
|
Statement
We will create an artwork by painting black some squares in a white square
grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will
paint the H_i bottommost squares and will not paint the other squares in that
column.
Before starting to work, you can choose at most K columns (possibly zero) and
change the values of H_i for these columns to any integers of your choice
between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following
operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
|
[{"input": "4 1\n 2 3 4 1", "output": "3\n \n\nFor example, by changing the value of H_3 to 2, you can create the modified\nartwork by the following three operations:\n\n * Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n * Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n * Paint black the 2-nd square from the left in the 3-rd row from the bottom.\n\n* * *"}, {"input": "6 2\n 8 6 9 1 2 1", "output": "7\n \n\n* * *"}, {"input": "10 0\n 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "output": "4999999996"}]
|
Print the minimum number of operations required.
* * *
|
s069808045
|
Accepted
|
p02864
|
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
|
N, K = map(int, input().split())
H = [0] + list(map(int, input().split())) + [0]
dp = [[0] * (K + 2) for i in [0] * (N + 2)]
for i in range(1, N + 2):
for j in range(K + 1):
dp[i][j] = min(
[
dp[i - k][j - k + 1] + max(0, H[i] - H[i - k])
for k in range(1, min(j + 1, i) + 1)
]
)
print(dp[N + 1][K])
|
Statement
We will create an artwork by painting black some squares in a white square
grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will
paint the H_i bottommost squares and will not paint the other squares in that
column.
Before starting to work, you can choose at most K columns (possibly zero) and
change the values of H_i for these columns to any integers of your choice
between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following
operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
|
[{"input": "4 1\n 2 3 4 1", "output": "3\n \n\nFor example, by changing the value of H_3 to 2, you can create the modified\nartwork by the following three operations:\n\n * Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n * Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n * Paint black the 2-nd square from the left in the 3-rd row from the bottom.\n\n* * *"}, {"input": "6 2\n 8 6 9 1 2 1", "output": "7\n \n\n* * *"}, {"input": "10 0\n 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "output": "4999999996"}]
|
Print the minimum number of operations required.
* * *
|
s386041064
|
Wrong Answer
|
p02864
|
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
|
n, k = map(int, input().split())
hlist = list(map(int, input().split()))
cost = []
dead = [0] * n
if n != 1:
for i in range(n):
if i == 0:
if hlist[i] >= hlist[i + 1]:
cost.append(hlist[i] - hlist[i + 1])
else:
cost.append(0)
elif i == n - 1:
if hlist[i] >= hlist[i - 1]:
cost.append(hlist[i] - hlist[i - 1])
else:
cost.append(0)
else:
if hlist[i] >= hlist[i - 1] and hlist[i] >= hlist[i + 1]:
cost.append(hlist[i] - max(hlist[i - 1], hlist[i + 1]))
elif hlist[i] <= hlist[i - 1] and hlist[i] <= hlist[i + 1]:
cost.append(min(hlist[i - 1], hlist[i + 1]) - hlist[i])
else:
cost.append(0)
# print(cost)
rest = k
while rest > 0:
bango = cost.index(max(cost))
hlist = hlist[:bango] + hlist[bango + 1 :]
cost = cost[:bango] + cost[bango + 1 :]
if bango == 0:
search = [bango]
elif bango == len(hlist):
search = [bango - 1]
else:
search = [bango - 1, bango]
if len(hlist) >= 2:
for i in search:
if i == 0:
if hlist[i] >= hlist[i + 1]:
cost[i] = hlist[i] - hlist[i + 1]
else:
cost[i] = 0
elif i == len(hlist) - 1:
if hlist[i] >= hlist[i - 1]:
cost[i] = hlist[i] - hlist[i - 1]
else:
cost[i] = 0
else:
if hlist[i] >= hlist[i - 1] and hlist[i] >= hlist[i + 1]:
cost[i] = hlist[i] - max(hlist[i - 1], hlist[i + 1])
elif hlist[i] <= hlist[i - 1] and hlist[i] <= hlist[i + 1]:
cost[i] = min(hlist[i - 1], hlist[i + 1]) - hlist[i]
else:
cost[i] = 0
rest -= 1
else:
if rest > 1:
hlist = [0]
break
else:
break
# print(cost, hlist)
nul = 0
mae = 0
for i in range(len(hlist)):
if hlist[i] >= mae:
nul += hlist[i] - mae
mae = hlist[i]
print(nul)
else:
if k >= 1:
print(0)
else:
print(hlist[0])
|
Statement
We will create an artwork by painting black some squares in a white square
grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will
paint the H_i bottommost squares and will not paint the other squares in that
column.
Before starting to work, you can choose at most K columns (possibly zero) and
change the values of H_i for these columns to any integers of your choice
between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following
operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
|
[{"input": "4 1\n 2 3 4 1", "output": "3\n \n\nFor example, by changing the value of H_3 to 2, you can create the modified\nartwork by the following three operations:\n\n * Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n * Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n * Paint black the 2-nd square from the left in the 3-rd row from the bottom.\n\n* * *"}, {"input": "6 2\n 8 6 9 1 2 1", "output": "7\n \n\n* * *"}, {"input": "10 0\n 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "output": "4999999996"}]
|
Print the minimum number of operations required.
* * *
|
s362772013
|
Wrong Answer
|
p02864
|
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
|
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
A = list(map(int, input().split()))
A += [0, 0]
graph = [[] for _ in range(N + 2)]
for i, a in enumerate(A):
if i == N + 1:
break
r = i + 1
while r != N + 1 and A[r] >= a:
r += 1
l = i - 1
while l != -1 and A[l] > a:
l -= 1
if A[l] == a:
graph[l].append((i, 0))
else:
if A[l] <= A[r]:
graph[r].append((i, a - A[r]))
elif A[l] > A[r]:
graph[l].append((i, a - A[l]))
stack = [N]
Ind = [0] * (N + 1)
dp = [[0] for _ in range(N + 1)]
while stack:
p = stack[-1]
if Ind[p] == len(graph[p]):
stack.pop()
if len(graph[p]) == 0:
continue
elif len(graph[p]) == 1:
ch, w = graph[p][0]
P = dp[ch]
if len(P) < K + 1:
dp[p] = P + [P[-1] + w]
else:
dp[p] = P[:]
else:
ch1, w1 = graph[p][0]
ch2, w2 = graph[p][1]
m = 0
if len(dp[ch1]) < K + 1:
dp[ch1].append(dp[ch1][-1] + w1)
if len(dp[ch2]) < K + 1:
dp[ch2].append(dp[ch2][-1] + w2)
for k in range(1, min(K + 1, len(dp[ch1]) + len(dp[ch2]) - 1)):
for i in range(k + 1):
tmp = 0
if i < len(dp[ch1]):
tmp += dp[ch1][i]
if k - i < len(dp[ch2]):
tmp += dp[ch2][k - i]
m = max(m, tmp)
dp[p].append(m)
elif len(stack) > 1 and stack[-2] == graph[p][Ind[p]][0]:
Ind[p] += 1
else:
stack.append(graph[p][Ind[p]][0])
Ind[p] += 1
ans = 0
for i in range(N + 1):
for _, w in graph[i]:
ans += w
ans -= dp[N][-1]
print(ans)
|
Statement
We will create an artwork by painting black some squares in a white square
grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will
paint the H_i bottommost squares and will not paint the other squares in that
column.
Before starting to work, you can choose at most K columns (possibly zero) and
change the values of H_i for these columns to any integers of your choice
between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following
operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
|
[{"input": "4 1\n 2 3 4 1", "output": "3\n \n\nFor example, by changing the value of H_3 to 2, you can create the modified\nartwork by the following three operations:\n\n * Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n * Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n * Paint black the 2-nd square from the left in the 3-rd row from the bottom.\n\n* * *"}, {"input": "6 2\n 8 6 9 1 2 1", "output": "7\n \n\n* * *"}, {"input": "10 0\n 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "output": "4999999996"}]
|
Print the minimum number of operations required.
* * *
|
s104748518
|
Runtime Error
|
p02864
|
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
|
N, T = map(int, input().split())
x = []
for i in range(N):
Ai, Bi = map(int, input().split())
x.append((Ai, Bi))
x.sort(key=lambda x: (x[1], x[0]))
dp = [
[0 for j in range(T)] for i in range(N)
] # i番目までの料理(最後の料理を含まない)でj分後(<=T-1分後)までに得られる満足度の最大値(単純dp)
# 単純dp
for i in range(N - 1):
for j in range(T):
if x[i][0] > j:
dp[i + 1][j] = dp[i][j]
else:
dp[i + 1][j] = max(dp[i][j], dp[i][j - x[i][0]] + x[i][1])
print(dp[N - 1][T - 1] + x[-1][1])
|
Statement
We will create an artwork by painting black some squares in a white square
grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will
paint the H_i bottommost squares and will not paint the other squares in that
column.
Before starting to work, you can choose at most K columns (possibly zero) and
change the values of H_i for these columns to any integers of your choice
between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following
operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
|
[{"input": "4 1\n 2 3 4 1", "output": "3\n \n\nFor example, by changing the value of H_3 to 2, you can create the modified\nartwork by the following three operations:\n\n * Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n * Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n * Paint black the 2-nd square from the left in the 3-rd row from the bottom.\n\n* * *"}, {"input": "6 2\n 8 6 9 1 2 1", "output": "7\n \n\n* * *"}, {"input": "10 0\n 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "output": "4999999996"}]
|
Print the minimum number of operations required.
* * *
|
s603342750
|
Wrong Answer
|
p02864
|
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
|
x, y = map(int, input().split())
if x == y and x % 3 != 0:
print(0)
else:
if x == (2 * y) or y == (2 * x):
print(1)
else:
if x == y and x % 3 == 0:
print((2 ** (x - 2)) % 1000000007)
else:
m = min(x, y)
n = m - (m % 3)
print((2 ** (n - 2) + (m % 3) + 1) % 1000000007)
|
Statement
We will create an artwork by painting black some squares in a white square
grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will
paint the H_i bottommost squares and will not paint the other squares in that
column.
Before starting to work, you can choose at most K columns (possibly zero) and
change the values of H_i for these columns to any integers of your choice
between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following
operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
|
[{"input": "4 1\n 2 3 4 1", "output": "3\n \n\nFor example, by changing the value of H_3 to 2, you can create the modified\nartwork by the following three operations:\n\n * Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n * Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n * Paint black the 2-nd square from the left in the 3-rd row from the bottom.\n\n* * *"}, {"input": "6 2\n 8 6 9 1 2 1", "output": "7\n \n\n* * *"}, {"input": "10 0\n 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "output": "4999999996"}]
|
Print the minimum number of operations required.
* * *
|
s696046024
|
Wrong Answer
|
p02864
|
Input is given from Standard Input in the following format:
N K
H_1 H_2 ... H_N
|
n, K = map(int, input().split())
l = list(map(int, input().split()))
INF = float("inf")
dp = [[[INF, INF] for j in range(K + 1)] for i in range(n + 1)]
dp[0][0] = [0, 0]
for i, j in enumerate(l, 1):
a1, b1 = dp[i - 1][0]
a1 += max(0, j - b1)
dp[i][0] = [a1, j]
for i, j in enumerate(l, 1):
for k in range(1, min(K + 1, i + 1)):
a1, b1 = dp[i - 1][k]
a1 += max(0, j - b1)
a2, b2 = dp[i - 1][k - 1]
dp[i][k] = sorted([[a1, j], [a2, b2]])[0]
print(dp[-1][-1][0])
|
Statement
We will create an artwork by painting black some squares in a white square
grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will
paint the H_i bottommost squares and will not paint the other squares in that
column.
Before starting to work, you can choose at most K columns (possibly zero) and
change the values of H_i for these columns to any integers of your choice
between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.
Then, you will create the modified artwork by repeating the following
operation:
* Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)
Find the minimum number of times you need to perform this operation.
|
[{"input": "4 1\n 2 3 4 1", "output": "3\n \n\nFor example, by changing the value of H_3 to 2, you can create the modified\nartwork by the following three operations:\n\n * Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.\n * Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.\n * Paint black the 2-nd square from the left in the 3-rd row from the bottom.\n\n* * *"}, {"input": "6 2\n 8 6 9 1 2 1", "output": "7\n \n\n* * *"}, {"input": "10 0\n 1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "output": "4999999996"}]
|
Print the minimum number of study hours required for Takahashi to win.
* * *
|
s033097590
|
Runtime Error
|
p03019
|
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
|
class Kenken:
def __init__(self, n, a, b, c, d, s):
self.n = n
self.a = a - 1
self.b = b - 1
self.c = c - 1
self.d = d - 1
self.s = s
self.s = self.s[: a - 1] + "A" + self.s[a:]
self.s = self.s[: b - 1] + "B" + self.s[b:]
def str_replace(self, i, k, S):
if k == 1:
self.s = self.s[:i] + "." + S + self.s[i + 2 :]
else:
self.s = self.s[:i] + "." + self.s[i + 1] + S + self.s[i + 3 :]
def check_stone(self, i):
if i < self.n:
if self.s[i] == ".":
return True
return False
def check_goal(self):
if self.a == self.c and self.b == self.d:
return False
else:
return True
def left(self, target, i):
if target == "a":
self.str_replace(self.a, i, "A")
self.a += i
else:
self.str_replace(self.b, i, "B")
self.b += i
def get_space(self, S):
if S == "a":
return self.a
elif S == "b":
return self.b
elif S == "c":
return self.c
elif S == "d":
return self.d
def print_all(self):
print(self.s)
n, a, b, c, d = map(int, input().split())
s = input()
ken = Kenken(n, a, b, c, d, s)
flag = 0
ken.print_all()
while ken.check_goal():
if (
ken.check_stone(ken.get_space("b") + 1)
and ken.check_stone(ken.get_space("b") - 1)
) or (
ken.get_space("a") + 1 == ken.get_space("b")
and ken.check_stone(ken.get_space("b") + 1)
):
if ken.check_stone(ken.get_space("a") + 1) and ken.get_space(
"a"
) != ken.get_space("c"):
ken.left("a", 1)
elif ken.check_stone(ken.get_space("a") + 2) and ken.get_space(
"a"
) != ken.get_space("c"):
ken.left("a", 2)
elif ken.check_stone(ken.get_space("b") + 1) and ken.get_space(
"b"
) != ken.get_space("d"):
ken.left("b", 1)
elif ken.check_stone(ken.get_space("b") + 2) and ken.get_space(
"b"
) != ken.get_space("d"):
ken.left("b", 2)
else:
flag = 1
break
else:
if ken.check_stone(ken.get_space("b") + 1) and ken.get_space(
"b"
) != ken.get_space("d"):
ken.left("b", 1)
elif ken.check_stone(ken.get_space("b") + 2) and ken.get_space(
"b"
) != ken.get_space("d"):
ken.left("b", 2)
elif ken.check_stone(ken.get_space("a") + 1) and ken.get_space(
"a"
) != ken.get_space("c"):
ken.left("a", 1)
elif ken.check_stone(ken.get_space("a") + 2) and ken.get_space(
"a"
) != ken.get_space("c"):
ken.left("a", 2)
else:
flag = 1
break
ken.print_all()
if flag == 0:
print("Yes")
else:
print("No")
|
Statement
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to
compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural
power.
Takahashi himself, on the other hand, will score 0 on all the exams without
studying more. For each hour of study, he can increase his score on some exam
by 1. (He can only study for an integer number of hours.) However, **he cannot
score more than X on an exam**, since the perfect score for all the exams is
X.
Print the minimum number of study hours required for Takahashi to win.
|
[{"input": "2 100\n 85 2 3\n 60 1 1", "output": "115\n \n\nOne optimal strategy is as follows:\n\n * Choose c_1 = 3, c_2 = 1.\n\n * Study to score 100 on Exam 1 and 15 on Exam 2.\n\nThen, A = 3 \\times 100 + 1 \\times 15 = 315, B = 3 \\times 85 + 1 \\times 60 =\n315 and Takahashi will win.\n\n* * *"}, {"input": "2 100\n 85 2 3\n 60 10 10", "output": "77\n \n\n* * *"}, {"input": "1 100000\n 31415 2718 2818", "output": "31415\n \n\n* * *"}, {"input": "10 1000\n 451 4593 6263\n 324 310 6991\n 378 1431 7068\n 71 1757 9218\n 204 3676 4328\n 840 6221 9080\n 684 1545 8511\n 709 5467 8674\n 862 6504 9835\n 283 4965 9980", "output": "2540"}]
|
Print the minimum number of study hours required for Takahashi to win.
* * *
|
s268069190
|
Wrong Answer
|
p03019
|
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
|
print("わからない")
|
Statement
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to
compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural
power.
Takahashi himself, on the other hand, will score 0 on all the exams without
studying more. For each hour of study, he can increase his score on some exam
by 1. (He can only study for an integer number of hours.) However, **he cannot
score more than X on an exam**, since the perfect score for all the exams is
X.
Print the minimum number of study hours required for Takahashi to win.
|
[{"input": "2 100\n 85 2 3\n 60 1 1", "output": "115\n \n\nOne optimal strategy is as follows:\n\n * Choose c_1 = 3, c_2 = 1.\n\n * Study to score 100 on Exam 1 and 15 on Exam 2.\n\nThen, A = 3 \\times 100 + 1 \\times 15 = 315, B = 3 \\times 85 + 1 \\times 60 =\n315 and Takahashi will win.\n\n* * *"}, {"input": "2 100\n 85 2 3\n 60 10 10", "output": "77\n \n\n* * *"}, {"input": "1 100000\n 31415 2718 2818", "output": "31415\n \n\n* * *"}, {"input": "10 1000\n 451 4593 6263\n 324 310 6991\n 378 1431 7068\n 71 1757 9218\n 204 3676 4328\n 840 6221 9080\n 684 1545 8511\n 709 5467 8674\n 862 6504 9835\n 283 4965 9980", "output": "2540"}]
|
Print the minimum number of study hours required for Takahashi to win.
* * *
|
s157982469
|
Wrong Answer
|
p03019
|
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
|
#!/usr/bin/env python3
import sys
INF = float("inf")
from itertools import accumulate
import heapq
def solve(N: int, X: int, b: "List[int]", l: "List[int]", u: "List[int]"):
# i番目のテストで高橋くんがx点とったとき、A-Bに加える量
def f(i, x):
if x <= b[i]:
return l[i] * (x - b[i])
else:
return u[i] * (x - b[i])
# あらかじめ、0点とった時とX点とった時の効果が大きい順に並べておく
mh = [[f(i, X) - f(i, 0), i] for i in range(N)]
mh.sort(reverse=True)
mX = [f(i, X) for _, i in mh]
mXacc = list(accumulate(mX))
m0 = [f(i, 0) for _, i in mh]
m0acc = list(accumulate(m0))
# print(mh)
# print(mX)
# print(mXacc)
# print(m0)
# print(m0acc)
def isOK(index, key):
# 勉強時間Tとしてスコア(A-B)を最大化するよう勉強時間を配分する
T = index
num = 1 + T // X # 点をとるテストの個数
# print(num)
# いったんX点とらせる
# D = sum([f(i, X) for _, i in mh[:num]])\
# + sum([f(i, 0) for _, i in mh[num:]])
# print(D)
# print("A", mXacc[num-1])
# print("B", m0acc[-1]-m0acc[num-1])
D = mXacc[num - 1] + m0acc[-1] - m0acc[num - 1]
# print(D)
# 点を取るテストの中で、点数をT%X点に変更した時、
# 最も減少の小さいものを選ぶ
a = [0] * N
for _, j in mh[:num]:
a[j] = X
if num != 0:
v, i = min([[f(i, X) - f(i, T % X), i] for _, i in mh[:num]])
D -= v
a[i] = T % X
# print(D)
# print(a)
return D >= key
def binary_search(key):
ng = -1
ok = N * X
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
# print("ng, mid, ok = {}, {}, {}".format(ng, mid, ok))
if isOK(mid, key):
ok = mid
else:
ng = mid
return ok
ans = binary_search(0)
print(ans)
return
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
X = int(next(tokens)) # type: int
b = [int()] * (N) # type: "List[int]"
l = [int()] * (N) # type: "List[int]"
u = [int()] * (N) # type: "List[int]"
for i in range(N):
b[i] = int(next(tokens))
l[i] = int(next(tokens))
u[i] = int(next(tokens))
solve(N, X, b, l, u)
if __name__ == "__main__":
main()
|
Statement
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to
compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural
power.
Takahashi himself, on the other hand, will score 0 on all the exams without
studying more. For each hour of study, he can increase his score on some exam
by 1. (He can only study for an integer number of hours.) However, **he cannot
score more than X on an exam**, since the perfect score for all the exams is
X.
Print the minimum number of study hours required for Takahashi to win.
|
[{"input": "2 100\n 85 2 3\n 60 1 1", "output": "115\n \n\nOne optimal strategy is as follows:\n\n * Choose c_1 = 3, c_2 = 1.\n\n * Study to score 100 on Exam 1 and 15 on Exam 2.\n\nThen, A = 3 \\times 100 + 1 \\times 15 = 315, B = 3 \\times 85 + 1 \\times 60 =\n315 and Takahashi will win.\n\n* * *"}, {"input": "2 100\n 85 2 3\n 60 10 10", "output": "77\n \n\n* * *"}, {"input": "1 100000\n 31415 2718 2818", "output": "31415\n \n\n* * *"}, {"input": "10 1000\n 451 4593 6263\n 324 310 6991\n 378 1431 7068\n 71 1757 9218\n 204 3676 4328\n 840 6221 9080\n 684 1545 8511\n 709 5467 8674\n 862 6504 9835\n 283 4965 9980", "output": "2540"}]
|
Print the minimum number of study hours required for Takahashi to win.
* * *
|
s147608356
|
Wrong Answer
|
p03019
|
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
|
from math import ceil
n, x = map(int, input().split())
# v = list(map(int,input().split()))
tlist = []
for i in range(n):
b, l, u = map(int, input().split())
tlist.append([b, l, u, i])
ans = 0
cp = []
# calc コスパ
for i in tlist:
cp.append(i[2] * x - (i[2] - i[1]) * i[0])
leastline = 0
for i in tlist:
leastline += i[0] * i[1]
# tlistをコスパで並び替え
# cptlistord = sorted(range(len(cp)) key=lambda x: cp[x])
cplist = sorted(tlist, key=lambda x: cp[x[3]])[::-1]
# print(cplist)
nowleastline = leastline
lenc = len(cplist)
for _ in range(lenc):
i = cplist[0]
leastline = nowleastline
nowleastline = nowleastline + (i[2] - i[1]) * i[0] - x * i[2]
if nowleastline <= 0:
break
else:
ans += x
del cplist[0]
hokan1 = cplist[0]
tmp1 = ceil((leastline + (hokan1[2] - hokan1[1]) * hokan1[0]) / hokan1[2])
cplist = sorted(cplist, key=lambda x: x[1])[::-1]
hokan2 = cplist[0]
tmp2 = ceil(leastline / hokan2[1])
cplist = sorted(cplist, key=lambda x: x[0])
tmp3 = x
for i in cplist:
if i[0] >= tmp1:
break
tmp3 = min(tmp3, ceil((leastline + (i[2] - i[1]) * i[0]) / i[2]))
# print(ceil((leastline+(hokan1[2] - hokan1[1])*hokan1[0])/hokan1[2]))
# print(ceil(leastline/hokan2[1]))
# ans += min(ceil((leastline+(hokan1[2] - hokan1[1])*hokan1[0])/hokan1[2]),ceil(leastline/hokan2[1]))
ans += min(tmp1, tmp2, tmp3)
print(ans)
|
Statement
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to
compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural
power.
Takahashi himself, on the other hand, will score 0 on all the exams without
studying more. For each hour of study, he can increase his score on some exam
by 1. (He can only study for an integer number of hours.) However, **he cannot
score more than X on an exam**, since the perfect score for all the exams is
X.
Print the minimum number of study hours required for Takahashi to win.
|
[{"input": "2 100\n 85 2 3\n 60 1 1", "output": "115\n \n\nOne optimal strategy is as follows:\n\n * Choose c_1 = 3, c_2 = 1.\n\n * Study to score 100 on Exam 1 and 15 on Exam 2.\n\nThen, A = 3 \\times 100 + 1 \\times 15 = 315, B = 3 \\times 85 + 1 \\times 60 =\n315 and Takahashi will win.\n\n* * *"}, {"input": "2 100\n 85 2 3\n 60 10 10", "output": "77\n \n\n* * *"}, {"input": "1 100000\n 31415 2718 2818", "output": "31415\n \n\n* * *"}, {"input": "10 1000\n 451 4593 6263\n 324 310 6991\n 378 1431 7068\n 71 1757 9218\n 204 3676 4328\n 840 6221 9080\n 684 1545 8511\n 709 5467 8674\n 862 6504 9835\n 283 4965 9980", "output": "2540"}]
|
Print the minimum number of study hours required for Takahashi to win.
* * *
|
s904253778
|
Accepted
|
p03019
|
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
|
from itertools import accumulate
import sys
input = sys.stdin.readline
def solve():
N, X = map(int, input().split())
tests = []
D0 = 0
for _ in range(N):
B, L, U = map(int, input().split())
v = L * B + U * (X - B)
tests.append((v, B, L, U))
D0 -= L * B
tests.sort(reverse=True)
accVs = list(accumulate([0] + tests, lambda accX, X: accX + X[0]))
def isOK(k):
q = k // X
r = k % X
accV = accVs[q + 1]
for v, B, L, U in tests[:q]:
d = D0 + accV - v
if r <= B:
d += L * r
else:
d += L * B + U * (r - B)
if d >= 0:
return True
accV = accVs[q]
for v, B, L, U in tests[q:]:
d = D0 + accV
if r <= B:
d += L * r
else:
d += L * B + U * (r - B)
if d >= 0:
return True
return False
ng, ok = -1, N * X
while abs(ok - ng) > 1:
mid = (ng + ok) // 2
if isOK(mid):
ok = mid
else:
ng = mid
return ok
print(solve())
|
Statement
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to
compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural
power.
Takahashi himself, on the other hand, will score 0 on all the exams without
studying more. For each hour of study, he can increase his score on some exam
by 1. (He can only study for an integer number of hours.) However, **he cannot
score more than X on an exam**, since the perfect score for all the exams is
X.
Print the minimum number of study hours required for Takahashi to win.
|
[{"input": "2 100\n 85 2 3\n 60 1 1", "output": "115\n \n\nOne optimal strategy is as follows:\n\n * Choose c_1 = 3, c_2 = 1.\n\n * Study to score 100 on Exam 1 and 15 on Exam 2.\n\nThen, A = 3 \\times 100 + 1 \\times 15 = 315, B = 3 \\times 85 + 1 \\times 60 =\n315 and Takahashi will win.\n\n* * *"}, {"input": "2 100\n 85 2 3\n 60 10 10", "output": "77\n \n\n* * *"}, {"input": "1 100000\n 31415 2718 2818", "output": "31415\n \n\n* * *"}, {"input": "10 1000\n 451 4593 6263\n 324 310 6991\n 378 1431 7068\n 71 1757 9218\n 204 3676 4328\n 840 6221 9080\n 684 1545 8511\n 709 5467 8674\n 862 6504 9835\n 283 4965 9980", "output": "2540"}]
|
Print the minimum number of study hours required for Takahashi to win.
* * *
|
s176768925
|
Runtime Error
|
p03019
|
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
|
import sys, collections as cl, bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
return list(map(int, input().split()))
def m():
return map(int, input().split())
def s(x):
a = []
aa = x[0]
su = 1
for i in range(len(x) - 1):
if aa != x[i + 1]:
a.append([aa, su])
aa = x[i + 1]
su = 1
else:
su += 1
a.append([aa, su])
return a
def jo(x):
return " ".join(map(str, x))
def binary_search_loop(l):
global su, cp, p, a
arry = list(range(l + 1))
left = 0
right = len(arry) - 1
while left <= right:
mid = (left + right) // 2
print(mid)
if left == right:
return mid
elif arry[mid] < (su - cp) // (p - a[i][0]):
right = mid - 1
else:
left = mid + 1
n, p = m()
a = []
for i in range(n):
a.append(l())
a.sort(reverse=True, key=lambda x: (p - x[0]) * x[2])
su = 0
cp = 0
coun = 0
for i in range(n):
su += a[i][0] * a[i][1]
for i in range(n):
su -= a[i][0] * a[i][1]
if cp + a[i][2] * p == su + a[i][0] * a[i][2]:
coun += p
break
elif cp + a[i][2] * p < su + a[i][0] * a[i][2]:
cp += a[i][2] * p
su += a[i][0] * a[i][2]
coun += p
else:
ppp = binary_search_loop(a[i][2])
print(ppp)
ppp = -(-(su - cp) // (ppp)) + a[i][0]
coun += ppp
break
print(coun)
|
Statement
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to
compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural
power.
Takahashi himself, on the other hand, will score 0 on all the exams without
studying more. For each hour of study, he can increase his score on some exam
by 1. (He can only study for an integer number of hours.) However, **he cannot
score more than X on an exam**, since the perfect score for all the exams is
X.
Print the minimum number of study hours required for Takahashi to win.
|
[{"input": "2 100\n 85 2 3\n 60 1 1", "output": "115\n \n\nOne optimal strategy is as follows:\n\n * Choose c_1 = 3, c_2 = 1.\n\n * Study to score 100 on Exam 1 and 15 on Exam 2.\n\nThen, A = 3 \\times 100 + 1 \\times 15 = 315, B = 3 \\times 85 + 1 \\times 60 =\n315 and Takahashi will win.\n\n* * *"}, {"input": "2 100\n 85 2 3\n 60 10 10", "output": "77\n \n\n* * *"}, {"input": "1 100000\n 31415 2718 2818", "output": "31415\n \n\n* * *"}, {"input": "10 1000\n 451 4593 6263\n 324 310 6991\n 378 1431 7068\n 71 1757 9218\n 204 3676 4328\n 840 6221 9080\n 684 1545 8511\n 709 5467 8674\n 862 6504 9835\n 283 4965 9980", "output": "2540"}]
|
Print the minimum number of study hours required for Takahashi to win.
* * *
|
s127079295
|
Runtime Error
|
p03019
|
Input is given from Standard Input in the following format:
N X
b_1 l_1 u_1
b_2 l_2 u_2
:
b_N l_N u_N
|
def get(list, n):
sum = 0
a = []
for i in range(len(list)):
sum += list[i][0] * list[i][1]
a.append([(n - list[i][0]) * list[i][2], i])
a.sort()
i, z = 0, True
count = 0
a.reverse()
while i < len(a) and z:
sum -= 100 * list[a[i][1]][2]
count += 100
if sum < 0:
z = False
else:
i += 1
sum += 100 * list[a[i][1]][2]
count -= 100
if sum % (list[a[i][1]][2]) == 0:
count += sum // list[a[i][1]][2]
else:
count += sum // (list[a[i][1]][2] + 1)
return count
m = list(map(int, input().strip().split()))
l = []
for i in range(m[0]):
l.append(list(map(int, input().strip().split())))
print(get(l, m[1]))
|
Statement
Takahashi and Aoki will take N exams numbered 1 to N. They have decided to
compete in these exams. The winner will be determined as follows:
* For each exam i, Takahashi decides its _importance_ c_i, which must be an integer between l_i and u_i (inclusive).
* Let A be \sum_{i=1}^{N} c_i \times (Takahashi's score on Exam i), and B be \sum_{i=1}^{N} c_i \times (Aoki's score on Exam i). Takahashi wins if A \geq B, and Aoki wins if A < B.
Takahashi knows that Aoki will score b_i on Exam i, with his supernatural
power.
Takahashi himself, on the other hand, will score 0 on all the exams without
studying more. For each hour of study, he can increase his score on some exam
by 1. (He can only study for an integer number of hours.) However, **he cannot
score more than X on an exam**, since the perfect score for all the exams is
X.
Print the minimum number of study hours required for Takahashi to win.
|
[{"input": "2 100\n 85 2 3\n 60 1 1", "output": "115\n \n\nOne optimal strategy is as follows:\n\n * Choose c_1 = 3, c_2 = 1.\n\n * Study to score 100 on Exam 1 and 15 on Exam 2.\n\nThen, A = 3 \\times 100 + 1 \\times 15 = 315, B = 3 \\times 85 + 1 \\times 60 =\n315 and Takahashi will win.\n\n* * *"}, {"input": "2 100\n 85 2 3\n 60 10 10", "output": "77\n \n\n* * *"}, {"input": "1 100000\n 31415 2718 2818", "output": "31415\n \n\n* * *"}, {"input": "10 1000\n 451 4593 6263\n 324 310 6991\n 378 1431 7068\n 71 1757 9218\n 204 3676 4328\n 840 6221 9080\n 684 1545 8511\n 709 5467 8674\n 862 6504 9835\n 283 4965 9980", "output": "2540"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s495263822
|
Accepted
|
p03449
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
n = int(input())
a_li = list(map(int, input().split()))
b_li = list(map(int, input().split()))
all_li = []
for i, a in enumerate(a_li):
x = sum(a_li[: i + 1])
y = sum(b_li[i:])
all_li.append(x + y)
print(max(all_li))
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s299277235
|
Accepted
|
p03449
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
# -*- coding: utf-8 -*-
#############
# Libraries #
#############
import sys
input = sys.stdin.readline
import math
# from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache
#############
# Constants #
#############
MOD = 10**9 + 7
INF = float("inf")
#############
# Functions #
#############
######INPUT######
def I():
return int(input().strip())
def S():
return input().strip()
def IL():
return list(map(int, input().split()))
def SL():
return list(map(str, input().split()))
def ILs(n):
return list(int(input()) for _ in range(n))
def SLs(n):
return list(input().strip() for _ in range(n))
def ILL(n):
return [list(map(int, input().split())) for _ in range(n)]
def SLL(n):
return [list(map(str, input().split())) for _ in range(n)]
######OUTPUT######
def P(arg):
print(arg)
return
def Y():
print("Yes")
return
def N():
print("No")
return
def E():
exit()
def PE(arg):
print(arg)
exit()
def YE():
print("Yes")
exit()
def NE():
print("No")
exit()
#####Shorten#####
def DD(arg):
return defaultdict(arg)
#####Inverse#####
def inv(n):
return pow(n, MOD - 2, MOD)
######Combination######
kaijo_memo = []
def kaijo(n):
if len(kaijo_memo) > n:
return kaijo_memo[n]
if len(kaijo_memo) == 0:
kaijo_memo.append(1)
while len(kaijo_memo) <= n:
kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
return kaijo_memo[n]
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
if len(gyaku_kaijo_memo) > n:
return gyaku_kaijo_memo[n]
if len(gyaku_kaijo_memo) == 0:
gyaku_kaijo_memo.append(1)
while len(gyaku_kaijo_memo) <= n:
gyaku_kaijo_memo.append(
gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo), MOD - 2, MOD) % MOD
)
return gyaku_kaijo_memo[n]
def nCr(n, r):
if n == r:
return 1
if n < r or r < 0:
return 0
ret = 1
ret = ret * kaijo(n) % MOD
ret = ret * gyaku_kaijo(r) % MOD
ret = ret * gyaku_kaijo(n - r) % MOD
return ret
######Factorization######
def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-(n**0.5) // 1)) + 1):
if temp % i == 0:
cnt = 0
while temp % i == 0:
cnt += 1
temp //= i
arr.append([i, cnt])
if temp != 1:
arr.append([temp, 1])
if arr == []:
arr.append([n, 1])
return arr
#####MakeDivisors######
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5) + 1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n // i)
return divisors
#####LCM#####
def lcm(a, b):
return a * b // gcd(a, b)
#####BitCount#####
def count_bit(n):
count = 0
while n:
n &= n - 1
count += 1
return count
#####ChangeBase#####
def base_10_to_n(X, n):
if X // n:
return base_10_to_n(X // n, n) + [X % n]
return [X % n]
def base_n_to_10(X, n):
return sum(int(str(X)[-i]) * n**i for i in range(len(str(X))))
#####IntLog#####
def int_log(n, a):
count = 0
while n >= a:
n //= a
count += 1
return count
#############
# Main Code #
#############
N = I()
A1 = IL()
A2 = IL()
ans = []
P(max(sum(A1[: i + 1] + A2[i:]) for i in range(N)))
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Print the maximum number of candies that can be collected.
* * *
|
s142338688
|
Accepted
|
p03449
|
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
|
import sys
from itertools import accumulate
def resolve():
input = sys.stdin.readline
N = int(input().rstrip())
A1 = list(map(int, input().rstrip().split()))
A2 = list(map(int, input().rstrip().split()))
csumA1 = [0] + A1
csumA2 = [0] + A2
csumA1 = list(accumulate(csumA1))
csumA2 = list(accumulate(csumA2))
sum = 0
for i in range(1, N + 1, 1):
sumA1 = csumA1[i] - csumA1[0]
sumA2 = csumA2[N] - csumA2[i - 1]
sum = max(sum, sumA1 + sumA2)
print(sum)
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """5
3 2 2 4 1
1 2 2 2 1"""
output = """14"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """4
1 1 1 1
1 1 1 1"""
output = """5"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """7
3 3 4 5 4 5 3
5 3 4 4 2 3 2"""
output = """29"""
self.assertIO(input, output)
def test_入力例_4(self):
input = """1
2
3"""
output = """5"""
self.assertIO(input, output)
if __name__ == "__main__":
# unittest.main()
resolve()
|
Statement
We have a 2 \times N grid. We will denote the square at the i-th row and j-th
column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1). You will travel to the
bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies. You will collect all the candies
you visit during the travel. The top-left and bottom-right squares also
contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to
travel?
|
[{"input": "5\n 3 2 2 4 1\n 1 2 2 2 1", "output": "14\n \n\nThe number of collected candies will be maximized when you:\n\n * move right three times, then move down once, then move right once.\n\n* * *"}, {"input": "4\n 1 1 1 1\n 1 1 1 1", "output": "5\n \n\nYou will always collect the same number of candies, regardless of how you\ntravel.\n\n* * *"}, {"input": "7\n 3 3 4 5 4 5 3\n 5 3 4 4 2 3 2", "output": "29\n \n\n* * *"}, {"input": "1\n 2\n 3", "output": "5"}]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.