G - Association for the Country of Mububa

vj原题链接:G - Association for the Country of Mububa

You are the boss of ACM (Association for the Country of Mububa), an upstanding company with a single goal of world domination.

Today, you have conquered the unnamed country of Mububa (how an unnamed country has a name is, of course, outside the scope of this problem). Mububa is known for its great, great, bananas. In light of this monumental achievement, you have decided to reward your executives with Mububa’s greatest treasure (which is obviously, bananas). You have prepared NN briefcases, each contains a number of bananas. These briefcases are numbered from 11 through NN.

You reward your executives one by one in order from the least evil executive, to the most evil executive (still not comparably evil to you, of course). No two executives are equally evil. For each executive, you first decide how many briefcases you want to give him. If you decide to give an executive aa briefcases, you give him the aa briefcases with lowest numbers that you still have. Each executive you reward must receive at least one briefcase.

It is important to be fair when distributing rewards. You do not want your executives to stage a hunger strike, after all. Thus, the rewards the executives received must reflect how evil they are. More rigorously, if executive AA is more evil than executive BB, then the total number of bananas received by executive AA must be at least as large as the total number of bananas received by executive BB.

You know the number of bananas inside all of the briefcases. You want to reward as many executives as possible, but wants the distribution to still be fair (i.e. following the previous requirement) amongst them. What is the maximum number of executives you can reward this way?

Input

The first line contains a non-negative integer 2 \leq N \leq 3\, 0002≤N≤3000, giving the number of briefcases you have. Then follows a line with NN integers, the ii-th of which denotes the number of bananas in briefcase number ii. Each briefcase contains between 11 and 10^9109 bananas, inclusively.

Output

Print the maximum number of executives you can reward with bananas.

Sample Data explanation

In the first example, give briefcase 11 to the least evil executive, briefcase 22 to the second least evil executive, and briefcases 33 and 44 to the most evil executive.

In the second example, give briefcase 11 to the least evil executive, briefcases 22 and 33 to the second least evil executive, and briefcases 44, 55, and 66 to the most evil executive.

Sample 1

InputcopyOutputcopy
4
1 2 1 2
3

Sample 2

InputcopyOutputcopy
6
6 4 2 2 2 2
3

 题意:给n个数字要形成尽可能多的区间使得区间和呈非严格递增的排列问有最多多少个这种区间

思路分析:dp问题模型有点类似于最长上升子序列模型但是包装的比较好(个人认为)区间和明显用前缀和来表示。区间尽可能多——>贪心(让最后一个区间和尽可能的小)

状态表示;f[N]   f[i]表示前i个数最多能形成多少区间(注意这里题目说明每个数都会参与形成区间)

状态计算:f[i]=f[j]+1; j 表示形成的最后一个区间的前一个区间右端点 同时开另外一个数组来存一下以j结尾的最后一个区间和

一定不要开long long

    #include <math.h>
    #include<map>
    #include <algorithm>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #define PI acos(-1)
    #include <string.h>
    using namespace std;
    const int N = 1e6 + 5, M = 1e5 + 5, inf = 0x3f3f3f3f, mod = 1e9 + 7;
    const double esp = 1e-6;
    typedef pair<int, int> PII;
    int a[N];
    int n;
    long long su[N];
    int f[N];
    long long best[N];
    int main() {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            su[i]=su[i-1]+a[i];
        }
        for(int i=1;i<=n;i++)
    {
        for(int j=i;j>=1;j--)
        {
            if(su[i]-su[j-1]>=best[j-1])
            {
            f[i]=f[j-1]+1;
            best[i]=su[i]-su[j-1];
            break;    
            }
        }
    }
    printf("%d\n",f[n]);
        return 0;
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Monster_six

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值