Problem:
Problem H:
Ropeway
On a small island, there are two towns Darkside and Sunnyside, with steep mountains between them. There’s a company Intertown Company of Package Conveyance; they own a ropeway car between Darkside and Sunnyside and are running a transportation business. They want maximize the revenue by loading as much package as possible on the ropeway car.
The ropeway car looks like the following. It’s
L
length long, and the center of it is hung from the rope. Let’s suppose the car to be a 1-dimensional line segment, and a package to be a point lying on the line. You can put packages at anywhere including the edge of the car, as long as the distance between the package and the center of the car is greater than or equal to R and the car doesn’t fall down.
The car will fall down when the following condition holds:
Here
N
is the number of packages;
m
i
the weight of the
i
-th package;
x
i
is the position of the
i
-th package relative to the center of the car.
You, a Darkside programmer, are hired as an engineer of the company. Your task is to write a program which reads a list of package and checks if all the packages can be loaded in the listed order without the car falling down at any point.
Input
The input has two lines, describing one test case. The first line contains four integers
N
,
L
,
M
,
R
. The second line contains
N
integers
m
0
,
m
1
, ...
m
N
-1
. The integers are separated by a space.
Output
If there is a way to load all the packages, output “Yes” in one line, without the quotes. Otherwise, output “No”.
Sample Input 1
3 3 2 1
1 1 4
Output for the Sample Input 1
Yes
Sample Input 2
3 3 2 1
1 4 1
Output for the Sample Input 2
No

Submitted solutions:

code_snippet: #include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
typedef long long ll;
#define clr(x,a) memset(x,a,sizeof(x))
#define sz(x) (int)x.size()
#define see(x) cerr<<#x<<" "<<x<<endl
#define se(x) cerr<<" "<<x
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for (long long i=l;i<=r;i++)
using namespace std;
int n,l,m,r,a[1010000],ans;
void dfs(int ll,int rr,int i){
    if (i>n) {
        ans=1;return;
    }
    if (ll+r*a[i]<=m)
        dfs(ll+r*a[i],min(m,rr+l*a[i]),i+1);
    if (rr-r*a[i]>=-m)
        dfs(max(-m,ll-l*a[i]),rr-r*a[i],i+1);
}
int main(){
    scanf("%d%d%d%d",&n,&l,&m,&r);
    if (2*r>l) {
        printf("No\n");
        return 0;
    }
    rep(i,1,n) scanf("%d",a+i);
    ans=0;
    r*=2;m*=2;
    dfs(0,0,1);
    if (ans) printf("Yes\n");
        else printf("No\n");
    return 0;
}
accuracy: 0.1568627450980392
time_ms: 1460
memory_kb: 1172
final_rank: 10

code_snippet: #include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
typedef long long ll;
#define clr(x,a) memset(x,a,sizeof(x))
#define sz(x) (int)x.size()
#define see(x) cerr<<#x<<" "<<x<<endl
#define se(x) cerr<<" "<<x
#define pb push_back
#define mp make_pair
#define rep(i,l,r) for (long long i=l;i<=r;i++)
using namespace std;
int n,l,m,r,a[101000],ans;
void dfs(int ll,int rr,int i){
    if (i>n) {
        ans=1;return;
    }
    if (ll+r*a[i]<=m)
        dfs(ll+r*a[i],min(m,rr+l*a[i]),i+1);
    if (rr-r*a[i]>=-m)
        dfs(max(-m,ll-l*a[i]),rr-r*a[i],i+1);
}
int main(){
    scanf("%d%d%d%d",&n,&l,&m,&r);
    rep(i,1,n) scanf("%d",&a[i]);
    ans=0;
    r*=2;m*=2;
    dfs(0,0,1);
    if (ans) printf("Yes\n");
        else printf("No\n");
    return 0;
}
accuracy: 0.1568627450980392
time_ms: 1490
memory_kb: 1172
final_rank: 11

code_snippet: #include<iostream>

using namespace std;

#define int long long

int pos[123][42345];
int O=20000;

