比赛 不平凡的世界 评测结果 AAAAAAATTT
题目名称 不平凡的boss 最终得分 70
用户昵称 Derrick_M 运行时间 4.266 s
代码语言 Pascal 内存使用 1.31 MiB
提交时间 2015-11-05 11:09:30
显示代码纯文本
program P2097;
var
  a,b,c:array[0..100010] of longint;
  ans,i,n,num:longint;

procedure swap(var u,v:longint);
var
  tmp:longint;
begin
  tmp:=u;
  u:=v;
  v:=tmp;
end;

procedure qsort(l,r:longint);
var
  i,j,x,y:longint;
begin
  i:=l;
  j:=r;
  x:=a[l+random(r-l+1)];
  repeat
    while a[i]<x do inc(i);
    while x<a[j] do dec(j);
    if not(i>j) then
                begin
                  swap(a[i],a[j]);
                  swap(b[i],b[j]);
                  swap(c[i],c[j]);
                  inc(i);
                  j:=j-1;
                end;
  until i>j;
  if l<j then qsort(l,j);
  if i<r then qsort(i,r);
end;

function work(u:longint):longint;
var
  i,max,ans:longint;
begin
  max:=0;
  ans:=maxlongint;
  for i:=n downto 1 do
  begin
    if c[i]<=u then continue;
    if max+a[i]<ans then ans:=max+a[i];
    if max<b[i] then max:=b[i];
  end;
  if max<ans then ans:=max;
  exit(ans);
end;

begin
  assign(input,'playwithboss.in');assign(output,'playwithboss.out');
  reset(input);rewrite(output);
  randomize;
  readln(n);
  for i:=1 to n do
    readln(a[i],b[i],c[i]);
  qsort(1,n);
  ans:=maxlongint;
  c[0]:=0;
  for i:=0 to n do
  begin
    if c[i]>=ans then continue;
    num:=work(c[i])+c[i];
    if ans>num then ans:=num;
  end;
  writeln(ans);
  close(input);close(output);
end.