QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97821#5606. A Musical QuestionNicolas125841WA 1ms3504kbC++141.2kb2023-04-19 01:16:362023-04-19 01:16:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-19 01:16:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3504kb
  • [2023-04-19 01:16:36]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

char dp[1001][1001];

int main(){
    cin.tie(NULL)->sync_with_stdio(false);
    
    int c, n;
    cin >> c >> n;

    for(int i = 0; i <= c; i++)
        for(int j = 0; j <= c; j++)
            dp[i][j] = '0';

    dp[0][0] = '1';

    vector<int> ar(n);
    for(int i = 0; i < n; i++)
        cin >> ar[i];

    for(int i = 0; i < n; i++){
        for(int j = c; j >= 0; j--){
            for(int k = c; k >= 0; k--){
                if(dp[j][k] == '1'){
                    if(j + ar[i] <= c)
                        dp[j + ar[i]][k] = '1';
                    if(k + ar[i] <= c)
                        dp[j][k + ar[i]] = '1'; 
                }
            }
        }
    }

    int a = 0, b = 0;

    for(int i = 0; i <= c; i++){
        for(int j = 0; j <= c; j++){
            if(dp[i][j] == '1'){
                if(i + j > a + b){
                    a = i;
                    b = j;
                }else if(i + j == a + b && abs(i - j) < abs(a - b)){
                    a = i;
                    b = j;
                }
            }
        }
    }

    cout << a << " " << b << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

100 5
10 20 40 60 85

output:

95 100

result:

wrong answer 1st lines differ - expected: '100 95', found: '95 100'