Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- От ArtemX, соревнование: Codeforces Round #393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition), задача: (B) Фродо и подушки, Неправильный ответ на претест 4, #
- var n,m,i,p,t,r,l:int64;data:boolean;
- function sum(x,y:int64):int64;
- begin
- if x>=y then
- sum:=(x+y)*(x-y+1) div 2
- else sum:=0;
- end;
- function Q(i:int64):BOOLEAN;
- VAR X,K,Y:INT64;
- BEGIN
- x:=i-2;
- k:=i;
- y:=n-p;
- if y=0 then inc(k,0)
- else if y<x then inc(k,sum(i-1,i-y))
- else inc(k,sum(i-1,2));
- if y>x then inc(k,y-x);
- y:=p-1;
- if y=0 then inc(k,0)
- else if y<x then inc(k,sum(i-1,i-y))
- else inc(k,sum(i-1,2));
- if y>x then inc(k,y-x);
- if k>m then Q:=FALSe
- else q:=true;
- END;
- begin
- readln(n,m,p);
- i:=1;
- L:=1;R:=m;
- while ( true) do begin
- if l>=R then begin
- t:=L;
- if (Q(t+1)=true) then
- writeln(t+1)
- else if (Q(t)=true) then
- writeln(t)
- else writeln(t-1);
- break
- end
- else
- t:=(R+L)div 2;
- IF not (q(t)) then r:=t-1
- else l:=t+1;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement