Codeforces 740A. Alyona and copybooks 模拟

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 arubles, 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.

题目链接:http://codeforces.com/contest/740/problem/A


题意:当前有n本书,需要买k本书,使得(n+k)是4的倍数。现在,买一本书需要a元,买2本书需要b元,买3本书需要k元。求最少需要花多少钱。

思路:模拟。因为a,b,c其中有可能会有价格悬殊较大的情况,所以并不是买的越少越好。

n%4  买书的钱

1    3a,b+a,c;

2    2a,b,2c;

3    a,b+c,3c;

这就是所有情况,输出最小的就可以了。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef __int64 ll;
const int MAXN=1e5+;
const __int64 INF=1e9+;
int main()
{
__int64 n,a,b,c;
scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
b=min(*a,b);
c=min(min(*a,a+b),c);
n=n%;
if(n==) cout<<<<endl;
else if(n==)
cout<<min(min(*a,a+b),c);
else if(n==)
cout<<min(min(*a,b),*c);
else
cout<<min(min(a,b+c),*c);
return ;
}
上一篇:字符集设置为UTF-8


下一篇:CodeForces.158A Next Round (水模拟)