java@Cat

Учебные материалы по изучению основ языка програvмирования Java

Menu

Skip to content
  • Главная
  • Word Of Week
    • Pancaked Strings
    • Segmented Array
    • StringTokenizer
    • Java Collections Framework: Map
    • BST – Двоичные деревья поиска
    • Разбор арифметических выражений
    • Дополнительные задания
  • Algorithms and Data Structures
    • Тест и отчет
    • Лекционный материал
  • Course Dashboard
  • Учебные материалы
  • 1. Линейные алгоритмы
  • 2. Алгоритмы с ветвлением
  • 3. Циклические вычисления
    • Вложенные циклы
  • 4. Потоковая обработка
  • 5. Массивы
    • Многомерные массивы
  • 7. Объекты
  • 8. Структуры данных

Мета

  • Войти
  • Лента записей
  • Лента комментариев
  • WordPress.org

Свежие комментарии

  • Игорь Мазурок к записи Обратная польская нотация
  • Кирилл к записи Обратная польская нотация
  • Игорь Мазурок к записи Обратная польская нотация
  • Vika к записи Обратная польская нотация
  • Игорь Мазурок к записи e-olymp 7612. Алекс и квадраты оригами

Новые решения

  • e-olymp 1390. Автогонки
  • e-olymp 9531. Комплексные числа: сложение и вычитание
  • e-olymp 1288. n-значные числа
  • e-olymp 9407. Слияние строк
  • e-olymp 8669. Все делители

Tag Archives: account

e-olymp 84. Transfer

20/11/2018 by Костя Григорян

0

Task

Vasya has one package of mobile phone operator Ratsviyk and $S_0$ tugriks on its account. (Tugrik is the currency in Vasya’s country. $0.01$ of tugrik is a cent). Also he has $n$ packages of Eciujd which is the satellite of Ratsviyk. There are $S_i$ tugriks on the account of the $i$-th package of Eciujd. There was a new tariff plan on Ratsviyk and Vasya want to go into it. For this purpose it is necessary to have at least $S$ tugriks on the account. Vasya hasn’t any money, that is why he don’t want to buy new bill replenishment, to fill up the Ratsviyk account to the necessary sum. But the escape exists.
On Ratsviyk there is such possibility as to transfer money between each others. The transfer is the sending of some money from one account to another. It is possible to send only an integer amounts of tugriks, not smaller than $5$. The cost of the transfer is $10$ cents which is draw from the account from which money was sended. Transfer can be made only if after it on the account remains at least $5$ tugriks. Since Eciujd is the satellite of Ratsviyk, then subscribers of Eciujd also can participate in this transfers.
Giving $S_0, S, n, S_i (1 \leq i \leq n)$ find whether it is possible to go into new tariff plan without buying new bill replenishment and if so find the minimum number of transfers needed for this.

Input

In the first line of input there is an integer $n (0 \leq n \leq 1000), S_0$ and $S$. In the second line are written down through a blank numbers $S_1, S_2,$…$,S_n$. All numbers $S, S_i (0 \leq i \leq n)$ — real numbers from the interval $[0.01, 10000.00]$ with exactly with two digits after a decimal point.

Output

Output the minimum number of transfers needed to go into new tariff plan or $-1$ if it is impossible without buying a new bill replenishment.

Tests

Input Output
[latex]2\, 10.00\, 16.00[/latex] [latex]2[/latex]
[latex]10.10\, 6.10[/latex]
[latex]3\, 100.00\, 50.00[/latex] [latex]0[/latex]
[latex]2.00\, 19.05\ 30.20[/latex]
[latex]3\ 10.00\ 14.00[/latex] [latex]-1[/latex]
[latex]2.00\ 10.05\ 10.00[/latex]
[latex]2\ 142.10\ 143.00[/latex] [latex]2[/latex]
[latex]6.05\ 7.00[/latex]

Code

e-olymp 84 Transfer
Java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.Scanner;
import java.util.*;
  
