Pagini recente » Cod sursa (job #1400332) | Cod sursa (job #2525415) | Cod sursa (job #2581075) | Cod sursa (job #542179) | Cod sursa (job #3134410)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("farfurii.in");
ofstream g("farfurii.out");
long long numberOfPlates, remainingPositions, i;
int main() {
f >> numberOfPlates >> remainingPositions;
// gasim primele i farfurii care vor fi asezate in ordine crescatoare
for(i = 1; (numberOfPlates - i) * (numberOfPlates - i - 1) / 2 > remainingPositions; ++i)
g << " " << i;
//gasim farfuria de la poz dif+i
long long difference = remainingPositions - ((numberOfPlates - i) * (numberOfPlates - i - 1) / 2);
g << " " << difference + i;
//afisam farfuriile ramase in ord desc
for (long long currPlate = numberOfPlates; currPlate >= i; --currPlate) {
if (currPlate != i + difference) {
g << " " << currPlate;
}
}
f.close();
g.close();
return 0;
}