# 2 Python beginners challenge AtCoder! ABC085C --Otoshidama

Importance of AtCoder

I'm new to such things, so I don't know. It's just fun to think logically and to output and confirm what you have learned. As I noticed when I was job hunting, some major IT companies give AtCoder scores. In that sense, it may be judged not only as self-satisfaction but also objectively. Right now, I'm solving in order from here "What to do next after registering with AtCoder-If you solve this much, you can fight enough! 10 past questions-".

Problem (quote)

[Problem summary] There were a total of NN 10000 yen bills, 5000 yen bills, and 1000 yen bills, and the total amount was YY yen. Find one set of the number of bills for each amount that meets these conditions. If such a situation cannot exist, output -1 -1 -1.

[Restrictions]

1≤N≤2000 1000≤Y≤2∗107 N is an integer Y is a multiple of 1000

What I thought after solving

First of all, did you write the part that should be considered as a commentary? That is. But I'm glad I read it after solving it. I've been addicted to muscle training lately, so I tried to push it through with power play. I think that an absolute solution will come out if there is no time limit, but instead I had to think about how to optimize it. It is the same as the probability and permutation that I did when I was a high school student, and it takes time to ask for all. So, 10,000 yen bill and 5,000 yen bill If you realize that the number of 1000-yen bills will be fixed automatically if you know the number of, this problem seems to be OK.

Submission code

from sys import stdin
N,Y = [int(x) for x in stdin.readline().rstrip().split()]
a = -1
b = -1
c = -1
for i in range(N+1):
    for j in range(N-i+1):
        if i+j+(N-i-j) == N and Y == 10000*i + 5000*j + 1000*(N-i-j):
            a = i
            b = j
            c = (N-i-j)
            break
print(str(a)+' '+str(b)+' '+str(c))

Reflection

Even with this, the correct answer was correct, but I regret that I should make efforts to increase the processing speed and reduce the size. I also wanted to remember about format. What I learned this time ・ -Input method in competitive programming -Optimization of combination

is! If you use your head and do it like that, the sense of accomplishment is amazing. Tobacco is delicious. When I didn't know anything about competitive programming, I put the input data in a list, took it out each time, put it in a variable, and so on, so it was a redundant code. I wanted to input beautifully this time, so I tried using list comprehension and stdin module!

The combination is as above! It's just the beginning, but programming is a series of applications of basic knowledge as long as you have a basic concept. ?? ?? If you remember the module each time, you can do it more and more, right? ?? ?? I'm starting to notice the gal inside me. I want to do more and more with an invincible mind. please excuse my poor writing.

Recommended Posts

# 2 Python beginners challenge AtCoder! ABC085C --Otoshidama
[AtCoder] ABC165C Personal Note [Python]
AtCoder Beginners Contest Past Question Challenge 4
AtCoder Beginners Contest Past Question Challenge 9
atCoder 173 Python
AtCoder Beginners Contest Past Question Challenge 7
AtCoder Beginners Contest Past Question Challenge 10
Challenge AtCoder
AtCoder Beginners Contest Past Question Challenge 5
Answer to AtCoder Beginners Selection by Python3
Atcoder standard input set for beginners (python)
[Python] Challenge 100 knocks! (015 ~ 019)
AtCoder ABC 174 Python
[Python] Challenge 100 knocks! (030-034)
[Python] Challenge 100 knocks! (006-009)
AtCoder ABC187 Python
[Python] Challenge 100 knocks! (000-005)
AtCoder ABC188 Python
[Python] Challenge 100 knocks! (010-014)
[Python] Challenge 100 knocks! (025-029)
Beginners practice Python
Python beginner's note
python challenge diary ①
AtCoder ABC 175 Python
[Python] Challenge 100 knocks! (020-024)
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
[Answer example (python3)] ABS (AtCoder Beginners Selection) of atcoder
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Python Beginner's Guide (Functions)
Daily AtCoder # 18 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Solve AtCoder 167 with python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Solve ABC146-C in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
[Python] Search (itertools) ABC167C
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Python beginners organize heapsort
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Python beginners organize quicksort
Daily AtCoder # 10 in Python
Python beginners touch Pytorch (3)
[Python] Search (NumPy) ABC165C
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
python textbook for beginners
Automate AtCoder submission (Python)