const
fin = 'szero.inp'; fon = 'szero.out';
maxn = 100000;vc=10000000;
type pt = record
cs:longint;gt:int64;
end;
var
a:array[1..maxn] of longint;
s:array[0..maxn] of pt;
n,i,k,j,im,jm:longint;
procedure nhap;
var i:longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
end;
procedure tinh_s;
var i:longint;
begin
s[0].gt:=0;s[0].cs:=0;
for i:=1 to n do
begin
s[i].cs:=i;
s[i].gt:=s[i-1].gt+a[i];
end;
end;
function ss(x,y:pt):boolean;
begin
if x.gt<y.gt then exit(true);
if x.gt>y.gt then exit(false);
if x.cs<y.cs then exit(true);
if x.cs>y.cs then exit(false);
exit(false);
end;
procedure qs(l,h:longint);
var i,j:longint;
x,t:pt;
begin
x:=s[l+random(h-l+1)];
i:=l;j:=h;
repeat
while ss(s[i],x)=true do inc(i);
while ss(x,s[j])=true do dec(j);
if i<=j then
begin
t:=s[i]; s[i]:=s[j]; s[j]:=t;
inc(i); dec(j);
end;
until i>j;
if L<j then qs(L,j);
if i<H then qs(i,H);
end;
procedure xl;
var i,k,x,y:longint;
begin
tinh_s;
qs(0,n);
k:=0;x:=0;y:=0;
for i:=1 to n do
begin
if s[i].gt<>s[i-1].gt then //ket thuc 1 doan
k:=i;
if s[i].cs-s[k].cs>s[y].cs-s[x].cs then
begin
x:=k;
y:=i;
end;
end;
write(s[x].cs+1,' ',s[y].cs);
end;
begin
randomize;
assign(input,fin);reset(input);
assign(output,fon);rewrite(output);
nhap;
xl;
end.
* Chuyên dạy lập trình ONLINE cho học sinh THCS, THPT *.
Mọi giao lưu, trao đổi, xin liên hệ: Lê Quang Vinh - zalo: 037.803.8755.
Page: Lớp học Code Sky
Group FB1: Ôn thi HSG9 - THTB - TS10 chuyên tin
Group FB2: Học Scratch - Ôn thi Tin học trẻ bảng A
Thứ Ba, 3 tháng 5, 2022
SZERO PASCAL
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét
Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.