A - Apple
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100 100 100 points
Problem Statement
A fruit store sells apples.
You may perform the following operations as many times as you want in any order:
- Buy one apple for X X X yen (the currency in Japan).
- Buy three apples for Y Y Y yen.
How much yen do you need to pay to obtain exactly N N N apples?
Constraints
-
1 ≤ X ≤ Y ≤ 100 1 \leq X \leq Y \leq 100 1≤X≤Y≤100
-
1 ≤ N ≤ 100 1 \leq N \leq 100 1≤N≤100
-
All values in input are integers.
Input
Input is given from Standard Input in the following format:
X X X Y Y Y N N N
Output
Print the answer as an integer.
题面翻译
你需要买 n n n个苹果,有两种购买方式:
- 一个苹果 x x x元;
- 三个苹果 y y y元。
求最少需要多少元。
Sample Input 1
10 25 10
Sample Output 1
85
Buy three apples for 25 25 25 yen three times and one apple for 10 10 10 yen, and you will obtain exactly 10 10 10 apples for a total of 85 85 85 yen.
You cannot obtain exactly 10 10 10 apples for a lower cost, so the answer is 85 85 85 yen.
Sample Input 2
10 40 10
Sample Output 2
100
It is optimal to buy an apple for 10 10 10 yen 10 10 10 times.
Sample Input 3
100 100 2
Sample Output 3
200
The only way to obtain exactly 2 2 2 apples is to buy an apple for 100 100 100 yen twice.
Sample Input 4
100 100 100
Sample Output 4
3400
题解部分
分情况讨论:
若 3 x ≤ y 3x \le y 3x≤y,即单个买更优,就输出单个买的情况: n x nx nx;
否则,三个买更优,则先三个地买,剩余的苹果单个买: n y 3 + ( n m o d 3 ) × x \frac{ny}{3}+(n \bmod 3) \times x 3ny+(nmod3)×x
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int x, y, n;
int main () {
scanf ("%d %d %d", &x, &y, &n);
if (x * 3 <= y) {
printf ("%d", x * n);
} else {
printf ("%d", n / 3 * y + (n % 3) * x);
}
return 0;
}
B - Explore
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200 200 200 points
Problem Statement
Takahashi is exploring a cave in a video game.
The cave consists of N N N rooms arranged in a row. The rooms are numbered Room 1 , 2 , … , N 1,2,…,N 1,2,…,N from the entrance.
Takahashi is initially in Room 1 1 1, and the time limit is T T T.
For each 1 ≤ i ≤ N − 1 1≤i≤N−1 1≤i≤N−1, he may consume a time of A i A_i Ai to move from Room i i i to Room ( i + 1 ) (i+1) (i+1). There is no other way to move between rooms. He cannot make a move that makes the time limit 0 0 0 or less.
There are M M M bonus rooms in the cave. The i i i-th bonus room is Room X i X_i Xi ; when he arrives at the room, the time limit increases by Y i Y_i Yi.
Can Takahashi reach Room N N N?
Constraints
-
2 ≤ N ≤ 1 0 5 2≤N≤10^5 2≤N≤105
-
0 ≤ M ≤ N − 2 0≤M≤N−2 0≤M≤N−2
-
1 ≤ T ≤ 1 0 9 1≤T≤10^9 1≤T≤109
-
1 ≤ A i ≤ 1 0 9 1≤A_i≤10^9 1≤Ai≤109
-
1 < X 1 < … < X M < N 1<X_1<…<X_M<N 1<X1<…<XM<N
-
1 ≤ Y i ≤ 1 0 9 1≤Y_i≤10^9 1≤Yi≤109
All values in input are integers.
Input
Input is given from Standard Input in the following format:
N N N M M M T T T
A 1 A_1 A1 A 2 A_2 A2 … … …