Codeforces Round #441 div2 A. Trip For Meal

A. Trip For Meal
time limit per test
1 second
memory limit per test
512 megabytes
input
standard input
output
standard output

Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is a meters, between Rabbit's and Eeyore's house is b meters, between Owl's and Eeyore's house is cmeters.

For enjoying his life and singing merry songs Winnie-the-Pooh should have a meal n times a day. Now he is in the Rabbit's house and has a meal for the first time. Each time when in the friend's house where Winnie is now the supply of honey is about to end, Winnie leaves that house. If Winnie has not had a meal the required amount of times, he comes out from the house and goes to someone else of his two friends. For this he chooses one of two adjacent paths, arrives to the house on the other end and visits his friend. You may assume that when Winnie is eating in one of his friend's house, the supply of honey in other friend's houses recover (most probably, they go to the supply store).

Winnie-the-Pooh does not like physical activity. He wants to have a meal n times, traveling minimum possible distance. Help him to find this distance.

Input

First line contains an integer n (1 ≤ n ≤ 100) — number of visits.

Second line contains an integer a (1 ≤ a ≤ 100) — distance between Rabbit's and Owl's houses.

Third line contains an integer b (1 ≤ b ≤ 100) — distance between Rabbit's and Eeyore's houses.

Fourth line contains an integer c (1 ≤ c ≤ 100) — distance between Owl's and Eeyore's houses.

Output

Output one number — minimum distance in meters Winnie must go through to have a meal n times.

Examples
input
3
2
3
1
output
3
input
1
2
3
5
output
0
Note

In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.

In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all.

题意 一个人在Rabbit家正在吃第一顿饭,接下来要去另外一家吃饭,共要吃n顿饭,三个人的家两两之间距离分别为a,b,c,求吃完n顿饭需要走的最短距离

判断a,b与c的大小关系

a>c&&b>c    先走a,b间最小的,剩下的全走c路(来回走直到走完)。

c>=a || c>=b  就是a,b中有一个数是a,b,c之间最小值,就一直走那个最小的就行了


#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <stack>
#include <set>
#include <queue>
#include <vector>
using namespace std;

#define ll long long 
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define mod 10000000007
#define debug() puts("Fuck you everyday!");
#define Maxn 10000005

int main() 
{
        int n, m, a, b, c;
        scanf("%d", &n);
        scanf("%d%d%d", &a, &b, &c);
        if (n == 1) {
                printf("0\n");
        }
        else if (n == 2) {
                printf("%d\n", min(a, b));
        }
        else if (n > 2) {
                if (c >= a || c >= b) {
                        printf("%d\n", (n - 1) * min(a, b));
                }
                else if (a >= c && b >= c) {
                        printf("%d\n", min(a, b) + (n - 2) * c);
                }
                
        }
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值