Tranvick

Untitled

Mar 5th, 2012
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #pragma comment(linker, "/STACK:65777216")
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <cstdlib>
  5. #include <ctime>
  6. #include <cstdio>
  7. #include <algorithm>
  8. #include <cmath>
  9. #include <vector>
  10. #include <set>
  11. #include <stack>
  12. #include <map>
  13. #include <queue>
  14. #include <string>
  15. #include <memory.h>
  16. #include <iterator>
  17. #define y1 trololoy1
  18. #define y0 trololoy0
  19. #define mem(A,X) memset(A,X,sizeof(A))
  20. #define memo(A) memset(A,0,sizeof(A))
  21. #define forn(I,B) for (int I=1;I<=(B);I++)
  22. #define forg(H,V) for (int H=first[V];h;h=next[H])
  23. #define rep(I,B) for (int I=0;I<(B);I++)
  24. #define labs(X) (((X)>0)?(X):(-(X)))
  25. #define ropen(X) freopen(X,"r",stdin)
  26. #define wopen(X) freopen(X,"w",stdout)
  27. #define rwopen(X) freopen(X".in","r",stdin);freopen(X".out","w",stdout)
  28. #define pb push_back
  29. #define mp make_pair
  30. #define all(X) (X).begin(),(X).end()
  31. #define sqr(X) ((X)*(X))
  32.  
  33. using namespace std;
  34.  
  35. typedef pair <int,int> pii;
  36. typedef double ld;
  37. typedef long long ll;
  38. typedef pair <ll,ll> pll;
  39. typedef vector<int> vi;
  40. const int N=1111;
  41. const ll INF=9187201950435737472ll;
  42. const double eps=1e-9;
  43. const double pi=3.14159265358979;
  44.  
  45. ll f[N][N],ans,mx[N],c;
  46. int a[N],l,r,n,m,w;
  47.  
  48. inline void build(int num){
  49.     mem(mx,128);
  50.     rep(i,n) mx[i]=f[num][i]-c*a[i];
  51. }
  52.  
  53. inline ll get_max(int l,int r){
  54.     ll ans=-INF;
  55.     for (int i=l;i<=r;i++) ans>?=mx[i];
  56.     return ans;
  57. }
  58.  
  59. int main(){
  60.     ropen("input.txt");
  61.     wopen("output.txt");
  62.     scanf("%d%d%d%d%d",&n,&m,&l,&r,&w);
  63.     rep(i,n) scanf("%d",&a[i]);
  64.     mem(f,128);
  65.     rep(i,n) if (a[i]>=l && a[i]<=r) f[1][i]=0;
  66.     for (int i=2;i<=m;i++){
  67.         c=(i-1)*(m-i+1);
  68.         build(i-1);
  69.         int L=0,R=0;
  70.         rep(j,n){
  71.             if (a[j]-a[L]<l) continue;
  72.             while (a[j]-a[L]>r && L<j) ++L;
  73.             if (L==j) continue;
  74.             while (a[j]-a[R+1]>=l && R<j-1) ++R;
  75.             ll t=get_max(L,R);
  76.             if (t<=-INF) f[i][j]=-INF;
  77.             else f[i][j]=t+c*a[j];
  78.         }
  79.     }
  80.     rep(i,n) if (w-a[i]>=l && w-a[i]<=r) ans>?=f[m][i];
  81.     printf("%I64d\n",ans+ans);
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment