Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
946 B
5
Indexable
Never
#include <bits/stdc++.h>
#define endl '\n'
#define maxn 1005
#define TASK bai1
#define For(i,a,b) for ( int i = a; i <= b; i++ )
#define Ford(i,a,b) for ( int i = a; i >= b; i-- )
#define MOD 100000000000007

using namespace std;
int a[maxn],n,pre[maxn],k = 0;
void swa()
{
    For(i,1,n-1)
    For(j,i+1,n)
        if (a[i] >= a[j]) swap(a[i],a[j]);
}
void inp()
{
    cin >> n;
    For(i,1,n)
        cin >> a[i];
    swa();
    For(i,1,n)
    pre[i] = pre[i-1] + a[i];
}
void solve()
{
    if(n<=3)
    {
        cout << -1;
        return;
    }
    while(pre[n] - pre[n-3] >= pre[n-3])
    {
        k++;
        n--;
        if(n == 3)
        {
            k = -1;
            break;
        }
    }
    cout << k;
}
int main()
{
    ios_base:: sync_with_stdio(0);
    cin.tie(0);
    if(fopen("bai16.inp","r")){
        freopen("bai16.inp","r",stdin);
    }
    inp();
    solve();
}
Leave a Comment