7221: Flower

7221: Flower

时间限制: 1 Sec  内存限制: 128 MB
提交: 152  解决: 44
[提交] [状态] [讨论版] [命题人:admin]

题目描述

Rabbit loves flowers very much and she plants n pots of flowers in her house. But she never prunes them because she is lazy. So the flowers have different heights and look ugly. One day, Kayaking decides to prune the flowers to make them look beautiful. To make them have equal heights, smart Kayaking has a wonderful idea. Initially, the i-th pot of flower’s height is a[i]. Each time, Kayaking will select n-1 pots of flowers and prune them to make their height subtract 1 with his 49m knife. Exactly, the height of the flowers is at least 1. Now, Kayaking wants to know if it is possible to prune the flowers to make them have equal height. If possible, what is the minimum times he prunes the flowers. Could you tell him?

 

输入

The input starts with a line contains exactly one positive number T which is the number of test case.
Each test case starts with a line contains a number n indicates the number of flowers. Then there is a line contains n numbers indicates a[i].

 

输出

For each test case, print a single line containing one integer—the minimum times Kayaking prunes the flowers, or -1 if it is impossible.

 

样例输入

2
5
1 2 2 2 2
5
1 2 2 2 3

 

样例输出

1
-1

 

提示

T≤10,n≤10^5,ai≤10^9

 

来源/分类

2018黑龙江省赛 

 

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100007];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll n,flag=1;
        scanf("%lld",&n);
        for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
            sort(a+1,a+1+n);
       int maxx=a[n];
        ll sum=0;
        for(int i=1;i<=n;i++)
             sum=sum+maxx-a[i];

        for(int i=1;i<=n;i++)
        {
            if(maxx-sum<1) {
                flag=0;
                break;
            }
        }
        if(!flag)
            printf("-1\n");
        else
            printf("%lld\n",sum);
    }
    return 0;
}
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值