QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#331357#1362. Bad Packingaggrovector#WA 1ms5732kbC++141.3kb2024-02-18 06:06:012024-02-18 06:06:01

Judging History

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

  • [2024-02-18 06:06:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5732kb
  • [2024-02-18 06:06:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
long long n,c,i,j,dp[1005][100005],a[1005],ans;
priority_queue<long long,vector<long long>,greater<long long>> q;

int main() {
    cin >> n >> c;
    for (i=1;i<=n;i++) {
        cin >> a[i];
    }
    sort(a+1,a+1+n);
    for (i=1;i<=n/2;i++) {
        swap(a[i],a[n+1-i]);
    }
    // for (i=1;i<=n;i++) {
    //     cout << a[i] << ' ';
    // }
    // cout << endl;
    dp[0][0]=1;
    for (i=1;i<=n;i++) {
        for (j=0;j<=c;j++) {
            dp[i][j]=dp[i-1][j];
            if (j-a[i]>=0 && dp[i-1][j-a[i]]==1) {
                dp[i][j]=1;
            }
        }
    }
    // for (i=0;i<=n;i++) {
    //     for (j=0;j<=c;j++) {
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << endl;
    // }
    for (i=n;i>=0;i--) {
        if (i==n) {
            for (j=c;j>=0;j--) {
                if (dp[i][j]==1) {
                    ans=j;
                    break;
                }
            }
        }
        else {
            q.push(a[i+1]);
            for (j=0;j<=c;j++) {
                if (dp[i][j]==1 && j+q.top()>c) {
                    // cout << i << ' ' << j << ' ' << q.top() << endl;
                    ans=min(ans,j);
                }
            }
        }
    }
    cout << ans << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5732kb

input:

4 10
9
6
5
7

output:

6

result:

wrong answer 1st lines differ - expected: '5', found: '6'