CodeForces 1282B2(hard version) K for the Price of One
7122 단어 cf
#include
#include
#include
using namespace std;
const int MAXN = 1e5 + 5;
int price[MAXN], dp[MAXN];
int main()
{
int T;
cin >> T;
while (T--)
{
int n, p, k;
cin >> n >> p >> k;
for (int i = 1; i <= n; ++i)
{
cin >> price[i];
dp[i] = 0;
}
sort(price + 1, price + n + 1);
for (int i = 1; i <= n; ++i)
{
if (i < k)
{
dp[i] = dp[i - 1] + price[i];
}
else
{
dp[i] = min(dp[i - k] + price[i], dp[i - 1] + price[i]);
}
}
int ans = 0;
for (int i = n; i >= 1; --i)
{
if (dp[i] <= p)
{
ans = i;
break;
}
}
cout << ans << endl;
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다: