# Codeforces 727 F. Polycarp ' s problems

Source: Internet
Author: User

Description

There is a sequence with a length of \ (n\) that has a positive and negative weight, you start with a value, each time to a weighted value plus, the minimum number of values to delete to the end of the sequence. \ (n \leqslant 750,m \leqslant 2 \times 10^5\)

Sol

dp+ two points.

Found that this thing has aftereffect, that is, the previous selection will affect the subsequent decision, and the weight is too large to record.

But we can do it backwards, because the decisions behind it don't affect the decision.

\ (f[i][j]\) indicates to \ (i\) to delete \ (j\) a minimum required initial weight value.

Because the initial weight is not negative, so it is impossible to appear in the middle of negative, to dispose of, and then on two decisions, delete or not delete, transfer is very good write.

He has a monotonous, two-point statistic when he answers.

Code
#include <cstdio> #include <cstring> #include <iostream>using namespace std;typedef long Long ll;const int N = 755;int n,m; ll A[n],f[n][n],w[n];inline ll in (ll X=0,char Ch=getchar ()) {while (ch> ' 9 ' | | ch< ' 0 ') Ch=getchar (); while (ch>= ' 0 ' && ch<= ' 9 ') x= (x<<3) + (x<<1) +ch-' 0 ', Ch=getchar (); return x; }void work (LL x) {int L=0,r=n,mid;while (l<=r) {mid= (l+r) >>1;if (F[1][mid] <= x) R=mid-1;else l=mid+1;} printf ("%d\n", L);} int main () {scanf ("%d%d", &n,&m), for (int i=1;i<=n;i++) Cin>>a[i];memset (f,0x3f,sizeof (f)); f[n+1][0 ]=0ll;for (int i=n;i;i--) for (int j=0;j<n-i+1;j++) {f[i][j]=min (F[i][j],max (0ll,f[i+1][j]-a[i])); F[i][j+1]=min (f I [J+1],f[i+1][j]);} for (; m--;) work (in ()); return 0;}

Codeforces 727 F. Polycarp ' s problems

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.