Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(linker, "/STACK:65777216")
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <ctime>
- #include <cstdio>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <stack>
- #include <map>
- #include <queue>
- #include <string>
- #include <memory.h>
- #include <iterator>
- #define y1 trololoy1
- #define y0 trololoy0
- #define mem(A,X) memset(A,X,sizeof(A))
- #define memo(A) memset(A,0,sizeof(A))
- #define forn(I,B) for (int I=1;I<=(B);I++)
- #define forg(H,V) for (int H=first[V];h;h=next[H])
- #define rep(I,B) for (int I=0;I<(B);I++)
- #define labs(X) (((X)>0)?(X):(-(X)))
- #define ropen(X) freopen(X,"r",stdin)
- #define wopen(X) freopen(X,"w",stdout)
- #define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
- #define pb push_back
- #define mp make_pair
- #define all(X) (X).begin(),(X).end()
- #define sqr(X) ((X)*(X))
- using namespace std;
- typedef pair <int,int> pii;
- typedef double ld;
- typedef long long ll;
- typedef pair <ll,ll> pll;
- typedef vector<int> vi;
- const int N=1111;
- const ll INF=9187201950435737472ll;
- const double eps=1e-9;
- const double pi=3.14159265358979;
- ll f[N][N],ans,mx[N],c;
- int a[N],l,r,n,m,w;
- inline void build(int num){
- mem(mx,128);
- rep(i,n) mx[i]=f[num][i]-c*a[i];
- }
- inline ll get_max(int l,int r){
- ll ans=-INF;
- for (int i=l;i<=r;i++) ans>?=mx[i];
- return ans;
- }
- int main(){
- ropen("input.txt");
- wopen("output.txt");
- scanf("%d%d%d%d%d",&n,&m,&l,&r,&w);
- rep(i,n) scanf("%d",&a[i]);
- mem(f,128);
- rep(i,n) if (a[i]>=l && a[i]<=r) f[1][i]=0;
- for (int i=2;i<=m;i++){
- c=(i-1)*(m-i+1);
- build(i-1);
- int L=0,R=0;
- rep(j,n){
- if (a[j]-a[L]<l) continue;
- while (a[j]-a[L]>r && L<j) ++L;
- if (L==j) continue;
- while (a[j]-a[R+1]>=l && R<j-1) ++R;
- ll t=get_max(L,R);
- if (t<=-INF) f[i][j]=-INF;
- else f[i][j]=t+c*a[j];
- }
- }
- rep(i,n) if (w-a[i]>=l && w-a[i]<=r) ans>?=f[m][i];
- printf("%I64d\n",ans+ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment