QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#97821 | #5606. A Musical Question | Nicolas125841 | WA | 1ms | 3504kb | C++14 | 1.2kb | 2023-04-19 01:16:36 | 2023-04-19 01:16:37 |
Judging History
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'