AtCoder Beginner Contest 044 A

Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

There is a hotel with the following accommodation fee:

  • X yen (the currency of Japan) per night, for the first K nights
  • Y yen per night, for the (K+1)-th and subsequent nights

Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee.

Constraints

  • 1≤N,K≤10000
  • 1≤Y<X≤10000
  • N, K, X, Y are integers.

Input

The input is given from Standard Input in the following format:

N
K
X
Y

Output

Print Tak's total accommodation fee.


Sample Input 1

Copy
5
3
10000
9000

Sample Output 1

Copy
48000

The accommodation fee is as follows:

  • 10000 yen for the 1-st night
  • 10000 yen for the 2-nd night
  • 10000 yen for the 3-rd night
  • 9000 yen for the 4-th night
  • 9000 yen for the 5-th night

Thus, the total is 48000 yen.


Sample Input 2

Copy
2
3
10000
9000

Sample Output 2

Copy
20000

题解:水过
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 #include <queue>
13 #include <stack>
14 using namespace std;
15 #define lowbit(x) (x&(-x))
16 #define max(x,y) (x>y?x:y)
17 #define min(x,y) (x<y?x:y)
18 #define MAX 100000000000000000
19 #define MOD 1000000007
20 #define pi acos(-1.0)
21 #define ei exp(1)
22 #define PI 3.141592653589793238462
23 #define INF 0x3f3f3f3f3f
24 #define mem(a) (memset(a,0,sizeof(a)))
25 typedef long long ll;
26 ll gcd(ll a,ll b){
27     return b?gcd(b,a%b):a;
28 }
29 bool cmp(int x,int y)
30 {
31     return x>y;
32 }
33 const int N=10005;
34 const int mod=1e9+7;
35 int main()
36 {
37     std::ios::sync_with_stdio(false);
38     int n,k,x,y;
39     cin>>n>>k>>x>>y;
40     ll s=0;
41     if(n<=k) s+=n*x;
42     else s+=k*x+(n-k)*y;
43     cout<<s<<endl;
44     return 0;
45 }
View Code
原文地址:https://www.cnblogs.com/shixinzei/p/7288482.html