QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142376 | #1362. Bad Packing | A3bat_team_f_Masr# | AC ✓ | 1975ms | 195776kb | C++14 | 995b | 2023-08-19 00:53:08 | 2023-08-19 00:53:11 |
Judging History
answer
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
#define IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
const int N=1e5+5;
bool dp[1005][N],vis[1005][N];
int a[1005];
int mn,n,c;
bool solve(int id,int rem)
{
if(id==n+1)return rem==0;
bool &ret=dp[id][rem];
if(vis[id][rem])return ret;
vis[id][rem]=1;
ret=solve(id+1,rem);
if(rem>=a[id])ret|=solve(id+1,rem-a[id]);
return ret;
}
int main()
{
// IO
cin>>n>>c;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1);
int sum=0;
int mx=0;
for(int i=1;i<=n;i++)
{
if(sum>c)break;
mn=a[i];
int tmp=c-sum;
for(int j=0;j<mn;j++)
{
if(tmp-j<0)break;
if(solve(i+1,tmp-j))mx=max(mx,j);
}
sum+=a[i];
}
if(sum<=c)mx=max(mx,c-sum);
cout<<c-mx;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5400kb
input:
4 10 9 6 5 7
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 2ms
memory: 7532kb
input:
10 25 1 1 1 2 2 3 3 4 2 1
output:
20
result:
ok single line: '20'
Test #3:
score: 0
Accepted
time: 10ms
memory: 14600kb
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:
8240
result:
ok single line: '8240'
Test #4:
score: 0
Accepted
time: 278ms
memory: 109364kb
input:
824 23969 7843 4609 5289 4566 10073 5792 302 12573 8256 17988 3970 8311 23021 16579 1671 3350 14966 23085 328 22695 2475 10369 2503 9025 8836 18228 9352 9762 12449 14974 1952 18417 14199 6086 678 22895 6878 20552 13514 7997 2129 12092 14102 23180 1677 17904 7383 16171 20457 5006 9286 20293 3849 391 ...
output:
22757
result:
ok single line: '22757'
Test #5:
score: 0
Accepted
time: 529ms
memory: 88712kb
input:
513 66631 43554 28519 65416 34524 28051 21903 63896 40807 20665 38551 30709 18688 32956 30597 45551 47965 64494 14611 46684 3015 12488 8416 14993 57326 54031 47541 9004 34387 14317 35659 39555 1328 66004 1497 57082 56017 58711 47790 54640 16805 5518 8151 7662 2380 41637 10090 6956 15887 50246 5888 3...
output:
62976
result:
ok single line: '62976'
Test #6:
score: 0
Accepted
time: 675ms
memory: 98624kb
input:
502 89394 76142 16744 46048 12838 48682 47728 55812 53405 34692 68091 87875 22869 61257 59828 72566 3635 64530 44377 83840 36190 8947 83094 22496 25364 51793 38877 35958 60617 65938 32033 16876 85674 24519 45412 32893 23237 3916 55695 49207 65897 32823 8194 55723 55609 85905 2360 60288 81255 3153 65...
output:
84288
result:
ok single line: '84288'
Test #7:
score: 0
Accepted
time: 1975ms
memory: 195776kb
input:
1000 100000 59299 60064 91703 62516 5152 27099 97994 97251 24914 85927 42812 397 35646 95202 40753 35672 10380 31001 51581 412 53485 28943 9206 97101 34880 83927 56052 98640 90377 11447 89159 26181 8741 54488 75170 86212 52592 47943 18017 82173 55365 92379 9123 11948 13066 6664 69045 37004 43400 166...
output:
95200
result:
ok single line: '95200'