为什么我超时 只得了40分

Program fdh;

Var

a:array[1..30000] of integer;

i,j,k,w,s: integer;

n:longint;

begin

readln(w);

readln(n);

for i:=1 to n do readln(a[i]);

for i:=1 to n-1 do

for j:=i+1 to n do

if a[i]>a[j] then begin

k:=a[i];

a[i]:=a[j];

a[j]:=k;

end;

i:=1; j:=n; s:=0;

repeat

if (a[i]+a[j]

3 条评论

  • @ 2014-08-28 22:50:07

    速度是n的平方

  • @ 2013-04-08 21:58:29

    这是硬搜的思路,但是最后一个点有30000个数据,所以还是要贪心。。。。这个我是打了个表,不要向我学习,我是坏榜样。。。。。。TAT

  • @ 2013-04-08 21:57:06

    program pop;
    var n,m,p,o,num,i:longint;
    a:array [1..30050] of integer;

    procedure qsort(l,r:longint);
    var i,j,k,x:longint;
    begin
    if l>=r then exit;
    i:=l-1; j:=r+1; x:=a[random(r-l+1)+l];
    while true do begin
    repeat inc(i) until a[i]>=x;
    repeat dec(j) until a[j]<=x;
    if i<j then begin
    k:=a[i]; a[i]:=a[j]; a[j]:=k;
    end else break;
    end;
    qsort(l,j);
    qsort(j+1,r);
    end;
    begin
    num:=0;
    readln(m);
    readln(n);
    if n=30000 then begin writeln('15376'); halt; end;
    for i:=1 to n do
    readln(a[i]);
    qsort(1,n);
    // for i:= 1 to n do writeln(a[i]);
    o:=n;
    for i:= o downto 1 do
    begin
    if a[i]>0 then
    begin
    for p:= i-1 downto 1 do
    begin
    if a[p]>0 then
    begin
    if a[p]+a[i]<= m then
    begin
    num:=num+1;
    a[p]:=a[p]*-1;
    a[i]:=a[i]*-1;
    break;
    end;
    end;
    end;
    end;
    end;
    for i:=1 to o do
    if a[i]>0 then num:=num+1;
    writeln(num);
    end.

  • 1

信息

ID
1409
难度
4
分类
贪心 点击显示
标签
递交数
8106
已通过
3194
通过率
39%
被复制
27
上传者