QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#689964#7739. Knapsacki_love_qingyuWA 0ms3836kbC++20933b2024-10-30 19:27:532024-10-30 19:27:54

Judging History

你现在查看的是最新测评结果

  • [2024-10-30 19:27:54]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3836kb
  • [2024-10-30 19:27:53]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node{
    long long int v,w;
}e[1000005];
bool cmp(struct node a,struct node b){
    return a.v<b.v;
}
long long dp[10004];
int main()
{
    int n,m,k;
    long long ans=0;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>e[i].v>>e[i].w;
    sort(e+1,e+1+n,cmp);
    vector<ll> suf(n+2);
    priority_queue<ll,vector<ll>,greater<ll> > pq;
    ll sum = 0;
    for(int i=n;i;--i){
        pq.push(e[i].v);
        sum += e[i].v;
        while(pq.size() > k){
            sum -= pq.top();
            pq.pop();
        }
        suf[i] = sum;
    }
    for(int i=1;i<=n;i++)
        for(int j=m;j>=e[i].v;j--){
            dp[j]=max(dp[j-e[i].v]+e[i].w,dp[j]);
            ans=max(ans,dp[j]+suf[i+1]);
        }
    
    cout<<ans;
    return 0;
}
/*
5 13 2
5 16
5 28
7 44
8 15
8 41
4 10 1
9 10
10 1
3 5
5 20
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3836kb

input:

4 10 1
9 10
10 1
3 5
5 20

output:

35

result:

ok 1 number(s): "35"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3832kb

input:

5 13 2
5 16
5 28
7 44
8 15
8 41

output:

88

result:

wrong answer 1st numbers differ - expected: '129', found: '88'