#include<bits/stdc++.h> using namespace std; int tab[4000002]; int czy[4000002]; int main() { ios_base::sync_with_stdio(0); int n,k; cin >> n >> k; int x = 1; for(int i = 1 ; i <= n ; i++) { int ile = 0; while(ile<i) { cin >> tab[x]; x++; ile++; } } x = 2; czy[1] = 1; int cos = 0; for(int i = 2; i<= n ; i++) { int poz = 1; int temp = i-1; if(i%2==1) cos++; int jojo = 1; while(poz <= i/2) { czy[x] = (temp*(temp+1))/2 - ((temp-jojo)*(temp-jojo+1))/2; jojo++; czy[x] ++; //cout << x << " " << czy[x] << "\n"; poz++; x++; } if(i%2==1) { if(cos<0) czy[x] = ((temp+1)*temp)/2; czy[x] = ((temp+1)*temp)/2 - cos; czy[x]++; //cout << x << " " << czy[x] << "\n"; x++; poz++; } jojo = i/2; while(poz<=i) { czy[x] = (temp*(temp+1))/2 - ((temp-jojo)*(temp-jojo+1))/2; jojo--; czy[x]++; //cout << x << " " << czy[x] << "\n"; poz++; x++; } } int minn = 3000; for(int i = 1 ; i <= (n*(n+1))/2; i++) { if(czy[i] <= k) { //cout << i << " "; minn = min(minn,tab[i]); } } cout << minn; }
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | #include<bits/stdc++.h> using namespace std; int tab[4000002]; int czy[4000002]; int main() { ios_base::sync_with_stdio(0); int n,k; cin >> n >> k; int x = 1; for(int i = 1 ; i <= n ; i++) { int ile = 0; while(ile<i) { cin >> tab[x]; x++; ile++; } } x = 2; czy[1] = 1; int cos = 0; for(int i = 2; i<= n ; i++) { int poz = 1; int temp = i-1; if(i%2==1) cos++; int jojo = 1; while(poz <= i/2) { czy[x] = (temp*(temp+1))/2 - ((temp-jojo)*(temp-jojo+1))/2; jojo++; czy[x] ++; //cout << x << " " << czy[x] << "\n"; poz++; x++; } if(i%2==1) { if(cos<0) czy[x] = ((temp+1)*temp)/2; czy[x] = ((temp+1)*temp)/2 - cos; czy[x]++; //cout << x << " " << czy[x] << "\n"; x++; poz++; } jojo = i/2; while(poz<=i) { czy[x] = (temp*(temp+1))/2 - ((temp-jojo)*(temp-jojo+1))/2; jojo--; czy[x]++; //cout << x << " " << czy[x] << "\n"; poz++; x++; } } int minn = 3000; for(int i = 1 ; i <= (n*(n+1))/2; i++) { if(czy[i] <= k) { //cout << i << " "; minn = min(minn,tab[i]); } } cout << minn; } |