public class Main {
public static void main (String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
double s0 = scanner.nextDouble();
double s = scanner.nextDouble();
double [] A = new double[n];
double [] B = new double[n];
if(s0>=s)
System.out.println(0);
else if(n==0)
System.out.println(-1);
else
{
    for(int i=0; i<n; i++)
    {
        double a = scanner.nextDouble();
        A[i]=a;
        B[i]=A[i];
    }
    Arrays.sort(B);
    int ans=0;
    for(int i=n-1; i>=1; i--)
    {
        if(B[i]>=10.1)
        {
            if((int)(B[i]-5.1)+s0>=s){
                ans++;
                System.out.println(ans);
                System.exit(0);
            }
            else
            {
                ans++;
                B[i-1]+=(int)(B[i]-5.1);
            }
        }
        else
        {
            break;
        }
    }
    if((B[0]>=10.1)&&((int)(B[0]-5.1)+s0>=s))
        System.out.println(ans+1);
    else
    {
        Arrays.sort(A);
        if(s0>=10.1)
        {
            A[n-1]+=(int)(s0-5.1);
            s0-=(int)(s0-5.1);
s0-=0.1;
            ans=1;
            for(int i=n-1; i>=1; i--)
            {
                if(A[i]>=10.1)
                {
                    if((int)(A[i]-5.1)+s0>=s){
                        ans++;
                        System.out.println(ans);
                        System.exit(0);
                    }
                    else
                    {  
                        ans++;
                        A[i-1]+=(int)(A[i]-5.1);
                    }
                }
                else
                {
                    break;
                }
            }
            if((A[0]>=10.1)&&((int)(A[0]-5.1)+s0>=s))
                System.out.println(ans+1);
            else
                System.out.println(-1);
        }
        else
         System.out.println(-1);
    }  
}
}
}

Solution

To begin with, if we have enough money in our account, then we do not need to do anything. Otherwise, we have three options: when we can collect the required amount without manipulating the main account, when we can collect the necessary amount by manipulating the main account and when we can not collect the required amount at all.
For the first option, we will transfer the largest possible amount to smaller ones from large side accounts and check whether we can switch to a new tariff by transferring the current account amount to the main account. In cases of a positive answer, the problem is solved.
If in the end you did not manage to get the right amount, go to the second option. We simply transfer the maximum possible amount from the main account to the largest collateral account. Then we do everything the same as in the first version. In cases of a positive answer, the problem is solved.
Otherwise, you can not get the right amount.

References

The task at E-Olymp
My solution at ideone

Posted in 5. Массивы. Tagged account, search of options, transfer.

Post navigation

Лисовой Андрей (12)
Rud Valeriya (11)
Григорян Костя (11)
Шостак Дмитрий (10)
Рябова Саша (10)
Пиндус Дарья (10)
Волков Кирилл (10)
Ворохта Алиса (10)
Мороз Дима (10)
Козачков Владислав (9)
Миловская Карина (9)
Тарасов Артур (9)
Савчак Даниель (9)
Лавриненко Валентин (9)
Ларикова Валерия (9)
Крутоголов Даниил (8)
Литвиненко Ирина (8)
Хоба Юрий (8)
Мартынюк Георгий (8)
Васильева Иоанна (7)
https://tripbusting.com/ https://tripbusting.com/ (7)
Черноглазов Николай (7)
Василевский Иван (7)
Присяжный Михаил (7)
Осецимский Анатолий (7)
Пасенченко Томас (7)
Коваль Максим (7)
Джашимов Антон (6)
Туромша Сережа (6)
Гуменюк Марина (6)
Брагар Эдуард (6)
Дяченко Александр (6)
Мазурин Эдвард (6)
Tuan Anh (5)
Сидоровский Дмитрий (5)
Жуков Павел (5)
Черноморец Илья (5)
Бондаренко Кирилл (5)
Варламов Игорь (5)
Чернобровкин Артем (5)
Рыжков Саша (5)
Колчинская Яна (5)
Чернецкий Андрей Святозар (4)
Илларионова Мария (4)
Савицкая Елизавета (4)
Халафов Нурал (4)
Филистович Александра (4)
Брошко Глеб (4)
Швандт Максим (4)
Пушкин Никита (4)
Гринькив Владислав (3)
Карташов Денис (3)
Рапчинский Александр (3)
Алексютенко Эвелина (3)
Болдин Валерий (3)
Крачилова Виктория (3)
Цушко Валентин (3)
Зозуля Алина (3)
Розин Александр (2)
Прокопов Эммануил (2)
Рогулин Артем (2)
Цивинская Анна (2)
Куперман Антон (2)
Мацалышенко Паша (2)
Андриеш Валентина (2)
Сторожев Олег (2)
Малихіна Аліна (2)
Фищук Евгений (2)
Жаркая Мария (2)
Осипенко Таня (2)
Репнин Никита (2)
Марченко Филипп (2)
Стасюк Владислав (2)
Романцова Катя (2)
Жирко Николай (1)
Писаревская Наташа (1)
Воротов Дмитрий (1)
Кулык Даниил (1)
Бронфен-Бова Роман (1)
Гербали Никита (1)
Андреев Даниил (1)
Захаренко Владимир (1)
Данілов Гліб Олегович (1)
Радчин Евгений (1)
Казарян Лаура (1)
Zelinsky Vacheslav (1)
Метасов Андрей (1)
Гордийчук Вадим (1)
Шиманский Владислав (1)
Yanishevskaya Alyona (1)
Proudly powered by WordPress | Theme: Sunspot by WordPress.com.