signed main(){
  int N,L,M,R;
  cin>>N>>L>>M>>R;
  pos[0][O]=1;
  bool can[123]={};
  for(int i=0;i<N;i++){
    int m;
    cin>>m;
    int mx=2*M;
    for(int j=-mx;j<=mx;j++){
      if(pos[i][j+O]){
	int lh=j-2*R*m;
	if(-mx<=lh){
	  pos[i+1][O+max(-mx,j-L*m)]++;
	  pos[i+1][O+lh+1]--;
	}
	int hl=j+2*R*m;
	if(hl<=mx){
	  pos[i+1][O+hl]++;
	  int hh=j+L*m;
	  if(hh+1<=mx){
	    pos[i+1][O+hh+1]--;
	  }
	}
      }
    }
    can[i+1]=pos[i+1][-mx+O];
    for(int j=-mx+1+O;j<=mx+O;j++){
      pos[i+1][j]+=pos[i+1][j-1];
      can[i+1]|=pos[i+1][j];
    }
  }
  cout<<(can[N]?"Yes":"No")<<endl;
}
accuracy: 1
time_ms: 20
memory_kb: 35580
final_rank: 8

code_snippet: #include<iostream>

using namespace std;

int pos[123][42345];
int O=20000;

int main(){
  int N,L,M,R;
  cin>>N>>L>>M>>R;
  pos[0][O]=1;
  bool can[123]={};
  for(int i=0;i<N;i++){
    int m;
    cin>>m;
    int mx=2*M;
    for(int j=-mx;j<=mx;j++){
      if(pos[i][j+O]){
	int lh=j-2*R*m;
	if(-mx<=lh){
	  pos[i+1][O+max(-mx,j-L*m)]++;
	  pos[i+1][O+lh+1]--;
	}
	int hl=j+2*R*m;
	if(hl<=mx){
	  pos[i+1][O+hl]++;
	  int hh=j+L*m;
	  if(hh+1<=mx){
	    pos[i+1][O+hh+1]--;
	  }
	}
      }
    }
    can[i+1]=pos[i+1][-mx+O];
    for(int j=-mx+1+O;j<=mx+O;j++){
      pos[i+1][j]+=pos[i+1][j-1];
      can[i+1]|=pos[i+1][j];
    }
  }
  cout<<(can[N]?"Yes":"No")<<endl;
}
accuracy: 0.1568627450980392
time_ms: 10
memory_kb: 1172
final_rank: 9

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const long long N = 10000;
vector<long long> f[N];
vector<long long> pack;
long long n, l, m ,r;

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> l >> m >> r;
	l *= 2; m *= 2; r *= 2;
	for (long long i = 0; i <= n; ++i)
		f[i] = vector<long long>(m + 10, 0);
	for (long long i = 0; i < n; ++i) {
		long long weight;
		cin >> weight;
		pack.push_back(weight);
	}
	f[0][0] = 1;
	f[0][1] = -1;
	for (long long i = 0; i <= n; ++i) {
		for (long long j = 1; j <= m; ++j)
			f[i][j] += f[i][j - 1];
		if (i == n) break;
		for (long long j = 0; j <= m; ++j) {
			if (!f[i][j]) continue;
			long long kl = r * pack[i], kr = l / 2 * pack[i];
			long long cl, cr;
			//part1
			if(j - kl >= 0 && j - kr >= 0) {
				cl = j - kr;
				cr = j - kl;
			} else if (j - kl <= 0 && j - kr <= 0) {
				cl = abs(j - kl);
				cr = abs(j - kr);
			} else {
				cl = 0;
				cr = max(abs(j - kr), abs(j - kl));
			}
			if(cl <= m) {
				cr = min(cr, m);
				f[i + 1][cl]++;
				f[i + 1][cr + 1]--;
			}
			//part2
			cl = j + kl, cr = j + kr;
			if(cl <= m) {
				cr = min(cr, m);
				f[i + 1][cl]++;
				f[i + 1][cr + 1]--;
			}
					
		}
	}
	for (long long i = 0; i <= m; ++i)
		if (f[n][i]) {
			cout << "Yes" << endl;
			return 0;
		}
	cout << "No" << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 17388
final_rank: 6

