⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 riddle2.pas

📁 PASCAL光盘资料PASCAL光盘资料PASCAL光盘资料
💻 PAS
字号:
program riddle(input,output);
var
  m,n,p,min,minx,total:longint;
  w,t:array[1..100] of longint;
  i,j:longint;

begin
  assign(input,'riddle.in');
  assign(output,'riddle.out');
  reset(input);
  rewrite(output);
  readln(m);
  readln(n);
  for i:=1 to n do
    read(t[i]);
  for i:=1 to n do
    read(w[i]);
  for i:=1 to n-1 do
    for j:=i+1 to n do
      if (t[i]>t[j]) or (t[i]=t[j]) and (w[i]>w[j]) then
        begin
          p:=t[i];
          t[i]:=t[j];
          t[j]:=p;
          p:=w[i];
          w[i]:=w[j];
          w[j]:=p;
        end;
  for i:=1 to n do
    if (t[i]<i) and (i<=n) then
      begin
        min:=maxlongint;
        for j:=1 to i do
          if w[j]<min then
            begin
              min:=w[j];
              minx:=j;
            end;
          total:=total+min;
          for j:=minx to n-1 do
            begin
              w[j]:=w[j+1];
              t[j]:=t[j+1];
            end;
          dec(n);
          dec(i);
      end;
  writeln(m-total);
  close(input);
  close(output);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -