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