codeforces 740A Alyona and copybooks

来源:互联网 发布:李荣浩后羿知乎 编辑:程序博客网 时间:2024/04/30 19:49
A. Alyona and copybooks
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.

What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.

Input

The only line contains 4 integers nabc (1 ≤ n, a, b, c ≤ 109).

Output

Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.

Examples
input
1 1 3 4
output
3
input
6 2 1 1
output
1
input
4 4 4 4
output
0
input
999999999 1000000000 1000000000 1000000000
output
1000000000
Note

In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.

In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.

In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.

In the fourth example Alyona should buy one pack of one copybook.

一看题确认水题 大致思路就是先把n%4 再看需要多少本 但是依然有一些细节需要考虑 

1.数据范围大小 应该是long long

2.比较函数n=4-n%4

n=4,ans=0;

n=1,ans=min(a,b+c,c*3)

n=2,ans=min(a*2,b,c*2)

n=3,ans=min(a*3,a+b,c)

这里的1,2种情况容易漏

#include<iostream>using namespace std;long long min(long long a,long long b){ return a<b?a:b;}long long min(long long a,long long b,long long c){ return min(min(a,b),min(a,c));}int main(){long long n,a,b,c;long long ans;cin>>n>>a>>b>>c;n=4-n%4;if(n==4) ans=0;else if (n==1) ans=min(a,b+c,c*3);else if (n==2) ans=min(a*2,b,c*2);else ans=min(a*3,a+b,c);cout<<ans<<endl;return 0;}



0 0
原创粉丝点击