|
|
back to boardthe program gives the correct answer, but test 8 is not passed I don’t understand what the problem is when passing the test 8. everything works for me Edited by author 22.06.2022 22:21 Re: программа выдает верный ответ, но тест 8 не пройден try this: 8 6 7 9 13 18 24 31 50 expected: 0 My program do this Re: программа выдает верный ответ, но тест 8 не пройден #include <iostream> int main() { int temp = 0, maxtemp=0, even = 0, midle = 0, different = 0, maxdifferent = 0; int arrayA[100]; int sizeArray; std::cin >> sizeArray; for (int i = 0; i < sizeArray; i++) { std::cin >> arrayA[i]; } for (int i = 0; i < sizeArray; i++) { for (int j = i; j < sizeArray; j++) { if (arrayA[i] < arrayA[j]) { temp = arrayA[i]; arrayA[i] = arrayA[j]; arrayA[j] = temp; }; }; }; for (int i = 0; i < sizeArray; i++) { midle += arrayA[i]; }; even = midle % 2; maxdifferent= different= midle = midle / 2 +even; if (sizeArray != 1) { for (int i = 0; i < sizeArray; i++) { different = midle; for (int j = i; j < sizeArray; j++) { if (different >= arrayA[j]) { temp += arrayA[j]; different -= arrayA[j]; }; }; if (maxdifferent > different) { maxdifferent = different; }; }; }; maxdifferent = 2* maxdifferent -even; std::cout << maxdifferent; } |
|
|