ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1005. Stone Pile

the program gives the correct answer, but test 8 is not passed
Posted by Teplotehnik 22 Jun 2022 18:21
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 не пройден
Posted by Teplotehnik 22 Jun 2022 19:37
try this:
8
6 7 9 13 18 24 31 50

expected: 0

My program do this
Re: программа выдает верный ответ, но тест 8 не пройден
Posted by Teplotehnik 22 Jun 2022 20:54
#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;
}