QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#689507#7739. Knapsacki_love_qingyu#WA 0ms3816kbC++202.5kb2024-10-30 17:30:152024-10-30 17:30:15

Judging History

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

  • [2024-10-30 17:30:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-10-30 17:30:15]
  • 提交

answer

/*#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct node{
     long long int w;
     int id;
     bool operator <(const node &x)const{
         return x.w<w;
    }
};
priority_queue<node>q[40004];
long long v[40004],w[40004],dp[40004][5003];
priority_queue<int > p;
int main()
{
    int n,m,k;
    long long ans=0;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)cin>>v[i]>>w[i];
    for(int i=1;i<=n;i++)
        for(int j=m;j>=1;j--){
            for(int x=k;x>=1;x--)
                dp[j][x]=max(dp[j][x-1]+w[i],dp[j][x]);
                ans=max(dp[i][x],ans);
            if(j>=v[i])
                dp[j][0]=max(dp[j-v[i]][0]+w[i],dp[j][0]);   
        }
    for(int i=0;i<=m;i++)
        for(int x=0;x<=k;x++)
            ans=max(ans,dp[i][x]);
    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
*/
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
    int n,w,k;cin>>n>>w>>k;
    vector<vector<ll > > a(n+1,vector<ll >(2));
    for(int i=1;i<=n;++i) cin>>a[i][0] >> a[i][1];

    vector<vector<ll > > dp(n+1,vector<ll>(w+1));
    for(int i=1;i<=n;++i){
        for(int j=1;j<=w;++j){
            dp[i][j] = dp[i-1][j];
            if(j>=a[i][0]){
                dp[i][j] = max(dp[i][j],dp[i-1][j-a[i][0]]+a[i][1]);
            }
        }
    }
    vector<int> vis(n+1,0);
    for(int i=n,j=w;i>0;){
        if(dp[i][j] == dp[i-1][j]){
            i--;
        }else{
            vis[i] = 1;
            j-=a[i][0];
        }
    }
    priority_queue<int> pq;
    for(int i=1;i<=n;++i){
        if(vis[i] == 0){
            pq.push(a[i][1]);
        }
    }
    
    ll ans = dp[n][w];
    while(k && !pq.empty()){
        k--;
        ans += pq.top();
        pq.pop();
    }
    //cout<<ans;
    
    sort(a.begin()+1,a.end(),[&](const vector<ll>& p1,const vector<ll>& p2)->bool{
        return p1[1]*p2[0] > p2[1]*p1[0];
    });
    ll ans2 = 0;
    
    for(int i=1;i<=min(k,n);++i) ans2 += a[i][1];
     vector<vector<ll > > b(1,vector<ll>(1));
     for(int i=k+1;i<=n;++i) b.push_back(a[i]);
     
     int nn = b.size()-1;
     vector<vector<ll > > dp1(nn+1,vector<ll>(w+1, 0));
     for(int i=1;i<=nn;++i){
         for(int j=b[i][0];j<=w;++j){
             dp1[i][j]=dp1[i-1][j];
            dp1[i][j] = max(dp1[i][j],dp1[i-1][j-b[i][0]]+b[i][1]);
         }
     }
     ans2 += dp1[nn][w];
     cout<<max(ans2,ans)<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3660kb

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: 3612kb

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: -100
Wrong Answer
time: 0ms
memory: 3816kb

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:

3982103796

result:

wrong answer 1st numbers differ - expected: '3765024872', found: '3982103796'