用的排序再一个个累加,结果两个ac其他输出结果全是0
查看原帖
用的排序再一个个累加,结果两个ac其他输出结果全是0
618195
sajdhkja楼主2022/1/31 22:18
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;const int inf=1e7+10;typedef long long ll;
ll n,m;
ll a[inf];

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n,[](int a,int b){return a>b;});
    ll sum=0;ll i=0;ll high=0;
    while (++i&&i<n)
    {
        ll temp=a[i]-a[i+1];
        if(temp==0)continue;
        if(sum+temp*i==m){sum+=temp*i,high=a[i+1];break;}
        if(sum+temp*i<m){sum+=temp*i;continue;}
        if(sum+temp*i>m){
            for(int k=1;k<temp;k++){
                if(sum+(temp-k)*i==m){sum+=(temp-k)*i,high=a[i+1]+k;break;}
                if(sum+(temp-k)*i>m){continue;}
                if(sum+(temp-k)*i<m){sum+=(temp-k+1)*i,high=a[i+1]+k-1;break;}
            }
            break;
        }
    }
    cout<<high;


    return 0;
}
2022/1/31 22:18
加载中...