#include <iostream> //#include <fstream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); // std::ifstream in("0.in"); // std::streambuf *cinbuf = std::cin.rdbuf(); //save old buf // std::cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt! // while (std::cin.peek() != std::char_traits<char>::eof()) { int n, k; cin >> n; cin >> k; int lowest = 2019; int next = 0; int removeCount = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i + 1; j++) { cin >> next; removeCount = (j + 1) * (i - j + 1); if (removeCount <= k && next < lowest) { lowest = next; } } } std::cout << lowest << std::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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <iostream> //#include <fstream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); // std::ifstream in("0.in"); // std::streambuf *cinbuf = std::cin.rdbuf(); //save old buf // std::cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt! // while (std::cin.peek() != std::char_traits<char>::eof()) { int n, k; cin >> n; cin >> k; int lowest = 2019; int next = 0; int removeCount = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < i + 1; j++) { cin >> next; removeCount = (j + 1) * (i - j + 1); if (removeCount <= k && next < lowest) { lowest = next; } } } std::cout << lowest << std::endl; // } return 0; } |