Codeforces Round 957 (Div. 3)

🚀欢迎来到本文🚀
🍉个人简介:陈童学哦,彩笔ACMer一枚。
🏀所属专栏:Codeforces
本文用于记录回顾总结个人的一些解题思路便于加深理解。

在这里插入图片描述

A. Only Pluses

Kmes has written three integers a a a, b b b and c c c in order to remember that he has to give Noobish_Monk a × b × c a \times b \times c a×b×c bananas.

Noobish_Monk has found these integers and decided to do the following at most 5 5 5 times:

  • pick one of these integers;
  • increase it by 1 1 1.

For example, if a = 2 a = 2 a=2, b = 3 b = 3 b=3 and c = 4 c = 4 c=4, then one can increase a a a three times by one and increase b b b two times. After that a = 5 a = 5 a=5, b = 5 b = 5 b=5, c = 4 c = 4 c=4. Then the total number of bananas will be 5 × 5 × 4 = 100 5 \times 5 \times 4 = 100 5×5×4=100.

What is the maximum value of a × b × c a \times b \times c a×b×c Noobish_Monk can achieve with these operations?

在这里插入图片描述
Input

Each test contains multiple test cases. The first line of input contains a single integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1t1000) — the number of test cases. The description of the test cases follows.

The first and only line of each test case contains three integers a a a, b b b and c c c ( 1 ≤ a , b , c ≤ 10 1 \le a, b, c \le 10 1a,b,c10) — Kmes’s integers.

在这里插入图片描述
Output

For each test case, output a single integer — the maximum amount of bananas Noobish_Monk can get.

在这里插入图片描述

解题思路

暴力枚举即可。

AC代码

#include<bits/stdc++.h>
#define look(x) cout << #x << " ==  " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 5e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve(){
   
	int a,b,c;
	cin >> a >> b >> c;
	int ans = a * b * c;
	for(int i = 0;i <= 5;i ++){
   
		for(int j = 0;j <= 5;j ++){
   
			for(int k = 0;k <= 5;k ++){
   
				if(i + j + k <= 5){
   
					ans = max(ans,(a + i) * (b + j) * (c + k));
				}
			}
		}
	}	
	cout << ans << "\n";
}
int main(){
   	

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	
	int t = 1;
	cin >> t;

	while(t --){
   
		solve();
	}
	
	return 0;
}

B. Angry Monk

To celebrate his recovery, k1o0n has baked an enormous n n n metres long potato casserole.

Turns out, Noobish_Monk just can’t stand potatoes, so he decided to ruin k1o0n’s meal. He has cut it into k k k pieces, of lengths a 1 , a 2 , … , a k a_1, a_2, \dots, a_k a1,a2,,ak meters.

k1o0n wasn’t keen on that. Luckily, everything can be fixed. In order to do that, k1o0n can do one of the following operations:

  • Pick a piece with length a i ≥ 2 a_i \ge 2 ai2 and divide it into two pieces with lengths 1 1 1 and a i − 1 a_i - 1 ai1. As a result, the number of pieces will increase by 1 1 1;
  • Pick a slice a i a_i ai and another slice with length a j = 1 a_j=1 aj=1 ( i ≠ j i \ne j i=j) and merge them into one piece with length a i + 1 a_i+1 ai+1. As a result, the number of pieces will decrease by 1 1 1.

Help k1o0n to find the minimum number of operations he needs to do in order to merge the casserole into one piece with length n n n.

For example, if n = 5 n=5 n=5, k = 2 k=2 k=2 and a = [ 3 , 2 ] a = [3, 2] a=[3,2], it is optimal to do the following:

  1. Divide the piece with length 2 2 2 into two pieces with lengths 2 − 1 = 1 2-1=1 21=1 and 1 1 1, as a result a = [ 3 , 1 , 1 ] a = [3, 1, 1] a=[3,1,1].
  2. Merge the piece with length 3 3 3 and the piece with length 1 1 1, as a result a = [ 4 , 1 ] a = [4, 1] a=[4,1].
  3. Merge the piece with length 4 4 4 and the piece with length 1 1 1, as a result a = [ 5 ] a = [5] a=[5].

在这里插入图片描述

Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104).

Description of each test case consists of two lines. The first line contains two integers n n n and k k k ( 2 ≤ n ≤ 1 0 9 2 \le n \le 10^9 2n109, 2 ≤ k ≤ 1 0 5 2 \le k \le 10^5 2k105) — length of casserole and the number of pieces.

The second line contains k k k integers a 1 , a 2 , … , a k a_1, a_2, \ldots, a_k a1,a2,…<

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈童学哦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值