跳到正文

题解

题解:AT_arc174_b [ARC174B] Bought Review

pbcoding约 5 分钟
原文
文章信息与版本

文章信息

发布
2026年5月30日
收录
2026年5月30日
更新
2026年11月12日
篇幅
约 5 分钟
获赞
2

版本

  1. v4当前
  2. v3
  3. v2
  4. v1

题目大意

在原始的评分中加入一些评分使得平均分不小于 33 分。

分析过程

首先我们知道,添加 1,2,31,2,3 分评论并不会使得平均分超过 33 分,所以只需要考虑 4,54,5 分评论。

设 ss 为原始评分总和,tt 为原始评分数量,加入 xx 个 44 分和 yy 个 55 分评论则可列出下列式子。

s+4x+5yt+x+y≥3\frac{s+4x+5y}{t+x+y}\ge3

将式子变形得到:

s+4x+5y≥3×(t+x+y)s+4x+5y≥3t+3x+3ys+x+2y≥3tx+2y≥3t−s\begin{aligned} s+4x+5y &\ge 3\times(t+x+y)\\ s+4x+5y &\ge 3t+3x+3y\\ s+x+2y &\ge 3t\\ x+2y &\ge 3t-s\\ \end{aligned}

设 low=3t−slow=3t-s,则答案应为:对于满足条件 x+2y≥lowx+2y\ge low 的 x,yx,y,求 xP4+yP5xP_4+yP_5 的最小值。

显然可以贪心,分类讨论:

  • 如果 st\frac{s}{t} 也就是平均分,已经超过 33 分时无需任何操作。
  • 如果 2P4<P52P_4<P_5,则全部点 44 分评论。
  • 如果 2P4>P52P_4>P_5 且 lowlow 是偶数,则全部点 55 分评论。
  • 如果 2P4>P52P_4>P_5 且 lowlow 是奇数,则点 11 个 44 分和 55 分中代价最小的,其他全部点 55 分评论。

整理得:

{0st≥3lowP42P4<P5low2P5(2P4≥P5)∧(2∣low)low2P5+min⁡(P4,P5)(2P4≥P5)∧(2∤low)\begin{cases} 0 & \frac{s}{t}\ge3\\ lowP_4 & 2P_4<P_5\\ \frac{low}{2}P_5 & (2P_4\ge P_5)\land(2\mid low)\\ \frac{low}{2}P_5+\min(P_4,P_5) & (2P_4\ge P_5)\land(2\nmid low) \end{cases}

代码

Code
C++
#include<iostream>
#define sqrt(x) __builtin_sqrt(x)
#define memcpy(dest, src, n) __builtin_memcpy(dest, src, n)
#define memset(st, val, n) __builtin_memset(st, val, n)
#define memmove(dest, src, n) __builtin_memmove(dest, src, n)
#define closeios() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fropen(x) freopen(x".in", "r", stdin);freopen(x".out", "w", stdout)
template<typename t> t sqr(t x){return (x*x);}
template<typename t> t abs(t x){return (x>0?x:-x);}
template<typename t> t inrange(t n, t l, t r){return (l<=n&&n<=r);}
#ifdef ONLINE_JUDGE
const bool use_stderr=0;
#else
const bool use_stderr=1;
#endif
template<typename... args>
void errorf(const char* format, args... v){if(use_stderr)fprintf(stderr, format, v...);}
int       log2(int x){return (31-__builtin_clz(x));}
long long log2(long long x){return (63-__builtin_clzll(x));}
#define int2ll 1
#if int2ll
#define intEx signed
#define int long long
#else
#define intEx int
#define ll long long
#endif
using namespace std;

string s;
int n, sum, cnt, p4, p5;

intEx main(){
//	fropen("");
	// code
	int t;
	cin >> t;
	while(t--){
		sum = cnt = 0; // 多测要清空!!!
		for(int i=1;i<=5;i++){
			int p;
			cin >> p;
			sum += i*p;
			cnt += p;
		}
		cin >> p4 >> p4 >> p4 >> p4 >> p5; // 1~3分没有用不管
		if(sum/cnt>=3){ // 本来就满足条件
			cout << "0\n";
			continue;
		}
		int low=3*cnt-sum;
		if(p4*2<p5){
			cout << low*p4 << "\n";
		}
		else{
			cout << low/2*p5+low%2*min(p4, p5) << "\n";
			// low%2*min(p4, p5) 和 (low%2==0?0:min(p4, p5)) 是同样的效果
		}
	}
	return 0;
}
原文