#include <iostream> using namespace std; int tab[1000*2001],n,k,a,minimum=2020,iter=1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>k; tab[0]=1; cin>>a; minimum=min(minimum, a); for(int i=2;i<=n;++i) { for(int j=0;j<i;++j,iter++) { if(j==0)tab[iter]=tab[iter-1]+1; else if(j+1==i)tab[iter]=tab[iter-i]+1; else { tab[iter]=tab[iter-i]+tab[iter-i+1]-tab[iter-2*i+2]+1; } cin>>a; if(tab[iter]<=k&&a<minimum)minimum=a; } } cout<<minimum; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include <iostream> using namespace std; int tab[1000*2001],n,k,a,minimum=2020,iter=1; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin>>n>>k; tab[0]=1; cin>>a; minimum=min(minimum, a); for(int i=2;i<=n;++i) { for(int j=0;j<i;++j,iter++) { if(j==0)tab[iter]=tab[iter-1]+1; else if(j+1==i)tab[iter]=tab[iter-i]+1; else { tab[iter]=tab[iter-i]+tab[iter-i+1]-tab[iter-2*i+2]+1; } cin>>a; if(tab[iter]<=k&&a<minimum)minimum=a; } } cout<<minimum; return 0; } |