code_snippet: #include<stdio.h>
#include<algorithm>
using namespace std;
int dp[110][41000];
int p[110];
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
		if(p[i]>20100){
			printf("No\n");return 0;
		}
	}
	c*=2;
	d*=2;
	dp[0][c]=1;
	for(int i=0;i<a;i++){
		int L=d*p[i];
		int R=b*p[i];
		if(L>2*c)break;
		if(R>2*c)R=2*c;
		for(int j=0;j<=2*c;j++){
			if(!dp[i][j])continue;
			if(j-L+1>=0){
				dp[i+1][max(0,j-R)]++;
				dp[i+1][max(0,j-L+1)]--;
			}
			dp[i+1][min(2*c+1,j+L)]++;
			dp[i+1][min(2*c+1,j+R+1)]--;
		}
		for(int j=1;j<=2*c;j++){
			dp[i+1][j]+=dp[i+1][j-1];
		}
		for(int j=0;j<=2*c;j++)dp[i+1][j]=!!dp[i+1][j];
	//	for(int j=0;j<=2*c;j++)printf("%d ",dp[i+1][j]);
		//printf("\n");
	}
	bool ok=false;
	for(int i=0;i<=2*c;i++)if(dp[a][i])ok=true;
	if(ok)printf("Yes\n");
	else printf("No\n");
}
accuracy: 1
time_ms: 30
memory_kb: 17232
final_rank: 7

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep1(i,n) for(ll i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef long long ll;
bool dp[40001];
ll imos[40002];
int main(){
	ll N,L,M,R;
	cin>>N>>L>>M>>R;
	L*=2,M*=2,R*=2;
	dp[M]=true;
	rep1(j,40001) imos[j+1]=imos[j]+(dp[j]?1:0);
	rep1(i,N){
		ll m;
		cin>>m;
		ll mn=m*R,mx=m*L/2;
//		show(i);
		rep(j,2*M+1){
			ll l=max(0LL,j-mx),r=j-mn;
			dp[j]=false;
			if(r>=0) if(imos[r+1]-imos[l]>0) dp[j]=true;
			l=j+mn,r=min(j+mx,M*2);
			if(l<=M*2) if(imos[r+1]-imos[l]>0) dp[j]=true;
//			cout<<"j:"<<j<<"  ";
//			show(dp[j]);
		}
//		cout<<endl;
		rep(j,40001) imos[j+1]=imos[j]+(dp[j]?1:0);
	}
	cout<<(imos[2*M]>0?"Yes\n":"No\n");
}
accuracy: 1
time_ms: 20
memory_kb: 1468
final_rank: 3

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



ll N, L, M, R;
ll m[105];

int dp[105][20100];

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    while (cin >> N >> L >> M >> R) {
        for (int i = 0; i < N; ++i) cin >> m[i];
        memset(dp, 0, sizeof(dp));
        R *= 2;
        M *= 2;
        
        dp[0][0] = 1;
        for (int i = 0; i <= N; ++i) {
            for (int j = 0; j <= M; ++j) {
                //cout << i << ", " << j << " : " << dp[i][j] << endl;
                
                if (dp[i][j] <= 0) continue;
                
                ll l1 = max(0LL, j + m[i]*R);
                ll r1 = min(M, j + m[i]*L) + 1;
                ll l2, r2;
                if (j - m[i]*L >= 0) {l2 = j - m[i]*L; r2 = min(M, j - m[i]*R) + 1;}
                else if (j - m[i]*R >= 0) {l2 = 0; r2 = min(M, max(abs(j - m[i]*L), abs(j - m[i]*R))) + 1;}
                else {l2 = abs(j - m[i]*R); r2 = min(M, abs(j - m[i]*L)) + 1;}
                
                if (l1 <= r1) {
                    dp[i+1][l1]++; dp[i+1][r1]--;
                }
                if (l2 <= r2) {
                    dp[i+1][l2]++; dp[i+1][r2]--;
                }
            }
            for (int j = 0; j <= M; ++j) {
                dp[i+1][j+1] += dp[i+1][j];
            }
        }
        
        bool exist = false;
        for (int i = 0; i <= M; ++i) {
            if (dp[N][i] > 0) {exist = true; break;}
        }
        
        if (exist) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 9408
final_rank: 4

code_snippet: #include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

ll m[1000];
bool dp[40010];
bool next[40010];

int main() {
  ll N,L,M,R;
  cin>>N>>L>>M>>R;
  REP(i,N) cin >> m[i];
  R*=2;
  L*=2;
  M*=2;
  ll MM = 2*M;
  dp[M] = 1;
  REP(i,N) {
    REP(j,MM+1)next[j]=0;
    ll ma = m[i]*L/2;
    ll mi = m[i]*R;
    REP(j,MM+1) {
      if (dp[j]) {
        // 右
        if (j+mi<=MM) {
          next[min(MM,j+ma)]=1;
          next[j+mi]=1;
        }
        // 左
        if (j-mi>=0) {
          next[max(0LL,j-ma)]=1;
          next[j-mi]=1;
        }
      }
    }
    bool f = 0;
    REP(j,MM+1) {
      dp[j]=next[j];
      f|=dp[j];
    }
    // REP(j,MM+1)cout<<dp[j]<<" ";cout<<endl;
    if (!f) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))


struct FenwickTree {
  static const int SIZE = 60000;
  int tree[SIZE + 10];
  FenwickTree() { memset(tree, 0, sizeof(tree)); }
  void add(int index, int value) {
    for (index += SIZE / 2; index < SIZE + 1; index += (index & -index)) {
      tree[index] += value;
    }
  }
  int sum(int index) {
    int ret = 0;
    for (index += SIZE / 2; index > 0; index -= (index & -index)) {
      ret += tree[index];
    }
    return ret;
  }
};

int n;
ll l, m, r;
ll seq[110];
FenwickTree ftree[2];

int main() {
  while (scanf("%d %lld %lld %lld", &n, &l, &m, &r) > 0) {
    m *= 2;
    r *= 2;
    REP(i, n) {
      scanf("%lld", &seq[i]);
    }
    ftree[0] = FenwickTree();
    ftree[1] = FenwickTree();
    ftree[0].add(0, 1);
    ftree[0].add(1, -1);
    REP(i, n) {
      int prev = i & 1;
      int next = prev ^ 1;
      ftree[next] = FenwickTree();
      ll l1 = -l * seq[i];
      ll r1 = -r * seq[i];
      ll l2 = r * seq[i];
      ll r2 = l * seq[i];
      FOREQ(w, -m, m) {
        if (ftree[prev].sum(w) == 0) { continue; }
        ll l, r;
        l = max(-m - 1, min(m + 1, l1 + w));
        r = max(-m - 1, min(m + 1, r1 + w));
        ftree[next].add(l, 1);
        ftree[next].add(r + 1, -1);
        l = max(-m - 1, min(m + 1, l2 + w));
        r = max(-m - 1, min(m + 1, r2 + w));
        ftree[next].add(l, 1);
        ftree[next].add(r + 1, -1);
      }
      bool ok = false;
      FOREQ(w, -m, m) {
        if (ftree[next].sum(w) >= 1) { ok = true; }
        //putchar(ftree[next].sum(w) > 0 ? 'o' : 'x');
      }
      //puts("");
      if (!ok) { goto ng; }
    }
    puts("Yes");
    continue;
ng:
    puts("No");
  }
}
accuracy: 1
time_ms: 570
memory_kb: 2012
final_rank: 5

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;
const int M = 40011;
bool dp[2][M];
bool solve(int n,ll *in,int m,int L,int R){
  int now=0;
  int allm=4*m+1;
  rep(i,M)dp[0][i]=dp[1][i]=false;
  dp[0][2*m]=true;

  rep(i,n){
    int next=(now+1)%2;
    rep(j,allm){
      if (!dp[now][j])continue;

      if ( j-R*in[i]*2 >= 0){
	//cout << j <<" " << j-L*in[i] << " " << j-R*in[i]*2 << endl;
	dp[next][max(0LL,  j-L*in[i])]=true;//j+(-L/2*mi+m)*2;
	dp[next][        j-R*in[i]*2]=true;//j+(-R*mi  +m)*2;
      }

      if (j+R*in[i]*2 <= 4*m){
	//cout << j <<" " << j+L*in[i] << " " << j+R*in[i]*2 << endl;
	dp[next][min(4LL*m,j+L*in[i])]=true;//j+(L/2*mi+m)*2;
	dp[next][        j+R*in[i]*2]=true;//j+(R*mi  +m)*2;
      }
    }
    //rep(j,allm)cout << dp[next][j]<<" ";cout << endl;
    rep(j,allm)dp[now][j]=false;
    now=next;
  }
  
  rep(i,allm){
    if (dp[now][i])return true;
  }
  return false;
}

const int N = 100;
ll in[N];
main(){
  int n,l,m,r;
  while(cin>>n>>l>>m>>r){
    rep(i,n)cin>>in[i];
    cout << (solve(n,in,m,l,r)?"Yes":"No") << endl;
  }
  return false;
}
accuracy: 1
time_ms: 20
memory_kb: 0
final_rank: 2