Posts

Showing posts from June, 2020

A - Beru-taxi(706A - Beru-taxi)

Image
                                  706A - Beru-taxi Vasiliy lives at point  ( a ,  b )  of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested  n  available Beru-taxi nearby. The  i -th taxi is located at point  ( x   i ,  y   i )  and moves with a speed  v   i . Consider that each of  n  drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars. Input The first line of the input contains two integers  a  and  b  (  - 100 ≤  a ,  b  ≤ 100 ) — coordinates of Vasiliy's home. The second line contains a single integer  n  ( 1 ≤  n  ≤ 1000 ) — the number of available Beru-taxi cars nearby. The  i -th of the following  n...

787A - The Monster

Image
787A - The Monster .cpp  A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times   b ,  b  +  a ,  b  + 2 a ,  b  + 3 a , ...   and Morty screams at times   d ,  d  +  c ,  d  + 2 c ,  d  + 3 c , ... . The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time. Input The first line of input contains two integers  a  and  b  ( 1 ≤  a ,  b  ≤ 100 ). The second line contains two integers  c  and  d  ( 1 ≤  c ,  d  ≤ 100 ). Output Print the first time Rick and Morty will scream at the same time, or   - 1  if they will never scream at the same time. Examples input Copy 20 2 9 19 output Copy 82 input Copy 2 1 16 12 output C...

680A - Bear and Five Cards

680A - Bear and Five Cards A. Bear and Five Cards   A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer. Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards. He is allowed to  at most once  discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number. Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards? Input The only line of the input contains five integers  t   1 ,  t   2 ,  t   3 ,  t   4  and  t   5  ( 1 ≤  t   i  ≤ 100 ) — numbers written on cards. Output Print the minimum possible sum of numbers written on remaining cards. Examples input Copy 7 3 7 3 20 output Copy 26 input Copy 7 9 3 1 8 output Copy 28 input Copy ...

676A - Nicholas and Permutation

A. Nicholas and Permutation   Nicholas has an array  a  that contains  n   distinct  integers from  1  to  n . In other words, Nicholas has a permutation of size  n . Nicholas want the minimum element (integer  1 ) and the maximum element (integer  n ) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions. Input The first line of the input contains a single integer  n  ( 2 ≤  n  ≤ 100 ) — the size of the permutation. The second line of the input contains  n  distinct integers  a   1 ,  a   2 , ...,  a   n  ( 1 ≤  a   i  ≤  n ), where  a   i  is equal to the element at the  i -th position. Output Print a single in...

670A - Holidays

670A - Holidays A. Holidays   On the planet Mars a year lasts exactly  n  days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. Input The first line of the input contains a positive integer  n  ( 1 ≤  n  ≤ 1 000 000 ) — the number of days in a year on Mars. Output Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. Examples input Copy 14 output Copy 4 4 input Copy 2 output Copy 0 2 Note In the first sample there are  14  days in a year on Mars, and therefore independently of the day a year starts with there will be exactly  4  days off . In the second sample there are only  2  days in a year on Mars, and they can both be either work days or days off. #include <iostream> using namespace ...