Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 – Final Round Div. 2 Edition), problem: (B) Frodo and pillows Solution in C/C++

#include <stdio.h>

int main()
{
int n, m, k, h, l, r;

scanf(“%d %d %d”, &n, &m, &k);

l = r = k;

h = 1;
m -= n;
while (m – (r – l + 1) >= 0 && !(l == 1 && r == n)) {
h++;
m -= r – l + 1;
if (r < n)
r++;
if (l > 1)
l–;
}

if (l == 1 && r == n)
h += m / n;

printf(“%d”, h);

return 0;
}

(Visited 85 times, 1 visits today)

About the Author:

Leave A Comment