AtCoder Beginner Contest 265 题解 (A~D)

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 1XY100

  • 1 ≤ N ≤ 100 1 \leq N \leq 100 1N100

  • 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 3xy,即单个买更优,就输出单个买的情况: 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 1iN1, 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 2N105

  • 0 ≤ M ≤ N − 2 0≤M≤N−2 0MN2

  • 1 ≤ T ≤ 1 0 9 1≤T≤10^9 1T109

  • 1 ≤ A i ≤ 1 0 9 1≤A_i≤10^9 1Ai109

  • 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 1Yi109

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 … …

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值