Codeforces Round #737 (Div. 2)题解

Problem - A - Codeforces

题目大意:给定你一个长度为n的序列,你可以将该序列划分为两个子序列,请求出两个子序列,使得两个子序列的平均值之和最大.

思路:思维题,如果一个数组内最大的数和其他较大的数分为一组,那么该组的平均值一定会小于最大的的数,我们目前只有两个序列,应该保证其中一个拥有最大平均值,那就是最大的数本身,所以该题只需要把最大的数作为一组,其他数作为一组即可.

#include<bits/stdc++.h>
using namespace std;
#define rep(x,y,z) for(int x = y; x<=z;++x)
#define dec(x,y,z) for(int x = y; x>=z;--x)
#define INF 0x3f3f3f3f
#define ll long long
#define LOOP ll _; cin>> _; for(ll LP_ = 1; LP_<=_; ++LP_)
#define syncfalse ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
inline int read(){
   
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){
   if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();
   return s*w;
}
const int N = 1e5+5;
int n;
ll a[N];
int main(){
   
    LOOP{
   
        cin>>n;
        ll pre = 0;
        ll maxn = -INF;
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值