提交时间:2023-04-10 13:35:40

运行 ID: 73839

/* * __----~~~~~~~~~~~------___ * . . ~~//====...... __--~ ~~ * -. \_|// |||\\ ~~~~~~::::... /~ * ___-==_ _-~o~ \/ ||| \\ _/~~- * __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ * _-~~ .=~ | \\-_ '-~7 /- / || \ / * .~ .~ | \\ -_ / /- / || \ / * / ____ / | \\ ~-_/ /|- _/ .|| \ / * |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ * ' ~-| /| |-~\~~ __--~~ * |-~~-_/ | | ~\_ _-~ /\ * / \ \__ \/~ \__ * _--~ _/ | .-~~____--~-/ ~~==. * ((->/~ '.|||' -_| ~~-/ , . _|| * -_ ~\ ~~---l__i__i__i--~~_/ * _-~-__ ~) \--______________--~~ * //.-~~~-~_--~- |-------~~~~~~~~ * //.-~~~--\ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * \|/ */ #include<stdio.h> #include<iostream> #include<stack> using namespace std; const int N=2e4+10; inline int read(char ch=getchar(),int n=0,int m=1) { while(ch<'0' or ch>'9') { if(ch=='-')m=-1; ch=getchar(); } while(ch>='0' and ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=getchar(); return n*m; } ostream& operator <<(ostream& o,__uint128_t &a) { __uint128_t x=a; stack<int>s; while(x)s.push(x%10),x/=10; while(!s.empty())o<<s.top(),s.pop(); return o; } int v=read(),n=read(),a[N],f[N]; signed main() { for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++) for(int j=v;j>=a[i];j--)f[j]=max(f[j],f[j-a[i]]+a[i]); cout<<v-f[v]; return 0; }