QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#394754 | #1362. Bad Packing | WisdomCasual# | WA | 48ms | 788832kb | C++20 | 1.1kb | 2024-04-20 19:10:39 | 2024-04-20 19:10:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ERROR ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); fileIO();
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
void fileIO(){
#ifndef ONLINE_JUDGE
freopen("io\\input.txt", "r", stdin);
freopen("io\\output.txt", "w", stdout);
#endif
}
const ll mod = 1e9 + 7, N = 1e3 + 5, M = 1e5 + 5;
ll n, c;
ll a[N];
bool taken[N];
ll dp[N][M];
ll solve(int idx, ll rem, int mnIdx){
if(idx == n){
return (rem < a[mnIdx] || mnIdx == n? c - rem : 1e12);
}
ll& ret = dp[idx][rem];
if(~ret)
return ret;
ret = solve(idx + 1, rem, mnIdx);
if(rem >= a[idx]){
ret = min(ret, solve(idx + 1, rem - a[idx], mnIdx + (idx == mnIdx)));
}
return ret;
}
void TestCase(){
memset(dp, -1, sizeof dp);
cin >> n >> c;
for(int i = 0; i < n; i++)
cin >> a[i];
sort(a, a+n);
cout << solve(0, c, 0) << '\n';
}
int main() {
ERROR;
int t = 1;
//cin >> t;
while(t--)
TestCase();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 27ms
memory: 788788kb
input:
4 10 9 6 5 7
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 35ms
memory: 788792kb
input:
10 25 1 1 1 2 2 3 3 4 2 1
output:
20
result:
ok single line: '20'
Test #3:
score: -100
Wrong Answer
time: 48ms
memory: 788832kb
input:
77 9383 203 6771 1608 6509 3213 3597 3416 3011 2241 740 5564 3113 360 3229 5819 5589 5210 4519 5270 6067 10 9147 4171 920 8325 263 8097 3400 9214 3927 8804 4805 8388 1211 523 3799 1124 8573 7491 5527 8026 8529 2510 6430 6171 1405 4820 7662 2449 7264 1419 6320 7272 3327 7042 1517 8326 881 2199 4664 9...
output:
9332
result:
wrong answer 1st lines differ - expected: '8240', found: '9332'