QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771051#7739. KnapsackcaiwenWA 0ms3820kbC++141.5kb2024-11-22 09:11:322024-11-22 09:11:33

Judging History

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

  • [2024-11-22 09:11:33]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3820kb
  • [2024-11-22 09:11:32]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ull unsigned long long
#define ls(k) (k)<<1
#define rs(k) (k)<<1|1
#define debug(x) cout<<#x<<"="<<x<<endl
using namespace std;
const int inf=0x3f3f3f3f3f3f3f3f;
const int mod=0;
typedef pair<int,int> pii;
#define _ 5003
int preva[_],prew[_],prec[_],dp[10004];
pii it[_];
inline void subtask(){
    int n,w,k;cin>>n>>w>>k;
    for(int i=1;i<=n;i++) cin>>it[i].first>>it[i].second;
    sort(it+1,it+n+1,[](pii x,pii y){return x.second>y.second;});
    for(int i=1;i<=n;i++) preva[i]=preva[i-1]+it[i].second,prew[i]=prew[i-1]+it[i].first;
    priority_queue<int,vector<int>,greater<int>> q;
    int now=prew[k-1];
    for(int i=1;i<=k-1;i++) q.push(it[i].first);
    for(int i=k+1;i<=n;i++){
        if(!q.empty()&&it[i-1].first>q.top()){
            now-=q.top(),q.pop();
            now+=it[i-1].first;
            q.push(it[i-1].first);
        }
        prec[i]=prew[i]-(now+it[i].first);
    }
    memset(dp,-0x3f,sizeof(dp));
    dp[0]=0;
    int ans=0;
    for(int i=n;i>=k+1;i--){
        for(int j=w;j>=it[i].first;j--){
            dp[j]=max(dp[j],dp[j-it[i].first]+it[i].second);
        }
        int maxx=-inf;
        for(int j=0;j<=w-prec[i-1];j++) maxx=max(maxx,dp[j]);
        ans=max(ans,maxx+preva[i-1]);
    }
    cout<<ans;
}
signed main(){
    ios::sync_with_stdio(false);
    int t=1;//cin>>t;
    while(t--) subtask();
    return 0;
}

/*
5  20
9  10
3  5
10 1

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 10 1
9 10
10 1
3 5
5 20

output:

35

result:

ok 1 number(s): "35"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

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

output:

129

result:

ok 1 number(s): "129"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

10 50 1
44 182173741
38 163268500
36 114173760
30 521894533
25 89514235
12 516184197
42 971377551
35 28242326
31 480227821
31 388523197

output:

2009456281

result:

ok 1 number(s): "2009456281"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

10 100 3
23 51015869
9 981426050
76 243762017
64 128189636
4 718411601
48 250140255
17 340478117
68 262055220
40 370503079
4 547232664

output:

3765024872

result:

ok 1 number(s): "3765024872"

Test #5:

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

input:

10 500 10
430 981427684
100 458631577
32 453298334
393 716958962
82 120486064
393 561149128
182 518807793
293 950335710
332 159193263
331 280711850

output:

0

result:

wrong answer 1st numbers differ - expected: '5201000365', found: '0'