#include <stdio.h> #include <vector> #define pb push_back using namespace std; typedef pair<int, int> PII; // first - in, second - ile sciagnac const int N = 2010; const int K = 2100000; int n,k,x; vector <PII> V[N]; int m = 3000; int main(){ scanf("%d%d",&n,&k); for(int i=0; i<n; i++){ for(int j=0; j<=i; j++){ scanf("%d",&x); V[i].pb({x,0}); if(i){ if(j && j<i){ V[i][j].second = V[i-1][j-1].second + V[i-1][j].second + 1; if(i>1){ V[i][j].second -= V[i-2][j-1].second; } } else if(j==0){ V[i][j].second = V[i-1][j].second + 1; } else if(j==i){ V[i][j].second = V[i-1][j-1].second + 1; } } if(V[i][j].second<k && V[i][j].first<m)m = V[i][j].first; } } printf("%d\n",m); 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 32 33 34 35 36 37 38 39 40 | #include <stdio.h> #include <vector> #define pb push_back using namespace std; typedef pair<int, int> PII; // first - in, second - ile sciagnac const int N = 2010; const int K = 2100000; int n,k,x; vector <PII> V[N]; int m = 3000; int main(){ scanf("%d%d",&n,&k); for(int i=0; i<n; i++){ for(int j=0; j<=i; j++){ scanf("%d",&x); V[i].pb({x,0}); if(i){ if(j && j<i){ V[i][j].second = V[i-1][j-1].second + V[i-1][j].second + 1; if(i>1){ V[i][j].second -= V[i-2][j-1].second; } } else if(j==0){ V[i][j].second = V[i-1][j].second + 1; } else if(j==i){ V[i][j].second = V[i-1][j-1].second + 1; } } if(V[i][j].second<k && V[i][j].first<m)m = V[i][j].first; } } printf("%d\n",m); return 0; } |