Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. От ArtemX, соревнование: Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition), задача: (B) Фродо и подушки, Неправильный ответ на претест 4, #
  3. var n,m,i,p,t,r,l:int64;data:boolean;
  4. function sum(x,y:int64):int64;
  5. begin
  6. if x>=y then
  7. sum:=(x+y)*(x-y+1) div 2
  8. else sum:=0;
  9. end;
  10. function Q(i:int64):BOOLEAN;
  11. VAR X,K,Y:INT64;
  12. BEGIN
  13. x:=i-2;
  14. k:=i;
  15. y:=n-p;
  16. if y=0 then inc(k,0)
  17. else if y<x then inc(k,sum(i-1,i-y))
  18. else inc(k,sum(i-1,2));
  19. if y>x then inc(k,y-x);
  20.  
  21. y:=p-1;
  22. if y=0 then inc(k,0)
  23. else if y<x then inc(k,sum(i-1,i-y))
  24. else inc(k,sum(i-1,2));
  25. if y>x then inc(k,y-x);
  26. if k>m then Q:=FALSe
  27. else q:=true;
  28. END;
  29. begin
  30. readln(n,m,p);
  31. i:=1;
  32. L:=1;R:=m;
  33. while ( true) do begin
  34. if l>=R then begin
  35. t:=L;
  36. if (Q(t+1)=true) then
  37. writeln(t+1)
  38. else if (Q(t)=true) then
  39. writeln(t)
  40. else writeln(t-1);
  41. break
  42. end
  43. else
  44. t:=(R+L)div 2;
  45. IF not (q(t)) then r:=t-1
  46. else l:=t+1;
  47. end;
  48. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement