Untitled
unknown
c_cpp
9 months ago
1.3 kB
7
Indexable
//OMI_14
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define faster \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using namespace std;
// unordered_map<ll, ll> mp;
// mp.reserve(1024);
// mp.max_load_factor(1);
ll func(int i,int k,vector<ll>& a,int n,int w,vector<vector<ll>>& dp){
if(k==0)return 0;
if(i==n)return 0;
if(dp[i][k]!=-1)return dp[i][k];
ll x=0,y=0;
auto it=upper_bound(a.begin(),a.end(),a[i]+w);
int inx=it-a.begin();
if(it==a.end()){
x=func(inx,k-1,a,n,w,dp)+(inx-i-1);
}else
{
x=func(inx,k-1,a,n,w,dp)+(inx-i);
}
y=func(i+1,k,a,n,w,dp);
return dp[i][k]=max(x,y);
}
int main() {
faster;
// freopen("input.txt","r",stdin);
// freopen("output1.txt","w",stdout);
int t;
cin>>t;
int j=0;
while (t--)
{
int n,w,k;
cin>>n>>w>>k;
vector<ll>a(n);
for (int i = 0; i < n; i++)
{
ll x,y;
cin>>x>>y;
a[i]=y;
}
cout << "Case " << j + 1 << ": ";
j++;
sort(a.begin(),a.end());
vector<vector<ll>>dp(n+1,vector<ll>(k+1,-1));
cout<<func(0,k,a,n,w,dp)+1<<"\n";
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
Editor is loading...
Leave a Comment