- 推销员
- 2016-07-24 10:31:41 @
var
n,i,j,temp,tempnow1,tempnow2,tot,max1,max2,temp2,m:longint;
a,s,k,idx,idx2,idxid,idx2id,b:array[-1..100001] of longint;
Function lowbit(x:longint):longint;
begin
exit(x and -x);
end;
Procedure update(i,x:longint);
var
j:longint;
begin
j:=i;
while i<=n do
begin
if idx[i]<x then begin idx[i]:=x; idxid[i]:=j; end;
inc(i,lowbit(i));
end;
end;
Procedure update2(i,x:longint);
var
j:longint;
begin
j:=i;
while i<=n do
begin
if idx2[i]<x then begin idx2[i]:=x; idx2id[i]:=j; end;
inc(i,lowbit(i));
end;
end;
Function query(l,r:longint):longint;
var
ret:longint;
begin
ret:=a[r];
tempnow1:=idxid[r];
while l<=r do
begin
if r-lowbit(r)+1>=l then
begin
if ret<idx[r] then
begin
ret:=idx[r];
tempnow1:=idxid[r];
end;
r:=r-lowbit(r);
end else
begin
if ret<a[r] then
begin
ret:=a[r];
tempnow1:=idxid[r];
end;
dec(r);
end;
end;
exit(ret);
end;
Function query2(l,r:longint):longint;
var
ret:longint;
begin
//ret:=k[r]-2*s[temp];
//tempnow2:=idx2id[r];
ret:=0;
while l<=r do
begin
if (r-lowbit(r)+1)>=l then
begin
if ret<idx2[r]-2*s[temp] then begin ret:=idx2[r]-2*s[temp]; tempnow2:=idx2id[r]; end;
r:=r-lowbit(r);
end else
begin
if ret<k[r]-2*s[temp] then
begin
ret:=k[r]-2*s[temp];
tempnow2:=idx2id[r];
end;
dec(r);
end;
end;
exit(ret);
end;
Procedure modify(p:longint);
var
i,j:longint;
begin
i:=p; a[i]:=0;
while i<=n do
begin
idx[i]:=a[i]; idxid[i]:=i;
j:=1;
while j<lowbit(i) do
begin
if idx[i]<idx[i-j] then begin idx[i]:=idx[i-j]; idxid[i]:=idxid[i-j]; end;
j:=j shl 1;
end;
//writeln('i ',i);
inc(i,lowbit(i));
end;
end;
begin
//assign(input,'salesman.in');reset(input);
//assign(output,'salesman.out');rewrite(output);
readln(n);
for i:=1 to n do
read(s[i]);
for i:=1 to n do
read(a[i]);
for i:=1 to n do
begin
update(i,a[i]);
update2(i,s[i]*2+a[i]);
k[i]:=s[i]*2+a[i];
end;
j:=1;
temp:=0;
while j<=n do
begin
max1:=query(1,temp);
max2:=query2(temp+1,n);
//writeln(max1,' ',max2);
if max1>max2 then
begin
inc(tot,max1);
temp2:=tempnow1;
end
else begin
inc(tot,max2);
temp:=tempnow2;
temp2:=tempnow2;
end;
writeln(tot);
//for i:=1 to temp do
//write(idx[i],' ');
//writeln;
modify(temp2);
inc(j);
end;
//close(input);close(output);
end.
2 条评论
-
方晨羽 LV 9 @ 2016-08-07 15:24:58
dd
-
2016-08-07 15:24:27@
···pascal
var
a:array[0..10000] of int64;
```
- 1
信息
- ID
- 1977
- 难度
- 8
- 分类
- (无)
- 标签
- 递交数
- 2269
- 已通过
- 267
- 通过率
- 12%
- 被复制
- 16
- 上传者