QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#142369 | #1362. Bad Packing | A3bat_team_f_Masr# | WA | 1ms | 5648kb | C++14 | 962b | 2023-08-19 00:38:16 | 2023-08-19 00:38:17 |
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=0;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];
}
cout<<c-mx;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5512kb
input:
4 10 9 6 5 7
output:
5
result:
ok single line: '5'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5648kb
input:
10 25 1 1 1 2 2 3 3 4 2 1
output:
25
result:
wrong answer 1st lines differ - expected: '20', found: '25'