Untitled

public
6shootingstar9 Apr 20, 2025 Never 17
Clone
C++ paste1.cpp 37 lines (37 loc) | 519 Bytes
1
//https://vjudge.net/contest/710802#problem/D
2
#include<bits/stdc++.h>
3
using namespace std;
4
const int N=40;
5
int v[N];
6
int V,n;
7
int dp[N];
8
int flag[N];
9
int ans;
10
int main()
11
{
12
cin>>V>>n;
13
for(int i=1;i<=n;i++)
14
{
15
cin>>v[i];
16
}
17
sort(v+1,v+1+n);
18
for(int i=1;i<=n;i++)
19
{
20
for(int j=V;j>=v[i];j--)
21
{
22
int d=dp[j];
23
dp[j]=max(dp[j],dp[j-v[i]]+1);
24
if(dp[j]!=d)
25
{
26
flag[dp[j]]=v[i];
27
}
28
}
29
}
30
ans=V;
31
for(int i=1;i<=N;i++)
32
{
33
ans-=flag[i];
34
}
35
cout<<ans;
36
return 0;
37
}