Submission #4076962


Source Code Expand

Copy
n,k=gets.split.map &:to_i
a=$<.map{|e|e.split.map &:to_i}.sort_by{|e|-e[1]}
c=Hash.new s=r=0
l=[]
i=k-1
a.each{|m,v|
	if l.size>=k
	next if c.has_key?(m)
	i=i.downto(0).find{|j|c[l[j][0]]>1}
	break if !i
	s-=l[i][1]
	c[l[i][0]]-=1
	l.delete_at(i)
	end
	s+=v
	c[m]+=1
	l<< [m,v]
	r=[r,s+c.size**2].max
}
p r

Submission Info

Submission Time
Task D - Various Sushi
User leafmoon
Language Ruby (2.3.3)
Score 400
Code Size 325 Byte
Status
Exec Time 416 ms
Memory 20776 KB

Compile Error

./Main.rb:1: warning: `&' interpreted as argument prefix
./Main.rb:2: warning: `&' interpreted as argument prefix
./Main.rb:1: warning: assigned but unused variable - n

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 7 ms 1788 KB
02.txt 7 ms 1788 KB
03.txt 7 ms 1788 KB
04.txt 7 ms 1788 KB
05.txt 7 ms 1788 KB
06.txt 7 ms 1788 KB
07.txt 7 ms 1788 KB
08.txt 7 ms 1788 KB
09.txt 7 ms 1788 KB
10.txt 7 ms 1788 KB
11.txt 7 ms 1788 KB
12.txt 7 ms 1788 KB
13.txt 7 ms 1788 KB
14.txt 75 ms 6088 KB
15.txt 192 ms 10616 KB
16.txt 96 ms 6828 KB
17.txt 149 ms 8440 KB
18.txt 13 ms 2168 KB
19.txt 267 ms 13196 KB
20.txt 224 ms 12276 KB
21.txt 208 ms 12408 KB
22.txt 314 ms 17104 KB
23.txt 286 ms 14824 KB
24.txt 344 ms 19100 KB
25.txt 416 ms 20776 KB
26.txt 321 ms 20416 KB
27.txt 221 ms 12536 KB
28.txt 316 ms 20416 KB
29.txt 241 ms 12536 KB
30.txt 344 ms 20672 KB
31.txt 223 ms 16348 KB
32.txt 234 ms 16348 KB
33.txt 271 ms 16336 KB
34.txt 280 ms 16336 KB
35.txt 285 ms 20652 KB
36.txt 301 ms 20264 KB
37.txt 197 ms 12280 KB
38.txt 194 ms 12280 KB
s1.txt 7 ms 1788 KB
s2.txt 7 ms 1788 KB
s3.txt 7 ms 1788 KB