Editorial for Going Once, Going Twice, Gone!


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này

Code mẫu của flashmt

var a:array[1..1000] of longint;
    n,m,pos:integer;
    re:longint;

procedure rf;
var i:integer;
begin
     readln(n,m);
     for i:=1 to m do readln(a[i]);
end;

procedure sort(l,r:integer);
var i,j:integer; x,y:longint;
begin
     i:=l; j:=r; x:=a[(i+j) div 2];
     repeat
           while a[i]<x do i:=i+1;
           while a[j]>x do j:=j-1;
           if i<=j then
           begin
                y:=a[i]; a[i]:=a[j]; a[j]:=y;
                i:=i+1; j:=j-1;
           end;
     until i>j;
     if i<r then sort(i,r);
     if j>l then sort(l,j);
end;

procedure pr;
var i,j,t:integer;
    f:text;
begin
     sort(1,m);
     re:=0; pos:=0;
     for i:=1 to m do
     begin
          if m-i+1<=n then t:=m-i+1
          else t:=n;
          if a[i]*t>re then 
      begin
        re:=a[i]*t;
        pos:=i;
          end;
     end;
     write(a[pos],' ',re);
end;

begin
     rf;
     pr;
end.

Code mẫu của ladpro98

program auction;
uses    math;
var     n,m,price,res,i:longint;
        a:array[1..1000] of longint;

procedure swap(i,j:longint);
var     t:longint;
begin
        t:=a[i];
        a[i]:=a[j];
        a[j]:=t;
end;
procedure sort(l,r:longint);
var     pivot,i,j:longint;
begin
        if l>=r then exit;
        pivot:=a[random(r-l+1)+l];
        i:=l;j:=r;
        repeat;
                while a[i]<pivot do inc(i);
                while a[j]>pivot do dec(j);
                if i<=j then
                begin
                        if i<j then swap(i,j);
                        inc(i);
                        dec(j);
                end;
        until i>j;
        sort(l,j);sort(i,r);
end;
begin
        readln(n,m);
        for i:=1 to m do readln(a[i]);
        sort(1,m);
        for i:=m downto (m-min(m,n)+1) do
        begin
                if res<(m-i+1)*a[i] then
                begin
                        res:=(m-i+1)*a[i];
                        price:=a[i];
                end;
        end;
        write(price,' ',res);
end.

Code mẫu của RR

uses math;
var
  cnt:array[1..1000000] of longint;
  res,m,n,u,i:longint;

begin
  read(m,n);
  for i:=1 to n do
    begin
      read(u);
      inc(cnt[u]);
    end;
  for i:=999999 downto 1 do
    inc(cnt[i],cnt[i+1]);

  u:=1;
  for i:=1 to 1000000 do
    if i*min(m,cnt[i])>res then
      begin
        res:=i*min(m,cnt[i]);
        u:=i;
      end;
  writeln(u,' ',res);
end.

Code mẫu của hieult

#include <stdio.h>
main()
{
int n,m;
long a[1000],max=0,b,c,min;
scanf("%d %d",&n,&m);
for(int i=0;i<m;i++)
  scanf("%ld",&a[i]);
for(int i=0;i<m;i++)
  {
  b=0;
  for(int j=0;j<m;j++)
    if(a[j]>=a[i])
      b++;
  if(b<=n)
    c=b*a[i];
  else c=n*a[i];
  if(max<c)
    {
    min=a[i];
    max=c;
    }
  }
printf("%ld %ld",min,max);
}

Code mẫu của ll931110

Program AUCTION;
        Const
                input  = '';
                output = '';
        Var
                n,m: longint;
                  a: array[1..1000] of longint;

Procedure init;
          Var
                f: text;
                i: longint;
          Begin
                Assign(f, input);
                        Reset(f);
                        Readln(f, n, m);
                        For i:= 1 to m do readln(f, a[i]);
                Close(f);
          End;

Procedure quicksort;

        Procedure partition(l,h: longint);
                Var
                        i,j,p,x: longint;
                Begin
                        If l >= h then exit;
                        p:= a[random(h - l + 1) + l];

                        i:= l;          j:= h;
                Repeat
                        While a[i] < p do inc(i);
                        While a[j] > p do dec(j);

                        If i <= j then
                                Begin
                                        If i < j then
                                                Begin
                                                        x:= a[i];
                                                        a[i]:= a[j];
                                                        a[j]:= x;
                                                End;
                                        inc(i);
                                        dec(j);
                                End;
                Until i > j;

                partition(l,j);
                partition(i,h);
          End;

       Begin
        partition(1,m);
       End;

Procedure solve;
          Var
                  f: text;
                i,s: longint;
                max,val: longint;
          Begin
                max:= 0;
                val:= 0;

                Assign(f, output);
                        Rewrite(f);
                        For i:= 1 to m do
                                Begin
                                        If n <= m - i + 1 then s:= a[i] * n
                                              else s:= a[i] * (m - i + 1);
                                        If max < s then
                                                Begin
                                                        max:= s;
                                                        val:= a[i];
                                                End;
                                End;
                        Writeln(f, val, ' ', max);
                Close(f);
          End;

Begin
        init;
        quicksort;
        solve;
End.

Code mẫu của skyvn97

#include<stdio.h>
#include<algorithm>
#define MAX   1111
using namespace std;
int a[MAX];
int m,n,s,t;
void init(void) {
    scanf("%d",&m);
    scanf("%d",&n);
    int i;
    for (i=1;i<=n;i=i+1) scanf("%d",&a[i]);
    sort(&a[1],&a[n+1]);
    s=0;
    for (i=n;(i>=1) && (n-i+1<=m);i=i-1)
        if (a[i]*(n-i+1)>s) {
            t=a[i];
            s=a[i]*(n-i+1);
        }
    printf("%d %d",t,s);
}
int main(void) {
    init();
}

Code mẫu của khuc_tuan

[n,m] = [int(s) for s in raw_input().split()]
a = [0] * m
for i in range(m):
    a[i] = input()
a.sort()
res = 0
p = 0
for i in range(m):
    if res<a[i] * min(m-i,n):
        res = a[i] * min(m-i,n)
        p = a[i]

print str(p) + " " + str(res)

Comments

Please read the guidelines before commenting.


There are no comments at the moment.