Submission #1188637

#TimeUsernameProblemLanguageResultExecution timeMemory
1188637mertbbmSki 2 (JOI24_ski2)C++20
9 / 100
7 ms1352 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<int,pii>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

int n,k;
pii arr[505];
vector<int>storage[505]; 
int memo[50][50][50];

int dp(int index, int take, int cur){
	if(index>2*n+1){
		if(cur==0) return 0;
		else return 1e15;
	}
	if(memo[index][take][cur]!=-1) return memo[index][take][cur];
	int ans=1e15;
	//show2(index,index,amos,amos);
	//establish a connecting point
	if(!storage[index].empty()&&take){
		for(int x=0;x<=n;x++){
			int nx=cur+storage[index].size();
			int hold=min(nx,take);
			nx-=hold;
			int ntake=take+x;
			if(ntake>n) break;
			ans=min(ans,dp(index+1,ntake,nx)+nx*k+x*storage[index][0]);
		}
	}	
	//bring everything up
	{
		int nx=cur+storage[index].size();
		int hold=min(nx,take);
		ans=min(ans,dp(index+1,take,nx-hold)+(nx-hold)*k);
	}
	//cout << index << " " << take << " " << cur << " " << amos << " " << ans << endl;
	return memo[index][take][cur]=ans;
}

void solve(){
	cin >> n >> k;
	for(int x=0;x<n;x++){
		cin >> arr[x].first >> arr[x].second;
		storage[arr[x].first].push_back(arr[x].second);
		//cnt+=arr[x].second;
	}
	
	for(int x=0;x<=n;x++) sort(storage[x].begin(),storage[x].end()); 
	
	memset(memo,-1,sizeof(memo));
	cout << dp(0,1,0);
}	
																   
int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...