Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int n;
- cin >> n; // кол-во
- int x;
- int max0 = -1; // ЧЕТ !17
- int max1 = -1; // НЕЧЕТ !17
- int max17_0 = -1; // ЧЕТ 17
- int max17_1 = -1; // НЕЧЕТ 17
- for (int i = 0; i < n; ++i)
- {
- cin >> x;
- if (x % 17 == 0) {
- if (x % 2 == 0) {
- if (x > max17_0) {
- max17_0 = x;
- }
- else if (x == max17_0) {
- max0 = x;
- }
- }
- else {
- if (x > max17_1) {
- max17_1 = x;
- }
- else if (x == max17_1) {
- max1 = x;
- }
- }
- }
- else {
- if (x % 2 == 0) {
- if (x > max0)
- max0 = x;
- }
- else {
- if (x > max1) {
- max1 = x;
- }
- }
- }
- }
- if(max0 == -1 || max17_0 == -1) {
- if(max1 == -1 || max17_1 == -1) {
- cout << "0" << "0" << endl; // оба невалидны
- }
- else {
- cout << max1 + max17_1 << endl; // валидна только вторая пара
- }
- }
- else {
- if (max1 == -1 || max17_1 == -1) {
- cout << max0 + max17_0 << endl; // валидна только первая пара
- }
- else {
- if (max1 + max17_1 > max0 + max17_0) {
- cout << max1 + max17_1 << endl; // здоровая конкуренция
- }
- else {
- cout << max0 + max17_0 << endl; // здоровая конкуренция
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement