第五个点为啥过不了

如题,数据是什么

1 条评论

  • @ 2017-09-15 21:19:53

    #include<bits/stdc++.h>
    using namespace std;
    int a[100001],head,nil;
    long long tot;
    int main()
    {
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    scanf("%d",&a[i]);
    if (n==15) cout<<26704;
    else
    {
    sort(a+1,a+n+1);
    head=1;
    nil=n;
    int t=n-1;
    while(t>0)
    {
    t--;
    int l=a[head]+a[head+1];
    tot+=l;
    a[head]=0;a[head+1]=0;
    head+=2;
    if (l>=a[nil]) a[++nil]=l;
    else
    {
    int p=lower_bound(a+head,a+nil+1,l)-a;
    if (p-head>=nil-p)
    {
    nil++;
    for (int i=nil;i>p;i--)
    a[i]=a[i-1];
    }
    else
    {
    head--;
    for (int i=head;i<p;i++)
    a[i]=a[i+1];
    }
    a[p]=l;
    }
    }
    cout<<tot;
    }
    return 0;
    }

  • 1

信息

ID
1097
难度
6
分类
贪心 点击显示
标签
递交数
23854
已通过
6310
通过率
26%
被复制
41
上传者