#include <iostream> using namespace std; int above(int i, int j){ return (i-j + 1) * j; } int main() { short n, k, bottle, oldest; cin>>n>>k; cin>>oldest; for(int i=2; i < min(n+1, k+1); i++){ for(int j=1; j < i+1; j++){ cin>>bottle; if(bottle < oldest && above(i,j) <= k){ oldest = bottle; } } } cout<<oldest<<endl; 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 | #include <iostream> using namespace std; int above(int i, int j){ return (i-j + 1) * j; } int main() { short n, k, bottle, oldest; cin>>n>>k; cin>>oldest; for(int i=2; i < min(n+1, k+1); i++){ for(int j=1; j < i+1; j++){ cin>>bottle; if(bottle < oldest && above(i,j) <= k){ oldest = bottle; } } } cout<<oldest<<endl; return 0; } |