Pagini recente » Cod sursa (job #671729) | Cod sursa (job #2496702) | Cod sursa (job #2989614) | Cod sursa (job #2578484) | Cod sursa (job #3225486)
#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream fin("multimi2.in");
ofstream fout("multimi2.out");
int main()
{
long long n;
fin >> n;
long long totalSum = n * (n + 1) / 2;
long long halfSum = totalSum / 2;
int firstSet[n], secondSet[n];
int firstSetSize = 0, secondSetSize = 0;
long long s1 = 0;
for (int i = n; i > 0; i--)
{
if (s1 + i <= halfSum)
{
firstSet[firstSetSize++] = i;
s1 += i;
}
else
{
secondSet[secondSetSize++] = i;
}
}
// Calculate the absolute difference
long long dif = abs(s1 - (totalSum - s1));
// Output the difference and the first subset
fout << dif << endl;
fout << firstSetSize << endl;
for (int i = 0; i < firstSetSize; i++)
{
fout << firstSet[i] << ' ';
}
fout << endl;
// Output the second subset
fout << secondSetSize << endl;
for (int i = 0; i < secondSetSize; i++)
{
fout << secondSet[i] << ' ';
}
fin.close();
fout.close();
return 0;
}