problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
262k
1.05M
problem_description
stringlengths
48
1.55k
codes
stringlengths
35
98.9k
status
stringlengths
28
1.7k
submission_ids
stringlengths
28
1.41k
memories
stringlengths
13
808
cpu_times
stringlengths
11
610
code_sizes
stringlengths
7
505
p03147
u941753895
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\n\ndef LI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\ndef main():\n n=I()\n l=LI()\n\n sm=sum(l)\n\n c=1\n i=0\n while True:\n if l[i]>0:\n l[i]-=1\n sm-=1\n\n if i+1==n or l[i+1]==0:\n c+=1\n\n i+=1\n if i>=n:\n i=0\n\n if sm==0:\n return c\n\nprint(main())\n', 'import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\n\ndef LI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\ndef main():\n n=I()\n l=LI()\n\n sm=sum(l)\n\n c=1\n i=0\n while True:\n if l[i]>0:\n l[i]-=1\n sm-=1\n\n if i+1==n or l[i+1]==0:\n c+=1\n\n if i+1>=n:\n if l[-1]!=0:\n c+=1\n i=0\n else:\n i+=1\n\n if sm==0:\n return c\n\nprint(main())\n', 'import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time\n\nsys.setrecursionlimit(10**7)\ninf=10**20\nmod=10**9+7\n\ndef LI(): return list(map(int,input().split()))\ndef I(): return int(input())\ndef LS(): return input().split()\ndef S(): return input()\n\ndef main():\n n=I()\n l=LI()\n\n sm=sum(l)\n\n c=0\n i=0\n while True:\n if l[i]>0:\n l[i]-=1\n sm-=1\n\n if i+1==n or l[i+1]==0:\n c+=1\n\n i+=1\n if i>=n:\n i=0\n\n if sm==0:\n return c\n\nprint(main())\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s396176793', 's509826298', 's744544149']
[5420.0, 5420.0, 5420.0]
[43.0, 43.0, 42.0]
[510, 556, 510]
p03147
u945181840
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['N = int(input())\nh = list(map(int, input().split()))\nans = 0\nfor i in range(max(h)):\n h.append(0)\n count = 0\n for k in range(N):\n if h[k] != 0 and h[k + 1] == 0:\n count += 1\n ans += count\n print(count, h)\n h = list(map(lambda x: (x - 1, 0)[x == 0], h))\nprint(ans)', 'N = int(input())\nh = list(map(int, input().split()))\nans = 0\ncount = 0\nh.append(0)\nf = set(h)\nfor i in range(max(h)):\n if i in f:\n count = 0\n for k in range(N):\n if h[k] != 0 and h[k + 1] == 0:\n count += 1\n ans += count\n h = list(map(lambda x: (x - 1, 0)[x == 0], h))\nprint(ans)']
['Wrong Answer', 'Accepted']
['s809942551', 's747435382']
[3064.0, 3064.0]
[23.0, 20.0]
[299, 327]
p03147
u945200821
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['import sys\nimport numpy as np\n\n\ndef count_water(np_arr):\n least = min(np_arr)\n div_p = np.where(np_arr == least)[0]\n np_arr -= least\n return least + count_water(np_arr[:div_p]) + count_water(np_arr[div_p + 1:])\n\n\ndef main():\n readline = sys.stdin.readline\n \n n = int(readline().rstirp())\n h = np.array(tuple(int(_) for _ in readline().rstrip().split()))\n \n print(count_water(h))\n\n \nif __name__ == "__main__":\n main()\n', 'import sys\nimport numpy as np\n\n\ndef count_water(np_arr):\n if not np_arr.any():\n return 0\n least = min(np_arr)\n div_p = np.where(np_arr == least)[0][0]\n np_arr -= least\n return least + count_water(np_arr[:div_p]) + count_water(np_arr[div_p + 1:])\n\n\ndef main():\n readline = sys.stdin.readline\n \n n = int(readline().rstrip())\n h = np.array(tuple(int(_) for _ in readline().rstrip().split()))\n \n print(count_water(h))\n\n \nif __name__ == "__main__":\n main()\n']
['Runtime Error', 'Accepted']
['s630785871', 's361221358']
[18504.0, 12388.0]
[247.0, 156.0]
[428, 467]
p03147
u953794676
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['def water(flowers, count):\n print(f\'count : {count}\')\n print(f\'flowers : {flowers}\')\n if len(flowers) is 0:\n return count\n count = count + min(flowers)\n flowers = [int(e-min(flowers)) for e in flowers]\n while 0 in flowers:\n count = water(flowers[:flowers.index(0)], count)\n flowers = flowers[flowers.index(0)+1: ]\n count = water(flowers, count)\n return count\n\nn = int(input())\nflowers = [int(e) for e in input().split()]\n\ncount = 0\nprint(f\'Initialize : {flowers}\')\nwater(flowers, count)\n# while flowers.count(0) != 0:\n# print(f\'{"="*20} iteration{i}\')\n\n# print(f\'flowers : {flowers}\')\n# print(f\'count : {count}\')', 'def water(flowers, count):\n if len(flowers) is 0:\n return count\n count = count + min(flowers)\n flowers = [int(e-min(flowers)) for e in flowers]\n while 0 in flowers:\n count = water(flowers[:flowers.index(0)], count)\n flowers = flowers[flowers.index(0)+1: ]\n count = water(flowers, count)\n return count\n\nn = int(input())\nflowers = [int(e) for e in input().split()]\n\ncount = 0\ncount = water(flowers, count)\nprint(count)']
['Runtime Error', 'Accepted']
['s687973929', 's964344119']
[2940.0, 3064.0]
[17.0, 26.0]
[717, 455]
p03147
u962197874
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['n = int(input())\nh = list(map(int,input().split()))\na = 0\nwhile sum(h) > 0:\n lst = [i for i, x in enumerate(h) if x > 0]\n mx = min(lst)\n for i in range(len(lst) -1):\n if lst[i] + 1 == lst[i+1]:\n mx += 1\n else:\n break\n h = [x - 1 if i >= min(lst) and i <= mx else x for i, x in enumerate(h)]\n a += 1\n print(h)\nprint(a)', 'n = int(input())\nh = list(map(int,input().split()))\na = 0\nwhile sum(h) > 0:\n lst = [i for i, x in enumerate(h) if x > 0]\n mx = min(lst)\n for i in range(len(lst) -1):\n if lst[i] + 1 == lst[i+1]:\n mx += 1\n else:\n break\n h = [x - 1 if i >= min(lst) and i <= mx else x for i, x in enumerate(h)]\n a += 1\nprint(a)']
['Wrong Answer', 'Accepted']
['s531464025', 's424584135']
[4724.0, 3188.0]
[442.0, 391.0]
[372, 358]
p03147
u991567869
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
[' = int(input())\nh = list(map(int, input().split()))\n\nans = 0\ncnt = 0\n\nfor i in range(1, max(h) + 1)[::-1]:\n cnt = 0\n for j in range(n):\n if h[j] == i:\n h[j] -= 1\n cnt += 1\n if j + 1 < n:\n if h[j + 1] == i:\n cnt -= 1\n ans += cnt\n\nprint(ans)', 'n = int(input())\nh = list(map(int, input().split())) + [0]\n\nans = 0\ncnt = 0\n\nfor i in range(1, max(h) + 1)[::-1]:\n cnt = 0\n for j in range(n):\n if h[j] == i:\n h[j] -= 1\n cnt += 1\n if h[j + 1] == i:\n cnt -= 1\n ans += cnt\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s695721958', 's731434250']
[2940.0, 3064.0]
[17.0, 20.0]
[322, 295]
p03147
u993435350
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['N = int(input())\n\nheight = list(map(int,input().split()))\n\nans = 0\ninterval = 0\n\nfor i in range(N):\n \n if height[i] > interval:\n\u3000\u3000\n\u3000\u3000\n \n ans += height[i] - interval\n interval += height[i] - interval\n \n else:\n interval = height[i]\n\nprint(ans)', 'N = int(input())\nheight = list(map(int,input().split()))\n\nflowers = [0] * N\n\nstart = 0\nend = 0\ncon = 0\n\nwhile flowers != height:\n for i in range(0,N):\n if height[i] > flowers[i]:\n start = i\n print(flowers)\n for j in range(start,N):\n if height[j] > flowers[j]:\n flowers[j] += 1\n elif height[j] == flowers[j]:\n con += 1\n break\n\n else:\n con += 1\n break\n\nprint(con)', 'N = int(input())\n\nheight = list(map(int,input().split()))\n\nans = 0\ninterval = 0\n\nfor i in range(N):\n \n if height[i] > interval:\n \n \n \n ans += height[i] - interval\n interval += height[i] - interval\n \n else:\n interval = height[i]\n\nprint(ans)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s473162024', 's665556602', 's458754280']
[2940.0, 4852.0, 3060.0]
[17.0, 66.0, 17.0]
[574, 440, 568]
p03147
u994988729
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['N = int(input())\nH = list(map(int, input().split()))\n\nans = 0\nwhile any(H):\n water = min(h for h in H if h)\n cnt = 0\n for x, y in zip(H[:-1], H[1:]):\n if x > y and y == 0:\n cnt += 1\n elif x < y and x == 0:\n cnt += 1\n ans += water * (cnt // 2 + 1)\n H = [max(0, h-water) for h in H]\n\n\nprint(ans)', 'N = int(input())\nH = [0] + list(map(int, input().split())) + [0]\n\nans = 0\nwhile any(H):\n water = min(h for h in H if h)\n\n cnt = 0\n bl = 0\n for x, y in zip(H[:-1], H[1:]):\n if x < y and x == 0:\n bl = 1\n elif x > y and y == 0 and bl:\n cnt += 1\n bl = 0\n ans += water * cnt\n H = [max(0, h-water) for h in H]\n\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s009332240', 's807391212']
[3064.0, 3064.0]
[21.0, 21.0]
[344, 381]
p03147
u999750647
2,000
1,048,576
In a flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\\{h_1,h_2,h_3,......\\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: * Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition.
['n = int(input())\nh = list(map(int, input().split()))\nans = 0\np = 0\nfor i in range(n):\n if p <= h[i]:\n ans += h[i]-p\n p = h[i]\n print(p)\nprint(ans)', 'n = int(input())\nh = list(map(int, input().split()))\nans = 0\np = 0\nfor i in range(n):\n if p <= h[i]:\n ans += h[i]-p\n p = h[i]\nprint(ans)']
['Wrong Answer', 'Accepted']
['s961832718', 's132765211']
[9164.0, 9068.0]
[26.0, 28.0]
[162, 149]
p03148
u016128476
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from heapq import heappop, heappush\nN, K = map(int, input().split())\nKMAX = 10 ** 5 + 1\nTD = []\nfor _ in range(N):\n t, d = map(int, input().split())\n TD.append((d, t))\n\nTD.sort(reverse=True)\n\npioneer = []\nsuccessor = []\nappear = [False] * KMAX\ncnt = 0\nnsp = 0 # num of species\nbase = 0\nbest = []\n\nfor td in TD:\n d, t = td\n if cnt < K:\n heappush(successor if appear[t] else pioneer, (d, t))\n nsp += 0 if appear[t] else 1\n appear[t] = True\n base += d\n cnt += 1\n if cnt == K-1:\n heappush(best, -(base + nsp ** 2))\n continue\n if not successor:\n break\n if appear[t]:\n continue\n cd, ct = heappop(successor)\n appear[t] = True\n heappush(pioneer, (d, t))\n base += (d-cd)\n nsp += 1\n heappush(best, -(base + nsp ** 2))\n\nprint(-heappop(best))\n', 'from heapq import heappop, heappush\nN, K = map(int, input().split())\nKMAX = 10 ** 5 + 1\nTD = []\nfor _ in range(N):\n t, d = map(int, input().split())\n TD.append((d, t))\n\nTD.sort(reverse=True)\n\npioneer = []\nsuccessor = []\nappear = [False] * KMAX\ncnt = 0\nnsp = 0 # num of species\nbase = 0\nbest = []\n\nfor td in TD:\n d, t = td\n if cnt < K:\n heappush(successor if appear[t] else pioneer, (d, t))\n nsp += 0 if appear[t] else 1\n appear[t] = True\n base += d\n cnt += 1\n if cnt == K:\n heappush(best, -(base + nsp ** 2))\n continue\n if not successor:\n break\n if appear[t]:\n continue\n cd, ct = heappop(successor)\n appear[t] = True\n heappush(pioneer, (d, t))\n base += (d-cd)\n nsp += 1\n heappush(best, -(base + nsp ** 2))\n\nprint(-heappop(best))\n']
['Runtime Error', 'Accepted']
['s168351319', 's991525436']
[24576.0, 24448.0]
[558.0, 579.0]
[842, 840]
p03148
u025235255
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n, k = map(int, input().split())\nsushi = []\nfor i in range(n):\n tmp = list(map(int, input().split()))\n sushi.append(tmp)\neaten = set() \nchohuku = [] \nscores = [] \n\nsushi.sort(key=lambda x:x[1])\nsushi.reverse() \n\ntmp = 0 \nfor i in range(k): \n if sushi[i][0] in eaten: \n chohuku.append(sushi[i][1])\n else:\n eaten.add(sushi[i][0]) \n tmp += sushi[i][1] \nchohuku.sort()\nscores.append(tmp+len(eaten)**2) \nprint(chohuku)\n\nfor i in range(k,n):\n if not sushi[i][0] in eaten:\n tmp -= chohuku.pop()\n eaten.add(sushi[i][0])\n tmp += sushi[i][1]\n scores.append(tmp+len(eaten)**2)\n \nprint(max(scores))', 'n, k = map(int, input().split())\nsushi = []\nfor i in range(n):\n tmp = list(map(int, input().split()))\n sushi.append(tmp)\neaten = set() \nchohuku = [] \nscores = [] \n\nsushi.sort(key=lambda x:x[1])\nsushi.reverse() \n\ntmp = 0 \nfor i in range(k): \n if sushi[i][0] in eaten: \n chohuku.append(sushi[i][1])\n else:\n eaten.add(sushi[i][0]) \n tmp += sushi[i][1] \nchohuku.sort()\nscores.append(tmp+len(eaten)**2) \n\nfor i in range(k,n):\n if not sushi[i][0] in eaten and chohuku != []:\n tmp -= chohuku.pop(0)\n eaten.add(sushi[i][0])\n tmp += sushi[i][1]\n scores.append(tmp+len(eaten)**2)\n \nprint(max(scores))']
['Runtime Error', 'Accepted']
['s654639588', 's999617244']
[30792.0, 30396.0]
[502.0, 530.0]
[1061, 1065]
p03148
u029169777
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N,K=map(int,input().split())\n\ntd=sorted([tuple(map(int,input().split())) for _ in range(N)],key=lambda x:-x[1])\nanswer=0\n\nnumber=set()\nafterpop=[]\n\nfor i in range(K):\n answer+=td[i][1]\n if td[i][0] not in number:\n number.append(td[i][0])\n else:\n afterpop.append(td[i][1])\n\nanswer+=(len(number))**2\n \nindex=K\ntempanswer=answer\nwhile index<N and afterpop:\n if td[i][0] not in number:\n number.append(td[i][0])\n tempanswer=tempanswer-afterpop.pop()-(len(number)-1)**2+(len(number))**2\n answer=max(tempanswer,answer)\n index+=1\n \nprint(answer)\n', 'N,K=map(int,input().split())\n\ntd=sorted([tuple(map(int,input().split())) for _ in range(N)],key=lambda x:-x[1])\nanswer=0\nnumber=set()\nafterpop=[]\n\nfor i in range(K):\n answer+=td[i][1]\n if td[i][0] not in number:\n number.add(td[i][0])\n else:\n afterpop.append(td[i][1])\n\nanswer+=(len(number))**2\n \nindex=K\ntempanswer=answer\nwhile index<N and afterpop:\n if td[index][0] not in number:\n number.add(td[index][0])\n tempanswer=tempanswer+td[index][1]-afterpop.pop()-(len(number)-1)**2+(len(number))**2\n answer=max(tempanswer,answer)\n index+=1\n \nprint(answer)']
['Runtime Error', 'Accepted']
['s335391404', 's929467953']
[22148.0, 22160.0]
[374.0, 438.0]
[618, 591]
p03148
u043844098
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
["import heapq\n\nfrom typing import List\n\n\ndef main():\n n, k = map(int, input().split())\n v = []\n for _ in range(n):\n t, d = map(int, input().split())\n v.append((t, d))\n\n print(vs(v, k))\n\n\ndef vs(v: List[List[int]], k: int) -> int:\n v.sort(reverse=True)\n\n # Dup type\n h0 = []\n # New type\n h1 = []\n # types\n s = set()\n types = 0\n op = 0\n\n for i in range(k):\n t, d = v[i]\n op += d\n\n if t in s:\n heapq.heappush(h0, d)\n continue\n\n types += 1\n s.add(t)\n\n for i in range(k, len(v)):\n t, d = v[i]\n\n if not t in s:\n heapq.heappush(h1, -d)\n\n result = op + types ** 2\n\n while len(h0) > 0 and len(h1) > 0:\n d0 = heapq.heappop(h0)\n d1 = -heapq.heappop(h1)\n op = op - d0 + d1\n types += 1\n tmp = op + types ** 2\n\n if tmp > result:\n result = tmp\n\n return result\n\n\nif __name__ == '__main__':\n main()\n", "import heapq\n\nfrom typing import List\n\n\ndef main():\n n, k = map(int, input().split())\n v = []\n for _ in range(n):\n t, d = map(int, input().split())\n v.append((t, d))\n\n print(vs(v, k))\n\n\ndef vs(v: List[List[int]], k: int) -> int:\n v.sort(key=lambda x: x[1], reverse=True)\n\n # Dup type\n h0 = []\n # New type\n h1 = []\n # types\n s = set()\n types = 0\n op = 0\n\n for i in range(k):\n t, d = v[i]\n op += d\n\n if t in s:\n heapq.heappush(h0, d)\n continue\n\n types += 1\n s.add(t)\n\n for i in range(k, len(v)):\n t, d = v[i]\n\n if not t in s:\n s.add(t)\n heapq.heappush(h1, -d)\n\n result = op + types ** 2\n\n while len(h0) > 0 and len(h1) > 0:\n d0 = heapq.heappop(h0)\n d1 = -heapq.heappop(h1)\n op = op - d0 + d1\n types += 1\n tmp = op + types ** 2\n\n if tmp > result:\n result = tmp\n\n return result\n\n\nif __name__ == '__main__':\n main()\n"]
['Wrong Answer', 'Accepted']
['s727403069', 's451252954']
[28068.0, 31048.0]
[297.0, 270.0]
[987, 1028]
p03148
u046187684
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
["def solve(string):\n n, k, *td = map(int, string.split())\n td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True)\n max_variety = len(set([c[0] for c in td]))\n choice = td[:k]\n r = []\n variety = set([])\n ans = 0\n for _c in choice:\n ans += _c[1]\n if _c[0] in variety:\n r.append(_c[1])\n else:\n variety.add(_c[0])\n ans += len(variety)**2\n i = k\n while len(variety) < min(max_variety, k):\n while td[i][0] in variety:\n i += 1\n variety.add(td[i][0])\n ans.append(ans[-1] - r.pop() + td[i][1] + 2 * len(variety) - 1)\n return str(max(ans))\n\n\nif __name__ == '__main__':\n n, m = map(int, input().split())\n print(solve('{} {}\\n'.format(n, m) + '\\n'.join([input() for _ in range(n)])))\n", "def solve(string):\n n, k, *td = map(int, string.split())\n td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True)\n max_variety = len(set([c[0] for c in td]))\n choice = td[:k]\n r, v, b = [], set([]), 0\n for _c in choice:\n b += _c[1]\n if _c[0] in v:\n r.append(_c[1])\n else:\n v.add(_c[0])\n b += len(v)**2\n i = k\n ans = [b]\n while len(v) < min(max_variety, k):\n while td[i][0] in v:\n i += 1\n v.add(td[i][0])\n ans.append(ans[-1] - r.pop() + td[i][1] + 2 * len(v) - 1)\n return str(max(ans))\n\n\nif __name__ == '__main__':\n n, m = map(int, input().split())\n print(solve('{} {}\\n'.format(n, m) + '\\n'.join([input() for _ in range(n)])))\n"]
['Runtime Error', 'Accepted']
['s223820650', 's187523084']
[26876.0, 26876.0]
[316.0, 304.0]
[824, 776]
p03148
u048004795
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
["\n# -*-coding: utf-8 -*-\n\nimport sys\n\ndef main():\n input = sys.stdin.readline\n n, k = map(int, input().split())\n S = [tuple(map(int, input().split())) for _ in range(n)]\n S.sort(key=lambda x: -x[1])\n y_1, y_0 = [0], [0]\n st = set()\n\n for t, d in S:\n if t in st:\n \n y_0.append(y_0[-1]+d)\n else:\n st.add(t)\n y_1.append(y_1[-1]+d)\n \n\n max_sum = -1\n\n for i in range(1,k+1):\n print(i)\n if k-i >= len(y_0):\n continue\n if i >= len(y_1):\n break\n max_sum = max(max_sum, y_0[k-i]+y_1[i]+i**2)\n \n print(max_sum)\n return\n\n\nif __name__ == '__main__':\n main()", "\n# -*-coding: utf-8 -*-\n\nimport sys\n\ndef main():\n input = sys.stdin.readline\n n, k = map(int, input().split())\n S = [tuple(map(int, input().split())) for _ in range(n)]\n S.sort(key=lambda x: -x[1])\n y_1, y_0 = [0], [0]\n st = set()\n\n for t, d in S:\n if t in st:\n \n y_0.append(y_0[-1]+d)\n else:\n st.add(t)\n y_1.append(y_1[-1]+d)\n \n\n max_sum = -1\n\n for i in range(1,k+1):\n if k-i >= len(y_0):\n continue\n if i >= len(y_1):\n break\n max_sum = max(max_sum, y_0[k-i]+y_1[i]+i**2)\n \n print(max_sum)\n return\n\n\nif __name__ == '__main__':\n main()"]
['Wrong Answer', 'Accepted']
['s531785780', 's787536212']
[32896.0, 32876.0]
[223.0, 208.0]
[722, 705]
p03148
u058861899
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n,k=map(int,input().split())\nli=[[0,0] for i in range(n)]\nfor i in range(n):\n li[i][0],li[i][1]=map(int,input().split())\n \n\nli.sort(reverse=True,key=lambda x:x[1])\n\ndef find_num_neta(choice,li):\n k=[]\n for i in choice:\n k.append(li[i][0])\n return len(set(k))\n\n\n\n#-----------------------------------------\nbest_list=[]\nnot_best_list=li.copy()\n\nfor i in li:\n if i[0] not in [best_list[p][0] for p in range(len(best_list))]:\n best_list.append(i)\n \nfor i in best_list:\n not_best_list.remove(i)\n\n#-----------------------------------------\ns2=min(find_num_neta(list(range(n)),li),k)\ns1=find_num_neta(list(range(k)),li)\n\noishisa=[0 for i in range(n)]\noishisa[s1]=sum([li[i][1] for i in range(k) ])\nscore=oishisa[s1]+s1**2\n\nfor i in range(s1+1,s2+1):\n oishisa[i]=oishisa[i-1]+best_list[i-1][1]-not_best_list[k-i][1]\n new_score=oishisa[i]+i**2\n if score<new_score:\n score=new_score\n \n \nprint(new_score)', 'n,k=map(int,input().split())\nli=[[0,0] for i in range(n)]\nfor i in range(n):\n li[i][0],li[i][1]=map(int,input().split())\n\nli.sort(reverse=True,key=lambda x:x[1])\n\ndef find_num_neta(choice,li):\n k=[]\n for i in choice:\n k.append(li[i][0])\n return len(set(k))\n\n#-----------------------------------------\nbest_list=[]\nbest_list_neta=[]\nnot_best_list=[]\n\nfor i in li:\n if i[0] in best_list_neta:\n not_best_list.append(i[1])\n else:\n best_list.append(i[1])\n best_list_neta.append(i[0])\n\n\ns2=min(len(best_list_neta),k)\ns1=find_num_neta(list(range(k)),li)\n\n\nscore=-1\noishisa=[0 for i in range(n)]\noishisa[s1]=sum([li[p][1] for p in range(k)])\n\nfor i in range(s1+1,s2+1):\n oishisa[i]=oishisa[i-1]-not_best_list[k-i]+best_list[i-1]\n \n new_score=i**2+oishisa[i]\n\n if score<new_score:\n score=new_score\n \n \nprint(score)', '# -*- coding: utf-8 -*-\n"""\nCreated on Fri Feb 22 08:12:39 2019\n\n@author: matsuda\n"""\n\nn,k=3,0\nli=[[1,9],[3,9],[2,6]]\n\n"""\nn,k=7,4\nli=[[1,1],\n[2,1],\n[3,1],\n[4,6],\n[4,5],\n[4,5],\n[4,5]]\n\n"""\n\nn,k=6,5\nli=[[5,1000000000],\n[2,990000000],\n[3,980000000],\n[6,970000000],\n[6,960000000],\n[4,950000000]]\n\n#####################\nli.sort(reverse=True,key=lambda x:x[1])\n\ndef calc_score(li,choice):\n score=0\n k=[]\n for i in choice:\n score+=li[i][1]\n k.append(li[i][0]) \n score+=len(set(k))**2\n return score\n\ndef find_num_neta(choice,li):\n k=[]\n for i in choice:\n k.append(li[i][0])\n return len(set(k))\n\nfirst_choice=list(range(k))\nscore=calc_score(li,first_choice)\n\nli_choice_set=set([li[i][0] for i in first_choice])\n\n\n\nfor i in range(find_num_neta(first_choice,li)+1,min(find_num_neta(list(range(n)),li),k)+1):\n \n new_choice=first_choice.copy()\n change=i-find_num_neta(first_choice,li)\n \n can_append=change\n must_delete=change\n \n\n \n \n for j in range(k,n):\n if li[j][0] not in li_choice_set:\n new_choice.append(j)\n can_append+=-1\n if can_append==0:\n break\n \n \n for j in range(k-1,-1,-1):\n\n if li[j][0] in [li[p][0] for p in range(j)]:\n new_choice.remove(j)\n must_delete+=-1\n if must_delete==0:\n break\n \n \n new_score=calc_score(li,new_choice)\n\n \n if score<new_score:\n score=new_score\n \n \nprint(score)', 'n,k=map(int,input().split())\nli=[[0,0] for i in range(n)]\nfor i in range(n):\n li[i][0],li[i][1]=map(int,input().split())\n\n\n\ndef find_num_neta(choice,li):\n k=[]\n for i in choice:\n k.append(li[i][0])\n return len(set(k))\n#-----------------------------------------\n\nli.sort(reverse=True,key=lambda x:x[1])\ns2=min(find_num_neta(list(range(n)),li),k)\ns1=find_num_neta(list(range(k)),li)\noishisa=sum([li[i][1] for i in range(k)])\nscore=oishisa+s1**2\n\n#-----------------------------------------\nli.sort(key=lambda x:x[0])\nbest_list=[]\nnot_best_list=[]\n\n\nm=-1\nfor i in li:\n if m==i[0]:\n not_best_list.append(i)\n else:\n best_list.append(i)\n m=i[0]\n \nnot_best_list.sort(reverse=True,key=lambda x:x[1])\nbest_list.sort(reverse=True,key=lambda x:x[1])\n\n\n\n \n \nfor i in range(s1+1,s2+1):\n oishisa=oishisa+best_list[i-1][1]-not_best_list[k-i][1]\n \n new_score=i**2+oishisa\n \n if score<new_score:\n score=new_score\n \n \nprint(score)']
['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted']
['s356379640', 's720878298', 's741034102', 's403965290']
[22520.0, 21288.0, 3192.0, 31116.0]
[2105.0, 2105.0, 17.0, 715.0]
[955, 880, 1536, 996]
p03148
u062459048
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n, k = map(int, input().split())\nTD = [[] for i in range(n)]\nfor i in range(n):\n TD[i] = list(map(int, input().split()))\n \nTD.sort(key = lambda x:x[1], reverse = True)\n\nans = 0\nhuku = []\nsu = set([])\n\nfor i, j in TD[:k]:\n ans += j\n if i in su:\n huku.append([i,j])\n su.add(i)\nans += len(su)**2\nhuku.sort(key = lambda x:x[1], reverse = True)\n\nansl = []\nansl.append(ans)\nfor i,j in TD[k:]:\n if i in su:\n continue\n elif:\n huku == []\n break\n else:\n temp = ansl[-1] + j - huku.pop()[1] + (len(su)+1)**2 -len(su)**2\n su.add(i)\n ansl.append(temp)\n\nprint(max(ansl))', 'n, k = map(int, input().split())\nTD = [[] for i in range(n)]\nfor i in range(n):\n TD[i] = list(map(int, input().split()))\n \nTD.sort(key = lambda x:x[1], reverse = True)\n\nans = 0\nhuku = []\nsu = set([])\n\nfor i, j in TD[:k]:\n ans += j\n if i in su:\n huku.append([i,j])\n su.add(i)\nans += len(su)**2\nhuku.sort(key = lambda x:x[1], reverse = True)\n\nansl = []\nansl.append(ans)\nfor i,j in TD[k:]:\n if i in su:\n continue\n elif huku == []:\n break\n else:\n temp = ansl[-1] + j - huku.pop()[1] + (len(su)+1)**2 -len(su)**2\n su.add(i)\n ansl.append(temp)\n\nprint(max(ansl))\n']
['Runtime Error', 'Accepted']
['s280615946', 's720498130']
[3064.0, 32964.0]
[17.0, 498.0]
[585, 582]
p03148
u099566485
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['def IL(): return list(map(int,input().split()))\ndef SL(): return input().split()\ndef I(): return int(input())\ndef S(): return input()\nimport heapq\nn,k=IL()\nnl=dict()\nfor i in range(n+1):\n nl[i]=0\nl=[]\nans=[]\nf=[]\nel=[]\nheapq.heapify(el)\ns=0\nfor i in range(n):\n t,d=IL()\n l.append([d,t])\nl.sort(reverse=True)\nfor i in range(k):\n t=l.pop(0)\n el.heappush(t)\n nl[t[1]]+=1\n s+=t[0]\n if t[1] not in f:\n f.append(t[1])\nu=len(f)\nans.append(s+u*u)\nfor i in range(u,k+1):\n if len(l)==0:\n break\n while True:\n t=el.heappop(0)\n if nl[t[1]]!=1:\n nl[t[1]]-=1\n s-=nl[t[0]]\n break\n while len(l)>0:\n t=l.pop(0)\n if nl[t[1]]==0:\n nl[t[1]]+=1\n s+=t[0]\n el.heappush(t)\n break\n ans.append(s+(u+i+1)**2)\n if len(l)==0:\n break\nprint(max(ans))', 'def IL(): return list(map(int,input().split()))\ndef SL(): return input().split()\ndef I(): return int(input())\ndef S(): return input()\nn,k=IL()\ntop=dict()\nsub=[]\nfor i in range(n):\n t,d=IL()\n if t in top:\n sub.append(min(top[t],d))\n top[t]=max(top[t],d)\n else:\n top[t]=d\n\ntop=sorted(top.items(),key=lambda x:-x[1])\nsub.sort(reverse=True)\n\nrtop=[top[0][1]]\nrsub=[0]\nfor i in range(1,len(top)):\n rtop.append(rtop[-1]+top[i][1])\nfor i in range(len(sub)):\n rsub.append(rsub[-1]+sub[i])\n\nans=0\nfor i in range(k):\n if i<len(rtop) and 0<=k-i-1<len(rsub):\n ans=max(ans,rtop[i]+rsub[k-i-1]+(i+1)**2)\nprint(ans)']
['Runtime Error', 'Accepted']
['s164809912', 's752308067']
[29852.0, 27324.0]
[553.0, 531.0]
[883, 646]
p03148
u102367647
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['\n\nINPUT1 = [int(n) for n in input().split()]\n\nN, K = INPUT1[0], INPUT1[1]\nParameters = []\nScore, Test = 0, 0\nflag1, flag2 = 0, 0\n\n\nfor i in range(N):\n INPUT2 = [int(m) for m in input().split()]\n Parameters.append((INPUT2[0], INPUT2[1]))\n\nParameters = sorted(Parameters, key=lambda x: x[1], reverse=True)\n\ndef SumScore(List, K):\n taste = 0\n kind = []\n for i in range(K):\n taste += List[i][1]\n kind.append(List[i][0])\n return taste + len(set(kind))**2\n\ndef SearchNew(List, K):\n kind = []\n newkind = -1\n for i in range(K):\n kind.append(List[i][0])\n kindset = set(kind)\n for i in range(len(List)-K):\n if List[K+i][0] not in kindset:\n newkind = K+i\n break\n return newkind\n\ndef SearchDouble(List, K):\n result = -1\n for i in range(K):\n leftkind = []\n for j in range(K):\n leftkind.append(List[j][0])\n testkind = List[K-1-i][0]\n leftkind.pop(K-1-i)\n if testkind in leftkind:\n result = K-1-i\n break\n return result\n\nScore = SumScore(Parameters, K)\n\nfor t in Parameters:\n i = SearchNew(Parameters, K)\n j = SearchDouble(Parameters, K)\n Parameters[i], Parameters[j] = Parameters[j], Parameters[i]\n Test = SumScore(Parameters, K)\n if Score <= Test:\n Score = Test\n print(i, j, t)\n\nprint(Score)\n', '\n\nINPUT1 = [int(n) for n in input().split()]\n\nN, K = INPUT1[0], INPUT1[1]\nParameters = []\nScore, Test = 0, 0\nflag1, flag2 = 0, 0\nkind = []\nkindnumber = 0\n\nParametersAppend = Parameters.append\nfor i in range(N):\n INPUT2 = [int(m) for m in input().split()]\n ParametersAppend([INPUT2[0], INPUT2[1]])\n\nParameters = sorted(Parameters, key=lambda x: x[1], reverse=True)\n\ndef binanrySearch(kind, target):\n testkind = kind[:]\n testkind.sort()\n left, right = 0, len(testkind)-1\n while(right >= left):\n mid = int((right + left) / 2)\n if testkind[mid] == target:\n return True\n elif testkind[mid] > target:\n right = mid - 1\n elif testkind[mid] < target:\n left = mid + 1\n return False\n\ndef SumScore(List, K, kindnumber):\n taste = 0\n for i in range(K):\n taste += List[i][1]\n return taste + kindnumber * kindnumber\n\ndef SearchNew(List, K, kind):\n newkind = -1\n for i in range(len(List)-K):\n if binanrySearch(kind, List[K+i][0]) == False:\n newkind = K+i\n break\n return newkind\n\ndef SearchDouble(List, K, kind):\n result = -1\n testkind = kind[:]\n testkindPop = testkind.pop\n for i in range(K):\n testkindPop(K-1-i)\n if binanrySearch(testkind, List[K-1-i][0]) == True:\n result = K-1-i\n break\n return result\n\nkindAppend = kind.append\n\nfor i in range(K):\n kindAppend(Parameters[i][0])\nkindnumber = len(set(kind))\nScore = SumScore(Parameters, K, kindnumber)\nkind.clear()\n\nfor t in Parameters:\n for i in range(K):\n kindAppend(Parameters[i][0])\n kindnumber = len(set(kind))\n i = SearchNew(Parameters, K, kind)\n j = SearchDouble(Parameters, K, kind)\n Parameters[i], Parameters[j] = Parameters[j], Parameters[i]\n if i != -1 and j != -1:\n kindnumber += 1\n else:\n break\n Test = Score - Parameters[i][1] + Parameters[j][1] + kindnumber**2\n if Score <= Test:\n Score = Test\n kind.clear()\n\nprint(Score)\n', '\n\nfrom sys import stdin\n#from numpy import sum\n\ninput = stdin.readline\n\nN, K = list(map(int, input().split()))\nList1= []\nkind = set()\npoint1, point2 = 0, 0\n\nINPUT = [tuple(map(int, input().split())) for _ in range(N)]\n\nINPUT.sort(key = lambda x: -x[1])\n\nfor ti, di in INPUT[:K]:\n point1 += di\n if ti in kind:\n List1.append(di)\n kind.add(ti)\n\npoint2 = len(kind)\n\nScore = point1 + point2**2\nTest = Score\n\nList1POP = List1.pop\n\nfor ti, di in INPUT[K:]:\n if 0 >= len(List1):\n break\n if ti in kind:\n continue\n Test = Test - List1POP() + di + 2 * point2 + 1\n point2 += 1\n kind.add(ti)\n Score = max(Score, Test)\n\nprint(Score)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s052605986', 's558610235', 's765825134']
[19912.0, 25260.0, 21444.0]
[2105.0, 2105.0, 262.0]
[1390, 2042, 691]
p03148
u129315407
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N, K = map(int, input().split())\nsushi = []\nfor i in N:\n s = list(map(int, input().split()))\n sushi.append(s)\n\n\nsushi.sort(key=lambda x: x[1], reverse=True)\n\ndef find_next(start, curr, point, tlist, tcount):\n if start == N:\n return [point, curr]\n max_c = curr\n max_p = point\n for s in sushi[start:]:\n if tlist[s[0]] > 0:\n continue\n for ri in range(len(curr) - 1, -1, -1):\n r = curr[ri]\n if tlist[r[0]] >= 2:\n c2 = [c for c in curr]\n t2 = [t for t in tlist]\n del c2[ri]\n c2.append(s)\n t2[r[0]] -= 1\n t2[s[0]] = 1\n p2 = point - r[1] + s[1] + (tcount + 1) * (tcount + 1) - tcount * tcount\n np, pc = find_next(start + 1, c2, p2, t2, tcount + 1)\n\n if np > max_p:\n max_p = np\n max_c = pc\n break\n return [max_p, max_c]\n\nresult = sushi[0: K]\ntype_count = [0] * (N + 1)\n\nfor r in result:\n type_count[r[0]] += 1\ntype_num = 0\nfor t in type_count:\n if t > 0:\n type_num += 1\npoint = type_num * type_num\nfor r in result:\n point += r[1]\nans_p, ans_c = find_next(K, result, point, type_count, type_num)\n\nprint(ans_p)\n', 'N, K = map(int, input().split())\nsushi = []\nfor i in range(N):\n s = list(map(int, input().split()))\n sushi.append(s)\n\n\nsushi.sort(key=lambda x: x[1], reverse=True)\n\n# pick from first\npoint = 0\nneta_set = set()\nremovable_idx = list()\nfor i in range(K):\n s = sushi[i]\n point += s[1]\n if s[0] not in neta_set:\n neta_set.add(s[0])\n else:\n removable_idx.append(i)\npoint += len(neta_set) **2\nmax_point = point\n\n# pick latest\nfor s in sushi[K:]:\n if len(removable_idx) == 0:\n break\n if s[0] in neta_set:\n continue\n idx = removable_idx[-1]\n count = len(neta_set)\n point += s[1] - sushi[idx][1]\n point += (count + 1) ** 2 - count ** 2\n neta_set.add(s[0])\n removable_idx = removable_idx[:-1]\n\n if point > max_point:\n max_point = point\nprint(max_point)']
['Runtime Error', 'Accepted']
['s376318290', 's748895432']
[3064.0, 31164.0]
[18.0, 1269.0]
[1280, 821]
p03148
u160244242
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
["nklist = list(map(int,input().split()))\nn, k= nklist[0], nklist[1]\n\nlst = [tuple(map(int, input().split())) for i in range(n)]\n\nmax_pt = 0\nfor comb in itertools.combinations(lst, k):\n kinds_set = set()\n umami = 0\n for tpl in comb:\n kinds_set.add(tpl[0])\n umami += tpl[1]\n ttl_pt = len(kinds_set)**2 + umami\n #print('ttl_pt:', ttl_pt,' max_pt:', max_pt)\n if ttl_pt > max_pt:\n max_pt = ttl_pt\nprint(max_pt)", 'n, k = map(int, input().split())\na = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x:-x[1])\n \nans = 0\ns = set()\nq = []\n \nfor i in range(k):\n ans += a[i][1]\n if a[i][0] in s:\n q.append(a[i][1])\n s.add(a[i][0])\n \nans += len(s)**2\nk1 = k\nans1 = ans\n \n\nwhile k1 < n and q:\n if a[k1][0] not in s:\n ans1 = ans1+a[k1][1]-q.pop()-len(s)**2+(len(s)+1)**2\n ans = max(ans, ans1)\n s.add(a[k1][0])\n k1 += 1\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s912200099', 's311680640']
[16604.0, 22164.0]
[315.0, 428.0]
[443, 540]
p03148
u181526702
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from itertools import groupby\nfrom heapq import heapify, heappop\n\nN, K = map(int, input().split())\nsushi = [tuple(map(int, input().split())) for _ in range(N)]\n\n\ndef point(sushi):\n t, d = zip(*sushi)\n return sum(d) + len(set(t))**2\n\n\nsrt = sorted(sushi, key=lambda x: x[1], reverse=True)\neat, non_eat = srt[:K], srt[K:]\n\nmaxs = []\nrems = []\nkinds = set()\nfor k, g in groupby(sorted(eat, key=lambda x: x[0]), key=lambda x: x[0]):\n _, d = zip(*g)\n maxs.append(d.pop(0))\n rems.extend(d)\n kinds.add(k)\nheapify(rems)\nans = point(eat)\n\nfor k, g in groupby(sorted(non_eat, key=lambda x: x[0]), key=lambda x: x[0]):\n if k in kinds:\n continue\n _, d = zip(*g)\n maxs.append(d.pop(0))\n heappop(rems)\n kinds.add(k)\n ans = max(ans, point(maxs + rems))\n\nprint(ans)', 'from heapq import heappop, heappush, heapify\n\nN, K = map(int, input().split())\nsushi = [(-d, t) for t, d in map(int, input().split())]\nheapify(sushi)\n\nmaxs = []\nrems = []\nkinds = set()\nfor _ in range(K):\n d, t = heappop(sushi)\n if t in kinds:\n heappush(rems, -d)\n else:\n maxs.append(-d)\n kinds.add(t)\nans = sum(maxs) + sum(rems) + len(kinds)**2\n\nwhile True:\n if not sushi or not rems:\n break\n d, t = heappop(sushi)\n if t in kinds:\n continue\n else:\n heappop(rems)\n maxs.append(-d)\n kinds.add(t)\n ans = max(ans, sum(maxs) + sum(rems) + len(kinds)**2)\n\nprint(ans)', 'N, K = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(N)]\nsushi.sort(key=lambda x: x[1], reverse=True)\n\nscore = 0\n\nremains = []\nkinds = set()\nfor t, d in sushi[:K]:\n if t in kinds:\n remains.append(d)\n kinds.add(t)\n score += d\nscore += len(kinds)**2\n\ntest = score\nfor t, d in sushi[K:]:\n if not remains:\n break\n if t in kinds:\n continue\n kinds.add(t)\n rm = remains.pop()\n test = test + (d - rm) + (len(kinds)*2 - 1)\n score = max(score, test)\n\nprint(score)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s465148335', 's848111281', 's983841686']
[20316.0, 3064.0, 30784.0]
[426.0, 19.0, 452.0]
[792, 644, 537]
p03148
u203843959
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N,K=map(int,input().split())\n\ndtlist = []\ntdlist = []\nfor i in range(N):\n t,d=map(int,input().split())\n dtlist.append((d,t))\n tdlist.append((t,d))\n \ndtlist.sort(reverse=True)\ntdlist.sort(reverse=True)\nprint(dtlist)\nprint(tdlist)\n \nsum_d=0\nset_t=set()\nfor i in range(K):\n d,t=dtlist[i]\n sum_d += d\n set_t.add(t)\n \nprint(sum_d+len(set_t)*len(set_t))', 'from collections import defaultdict\nN,K=map(int,input().split())\n\ndtlist=[]\ntset_all=set()\nfor i in range(N):\n t,d=map(int,input().split())\n dtlist.append((d,t))\n tset_all.add(t)\ndtlist.sort()\n#print(heapq)\n\ndtlist_Krev=[]\ndsum=0\ntdic=defaultdict(int)\nfor i in range(K):\n d,t=dtlist.pop()\n dtlist_Krev.append((d,t))\n dsum+=d\n tdic[t]+=1\n#dtlist_Krev.sort(reverse=True)\n\nt0=len(tdic)\nmax_answer=dsum+(t0**2)\n#print(t0,max_answer)\n\nfor i in range(t0+1,min(K,len(tset_all))+1):\n while(True): \n d1,t1=dtlist_Krev.pop()\n if tdic[t1]>1:\n tdic[t1]-=1\n dsum-=d1\n break\n \n while(True): \n d2,t2=dtlist.pop()\n if tdic[t2]==0:\n tdic[t2]=1\n dsum+=d2 \n break\n \n answer_i=dsum+(i**2)\n #print(i,answer_i)\n max_answer=max(max_answer,answer_i)\n \nprint(max_answer)']
['Wrong Answer', 'Accepted']
['s387159102', 's641273937']
[33796.0, 26984.0]
[652.0, 565.0]
[356, 829]
p03148
u210440747
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
["#!/usr/bin/env python3\n# -*- coding:utf-8 -*-\n\nimport sys\ninput = sys.stdin.readline\n\ndef main():\n N, K = map(int, input().split())\n # sushis = sorted([tuple(map(int, input().split())) for _ in range(N)], key=lambda x:x[1], reverse=True)\n sushis = [tuple(map(int, input().split())) for _ in range(N)]\n sushis.sort(key=lambda x:x[1])\n curr = sushis[:K]\n leave = sushis[K:]\n base = lambda li: sum([l[1] for l in li])\n types_max = len(set([c[0] for c in sushis]))\n types = []\n dups = []\n\n for c in curr:\n if c[0] in types:\n dups += [c]\n else:\n types += [c[0]]\n types = set(types)\n\n ps = base(curr) + len(types)**2\n di = {}\n di[len(types)] = ps\n n_types = len(types) + 1\n for l in leave:\n if len(types) >= types_max:\n break\n if len(dups) == 0:\n break\n if not l[0] in types:\n dup = dups.pop()\n di[n_types] = ps - dup[1] + l[1] + n_types**2 - (n_types-1)**2\n ps = di[n_types]\n n_types += 1\n types.add(l[0])\n\n print(sorted(di.items(), key=lambda x:x[1])[-1][1])\n\n\nif __name__=='__main__':\n main()", "#!/usr/bin/env python3\n# -*- coding:utf-8 -*-\n\n\nif __name__=='__main__':\n N, K = map(int, input().split())\n sushis = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[1])[::-1]\n\n curr = sushis[:K]\n leave = sushis[K:]\n base = lambda li: sum([l[1] for l in li])\n types = set([c[0] for c in curr])\n di = {}\n\n types_max = len(set([c[0] for c in sushis]))\n\n for i in range(len(types), K+1):\n di[str(i)] = base(curr) + i**2\n\n # next\n if i < types_max:\n tdi = {}\n remove_number = -1\n for j, t in enumerate(curr[::-1]):\n if not str(t[0]) in tdi.keys():\n tdi[str(t[0])] = -j-1\n else:\n remove_number = tdi[str(t[0])]\n break\n curr.pop(int(remove_number))\n\n for j, l in enumerate(leave):\n if not l[0] in types:\n types.union({l[0]})\n break\n leave = leave[:j]\n curr += [leave.pop(0)]\n else:\n break\n print(sorted(di.items(), key=lambda x:x[1])[-1][1])", "#!/usr/bin/env python3\n# -*- coding:utf-8 -*-\n\nif __name__=='__main__':\n N, K = map(int, input().split())\n sushis = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[1])[::-1]\n\n curr = sushis[:K]\n leave = sushis[K:]\n base = lambda li: sum([l[1] for l in li])\n types = set([c[0] for c in curr])\n di = {}\n\n types_max = len(set([c[0] for c in sushis]))\n\n for i in range(len(types), K+1):\n di[str(i)] = base(curr) + i**2\n\n # next\n if i < types_max:\n tdi = {}\n remove_number = -1\n for j, t in enumerate(curr[::-1]):\n if not str(t[0]) in tdi.keys():\n tdi[str(t[0])] = -j-1\n else:\n remove_number = tdi[str(t[0])]\n break\n curr.pop(int(remove_number))\n\n for j, l in enumerate(leave):\n if not l[0] in types:\n types.union({l[0]})\n break\n curr += [leave.pop(j)]\n else:\n break\n print(curr)\n print(di)\n print(sorted(di.items(), key=lambda x:x[1])[-1][1])", "#!/usr/bin/env python3\n# -*- coding:utf-8 -*-\n\n\nif __name__=='__main__':\n N, K = map(int, input().split())\n sushis = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x:x[1])[::-1]\n\n curr = sushis[:K]\n leave = sushis[K:]\n base = lambda li: sum([l[1] for l in li])\n types = set([c[0] for c in curr])\n di = {}\n\n types_max = len(set([c[0] for c in sushis]))\n\n for i in range(len(types), K+1):\n di[str(i)] = base(curr) + i**2\n\n # next\n if i < types_max:\n tdi = {}\n remove_number = -1\n for j, t in enumerate(curr[::-1]):\n if not str(t[0]) in tdi.keys():\n tdi[str(t[0])] = -j-1\n else:\n remove_number = tdi[str(t[0])]\n break\n curr.pop(int(remove_number))\n\n for j, l in enumerate(leave):\n if not l[0] in types:\n types.union({l[0]})\n break\n leave[:j]\n curr += [leave.pop(0)]\n else:\n break\n print(sorted(di.items(), key=lambda x:x[1])[-1][1])", "#!/usr/bin/env python3\n# -*- coding:utf-8 -*-\n\nimport sys\ninput = sys.stdin.readline\n\ndef main():\n N, K = map(int, input().split())\n sushis = [tuple(map(int, input().split())) for _ in range(N)]\n sushis.sort(key=lambda x:x[1], reverse=True)\n curr = sushis[:K]\n leave = sushis[K:]\n base = lambda li: sum([l[1] for l in li])\n types_max = len(set([c[0] for c in sushis]))\n types = set()\n dups = []\n\n for c in curr:\n if c[0] in types:\n dups += [c]\n else:\n types.add(c[0])\n types = set(types)\n\n ps = base(curr) + len(types)**2\n di = {}\n di[len(types)] = ps\n n_types = len(types) + 1\n for l in leave:\n if len(types) >= types_max:\n break\n if len(dups) == 0:\n break\n if not l[0] in types:\n dup = dups.pop()\n di[n_types] = ps - dup[1] + l[1] + n_types**2 - (n_types-1)**2\n ps = di[n_types]\n n_types += 1\n types.add(l[0])\n\n print(sorted(di.items(), key=lambda x:x[1])[-1][1])\n\n\nif __name__=='__main__':\n main()"]
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s177504646', 's624683649', 's665592466', 's906065103', 's391683653']
[24824.0, 41136.0, 76124.0, 41136.0, 24836.0]
[2105.0, 569.0, 2106.0, 2105.0, 270.0]
[1068, 989, 992, 981, 978]
p03148
u210827208
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n,k=map(int,input().split())\nX=[]\nfor i in range(n):\n t,d=map(int,input().split())\n X.append([t,d])\n \nX.sort(key=lambda x:x[1],reverse=True)\n\nV=set()\nf=0\nS=[]\n\nfor t,d in X[:k]:\n f+=d\n if t in V:\n S.append(t)\n else:\n V.add(t)\n\npoint=f+len(V)**2\n\nans=point\n\nfor t,d in X[k:]:\n if not S:\n break\n if not t in V:\n point+=d-S.pop()+1+len(V)*2\n V.add(t)\n ans=max(ans,point)\nprint(ans)\n ', 'n,k=map(int,input().split())\nX=[]\nfor i in range(n):\n t,d=map(int,input().split())\n X.append([t,d])\n \nX.sort(key=lambda x:x[1],reverse=True)\n\nV=set()\npoint=0\nS=[]\n\nfor t,d in X[:k]:\n point+=d\n if t in V:\n S.append(d)\n else:\n V.add(t)\npoint+=len(V)**2\n\nans=point\n\nfor t,d in X[k:]:\n if not S:\n break\n if not t in V:\n point+=d-S.pop()+1+len(V)*2\n V.add(t)\n ans=max(ans,point)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s597724390', 's963146669']
[22972.0, 22980.0]
[433.0, 505.0]
[449, 451]
p03148
u226155577
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from collections import defaultdict\nN, K = map(int, input().split())\nT = defaultdict(list)\nfor i in range(N):\n t, d = map(int, input().split())\n T[t].append(d)\nS = []\nU = []\nfor k, v in T.items():\n v.sort(reverse=1)\n U.append((v[0], k))\n for w in v[1:]:\n S.append((w, k))\nS.sort(reverse=1)\nU.sort(reverse=1)\nD = defaultdict(int)\ncnt = 0\nD[U[0][1]] += 1\nt = 1\ncnt += 1\nres = U[0][0]\nS = S[:K-1]\nfor w, k in S:\n D[k] += 1\n if D[k] == 1:\n t += 1\n cnt += 1\n res += w\nans = 0\nfor v, k in U[1:]:\n D[k] += 1\n if D[k] == 1:\n t += 1\n cnt += 1\n res += v\n while cnt > K:\n cnt -= 1\n w, l = S.pop()\n D[l] -= 1\n if D[l] == 0:\n t -= 1\n res -= w\n print(t, res, cnt)\n ans = max(ans, t*t + res)\nprint(ans)', 'from collections import defaultdict\nN, K = map(int, input().split())\nT = defaultdict(list)\nfor i in range(N):\n t, d = map(int, input().split())\n T[t].append(d)\nS = []; U = []\nfor k, v in T.items():\n v.sort(reverse=1)\n U.append((v[0], k))\n for w in v[1:]:\n S.append((w, k))\nS.sort(reverse=1)\nU.sort(reverse=1)\nD = defaultdict(int)\nt = cnt = 0\nres = 0\nfor w, k in S:\n D[k] += 1\n if D[k] == 1:\n t += 1\n cnt += 1\n res += w\nans = 0\ncan = 1\nfor v, k in U:\n D[k] += 1\n if D[k] == 1:\n t += 1\n cnt += 1\n res += v\n while cnt > K:\n if not S:\n can = 0\n break\n cnt -= 1\n w, l = S.pop()\n D[l] -= 1\n if D[l] == 0:\n t -= 1\n res -= w\n if not can:\n break\n ans = max(ans, t*t + res)\nprint(ans)']
['Runtime Error', 'Accepted']
['s656041119', 's813140567']
[42324.0, 40224.0]
[942.0, 1035.0]
[802, 825]
p03148
u237362582
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from operator import itemgetter\n\nn, k = map(int, input().split(" "))\nsushis = []\nflags = [False for i in range(n+10)]\nsushis2 = []\nsushis22 = []\nsum2 = 0\ncount2 = 0\nfor i in range(n):\n t, d = (map(int, input().split(" ")))\n sushis.append([t, d])\n\n if not flags[t]:\n sushis22.append(d)\n flags[t] = True\n else:\n sushis2.append(d)\n# calc variety\nif len(sushis22) <= k:\n count2 += len(sushis22)\n sum2 += sum(sushis22)\n sum2 += len(sushis22) * len(sushis22)\nelse:\n sum2 += sum(sorted(sushis22, reverse=True)[0:k])\n sum2 += k*k\n count2 += k\n\nif count2 < k:\n sushis2 = sorted(sushis2, reverse=True)\n sum2 += sum(sushis2[0:k-count2])\n\n# calc score\nsum1 = 0\nset1 = []\ncount = k\ntemp_score = 0\ntemp_i = 0\nsushis = sorted(sushis, key=itemgetter(1), reverse=True)\n\ntemp_set = []\nfor i, sushi in enumerate(sushis):\n sum1 += sushi[1]\n if count == 1:\n temp_set.append(sushi[0])\n temp_i = i\n temp_score = sushi[1]\n break\n group = sushi[0]\n set1.append(group)\n count -= 1\n\n\nset1 = set(set1)\n\nwhile temp_i+1 < n:\n if temp_score == sushis[temp_i+1]:\n temp_set.append(sushis[temp_i+1][0])\n temp_i += 1\n else:\n break\n\nif len(set1 | set(temp_set)) != len(set1):\n sum1 += (len(set1)+1)*(len(set1)+1)\nelse:\n sum1 += len(set1) * len(set1)\nprint(sum1)\nprint(sum2)\n\nprint(max(sum1, sum2))\n', 'from operator import itemgetter\n\nn, k = map(int, input().split(" "))\nsushis = [list(map(int, input().split(" "))) for i in range(n)]\nflags = [False for i in range(n+10)]\n\n# calc score\nsushis = sorted(sushis, key=itemgetter(1), reverse=True)\nduplicated_set = []\nvariety = 0\neat = 0\nmax_score = 0\nsum1 = 0\nfor i, sushi in enumerate(sushis):\n t, d = sushi\n if eat < k:\n sum1 += d\n eat += 1\n if flags[t]:\n duplicated_set.append(d)\n else:\n variety += 1\n flags[t] = True\n if eat == k:\n sum1 += variety * variety\n max_score = sum1\n duplicated_set = sorted(duplicated_set, reverse=True)\n else:\n if variety == k or len(duplicated_set) == 0:\n break\n if flags[t]:\n pass\n else:\n variety += 1\n flags[t] = True\n sum1 = sum1 + d - duplicated_set.pop() + 2*(variety) - 1\n max_score = max(max_score, sum1)\n\nprint(max_score)\n']
['Wrong Answer', 'Accepted']
['s348803315', 's017837384']
[26860.0, 32716.0]
[516.0, 522.0]
[1395, 1004]
p03148
u259418313
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n, k = map(int, input().split())\nans = []\naru = []\nnai = []\nspe = set()\nf = []\nm = 0\nfor i in range(n):\n t, d = map(int, input().split())\n nai.append([t,d])\nnai = sorted(nai, key=lambda x: x[1], reverse = True)\nfor i in range(k):\n anstmp = nai.pop(0)\n if(anstmp[0] not in spe):\n ans.append(anstmp[1])\n spe.add(anstmp[0])\n else:\n aru.append(anstmp[1])\n\ns = len(spe)\nm = sum(ans) + sum(aru) + s**2\n\nfor i in range(len(nai)):\n if(len(aru) == 0): break\n if(nai[i][0] not in spe):\n aru.pop()\n ans.append(nai[i][1])\n s += 1\n m = max(m, sum(ans) + sum(aru) + (s + i)**2)\nprint(m)\n', 'n, k = map(int, input().split())\nans = []\naru = []\nnai = []\nspe = set()\nf = []\nm = 0\nfor i in range(n):\n t, d = map(int, input().split())\n nai.append([t,d])\nnai = sorted(nai, key=lambda x: x[1], reverse = True)\nfor i in range(k):\n anstmp = nai.pop(0)\n if(anstmp[0] not in spe):\n ans.append(anstmp[1])\n spe.add(anstmp[0])\n else:\n aru.append(anstmp[1])\n\ns = len(spe)\nm = sum(ans) + sum(aru) + s**2\nprint(ans, aru, s)\n\nfor i in range(len(nai)):\n if(len(aru) == 0): break\n if(nai[i][0] not in spe):\n aru.pop()\n ans.append(nai[i][1])\n s += 1\n print(ans, aru, s)\n m = max(m, sum(ans) + sum(aru) + s**2)\nprint(m)\n', 'n, k = map(int, input().split())\nnai = [list(map(int, input().split())) for _ in range(n)]\n\nnai = sorted(nai, key=lambda x: -x[1])\n\nans = 0\naru = []\nspe = set()\nm = 0\nfor i in range(k):\n anstmp = nai.pop(0)\n if(anstmp[0] not in spe):\n ans+=anstmp[1]\n spe.add(anstmp[0])\n else:\n aru.append(anstmp[1])\nsumaru = sum(aru)\nm = ans + sumaru + len(spe)**2\n\nfor i in range(len(nai)):\n if(len(aru) == 0): break\n if(nai[i][0] not in spe):\n sumaru-=aru.pop()\n ans+=nai[i][1]\n spe.add(nai[i][0])\n m = max(m, ans + sumaru + len(spe)**2)\nprint(m)\n']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s015827872', 's228905495', 's793494819']
[24368.0, 141012.0, 33024.0]
[2105.0, 2105.0, 1972.0]
[639, 679, 593]
p03148
u272557899
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['#import collections\nn, k = map(int, input().split())\nc = []\nfor i in range(n):\n c.append([int(m) for m in input().split()])\nc.sort(key=lambda x:(x[0], x[1]))\nf = sorted(c, key=lambda x:(x[1], x[0]), reverse=True)\ndonyoku = 0\ndonset = set()\nfor i in range(k):\n donyoku += f[i][1]\n donset.add(f[i][0])\ndonyoku += len(donset)**2\n\nt = []\nd = []\nfor i in range(n):\n pi, qi = c[i][0], c[i][1]\n t.append(pi)\n d.append(qi)\nspe = len(set(t))\nstili = []\nreal = 0\nreaset = set()\nws = set()\ni = 0\np = [0]*n\nwhile True:\n if f[i][0] not in ws:\n real += f[i][1]\n ws.add(f[i][0])\n p[i] = 1\n i += 1\n if i == len(donset):\n break\nkosu = len(donset)\nyy = real\nu = 0\nfor i in range(len(donset) + 1, k + 1):\n while True:\n if f[i][0] not in ws:\n real += f[i][1]\n ws.add(f[i][0])\n kosu += 1\n break\n else:\n i += 1\n if i == n:\n u = 1\n break\n if u == 1:\n break\n q = 0\n while True:\n if q < n:\n if p[q] == 0:\n real += f[q][1]\n kosu += 1\n if kosu == k:\n break\n else:\n break\n q += 1\n real += len(ws) ** 2\n stili.append(real)\n real = yy\n\n\nif stili != []:\n rr = min(stili)\n print(min(donyoku,rr))\nelse:\n print(donyoku)', 'from heapq import heappush, heappop\n#import collections\nn, k = map(int, input().split())\nc = []\nfor i in range(n):\n c.append([int(m) for m in input().split()])\nc.sort(key=lambda x:(x[0], x[1]))\nf = sorted(c, key=lambda x:(x[1], x[0]), reverse=True)\ndonyoku = 0\ndonset = set()\n\nnotfirst =[]\nfor i in range(k):\n if f[i][0] not in donset:\n donset.add(f[i][0])\n else:\n heappush(notfirst, f[i][1])\n donyoku += f[i][1]\ndonyoku += len(donset)**2\n\ncandidate = []\ncandidateset = set()\ndonyokulength = len(donset)\nfor i in range(k, n):\n if f[i][0] not in donset:#\n candidate.append(-f[i][1])\n candidateset.add(f[i][0])\n donset.add(f[i][0])\n\nsatili = [donyoku]\ndonyoku -= donyokulength**2\nfor i in range(len(candidateset)):\n if notfirst == []:\n break\n else:\n donyoku -= heappop(notfirst)\n donyoku += -heappop(candidate)\n donyoku += (donyokulength + i + 1) ** 2\n satili.append(donyoku)\n donyoku -= (donyokulength + i + 1) ** 2\n\n\n\n\nprint(max(satili))\n']
['Wrong Answer', 'Accepted']
['s102016225', 's791724375']
[38808.0, 37264.0]
[2106.0, 748.0]
[1404, 1482]
p03148
u332906195
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['# -*- coding: utf-8 -*-\n\ndef popMaxOishisa(sushis):\n t, d = max(sushis["max"].items(), key=lambda i:i[1])\n if len(sushis[t]) == 1:\n sushis.pop(t)\n sushis["max"].pop(t)\n else:\n sushis[t].pop()\n sushis["max"][t] = sushis[t][-1]\n return t, d\n\n\ndef popMinOishisa_nonUniqueNeta(sel_sushis):\n t, d = min(sel_sushis["min"].items(), key=lambda i:i[1])\n sel_sushis[t].pop()\n if len(sel_sushis[t]) == 1:\n sel_sushis["min"].pop(t)\n else:\n sel_sushis["min"][t] = sel_sushis[t][-1]\n return t, d\n\n\ndef popMaxOishisa_uniqueNeta(sushis, netas):\n max_dict = {k:v for k,v in sushis["max"].items() if not k in netas}\n t, d = max(sushis["max"].items(), key=lambda i:i[1])\n if len(sushis[t]) == 1:\n sushis.pop(t)\n sushis["max"].pop(t)\n else:\n sushis[t].pop()\n sushis["max"][t] = sushis[t][-1]\n return t, d\n\n\nn, k = map(int, input().split())\n\n\nsushis = {}\nsel_sushis = {}\nfor i in range(n):\n t, d = map(int, input().split())\n if not t in sushis:\n sushis[t] = [d]\n else:\n sushis[t].append(d)\n\n\nfor type in sushis:\n sushis[type].sort()\nsushis["max"] = {t:sushis[t][-1] for t in sushis}\n\ntMax = len(sushis) - 1\n\n\nsum_oishisa = 0\nfor i in range(k):\n t, d = popMaxOishisa(sushis)\n if not t in sel_sushis:\n sel_sushis[t] = [d]\n else:\n sel_sushis[t].append(d)\n sum_oishisa += d\nsel_sushis["min"] = {t:sel_sushis[t][-1] for t in sel_sushis if len(sel_sushis[t]) > 1}\n\ntMin = len(sel_sushis) - 1\nmax_score = tMin**2 + sum_oishisa\n\nfor nNeta in range(tMin+1, tMax + 1, 1):\n\n # Find sushi having minimum oishisa and being not unique for neta\n t1, d1 = popMinOishisa_nonUniqueNeta(sel_sushis)\n sum_oishisa -= d1\n\n # Find sushi having maximum oishisa and unique for neta\n t2, d2 = popMaxOishisa_uniqueNeta(sushis, list(sel_sushis.keys()))\n sum_oishisa += d2\n\n if not t1 in sushis:\n sushis[t1] = [d1]\n else:\n sushis[t1].append(d1)\n\n if not t2 in sel_sushis:\n sel_sushis[t2] = [d2]\n else:\n sel_sushis[t2].append(d2)\n\n score = nNeta**2 + sum_oishisa\n if score > max_score:\n max_score = score\n\nprint(max_score)', 'N, K = map(int, input().split())\nTD = [tuple(map(int, input().split())) for _ in range(N)]\nM = len(set([t for t, d in TD]))\n \nTD.sort(key=lambda x: x[1], reverse=True)\np, S, V = 0, [], set()\nfor t, d in TD[:K]:\n p += d\n if t in V:\n S.append(d)\n else:\n V.add(t)\np += len(V) ** 2\nans = p\nfor t, d in TD[K:]:\n if len(S) == 0:\n break\n if t not in V:\n p += 2 * len(V) + 1 - S.pop() + d\n V.add(t)\n ans = max(ans, p)\nprint(ans)']
['Runtime Error', 'Accepted']
['s337972625', 's011301347']
[37252.0, 23528.0]
[2105.0, 428.0]
[2273, 477]
p03148
u335038698
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['# -*- coding utf-8 -*-\n\nn, k = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(n)]\nsushi.sort(key = lambda x: x[1], reverse = True) # sort by d\n\nmp_max = 0\nop = 0\ntaberu_ind = set()\npop_cands = []\nt_taberu = set()\n\nfor i in range(k):\n op += sushi[i][1]\n\n t = sushi[i][0]\n if t_taberu.isdisjoint({t}): # new type\n t_taberu.add(t)\n else:\n pop_cands.append(i)\n\n taberu_ind.add(i)\nmp_max = op + len(t_taberu)**2\n\n\ni += 1\nj = i\nfor i in range(i, n):\n pop_ind = pop_cands.pop()\n taberu_ind.remove(pop_ind)\n\n for j in range(j, n):\n t = sushi[j][0]\n if t_taberu.isdisjoint({t}):\n t_taberu.add(t)\n break\n else:\n break\n \n # calc points\n op -= sushi[pop_ind][1]\n op += sushi[j][1]\n mp = op + len(t_taberu)**2\n mp_max = max(mp_max, mp)\n\n taberu_ind.add(i)\n\nprint(mp_max)\n\n', '# -*- coding utf-8 -*-\n\nn, k = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(n)]\nsushi.sort(key = lambda x: x[1], reverse = True) # sort by d\n\nmp_max = 0\nop = 0\ntaberu_ind = set()\npop_cands = []\nt_taberu = set()\n\nfor i in range(k):\n op += sushi[i][1]\n\n t = sushi[i][0]\n if t_taberu.isdisjoint({t}): # new type\n t_taberu.add(t)\n else:\n pop_cands.append(i)\n\n taberu_ind.add(i)\nmp_max = op + len(t_taberu)**2\n\n\ni += 1\nj = i\nfor i in range(i, n):\n if len(pop_cands) == 0:\n break\n\n pop_ind = pop_cands.pop()\n taberu_ind.remove(pop_ind)\n\n for j in range(j, n):\n t = sushi[j][0]\n if t_taberu.isdisjoint({t}):\n t_taberu.add(t)\n break\n else:\n break\n \n # calc points\n op -= sushi[pop_ind][1]\n op += sushi[j][1]\n mp = op + len(t_taberu)**2\n mp_max = max(mp_max, mp)\n\n taberu_ind.add(i) # not necessary actually\nprint(mp_max)\n\n']
['Runtime Error', 'Accepted']
['s719930122', 's390067308']
[39632.0, 39632.0]
[543.0, 531.0]
[965, 1035]
p03148
u365364616
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from collections import defaultdict\n\nn, k = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(n)]\nsushi.sort(key=lambda x: x[1])\nt = defaultdict(int)\nx = list(range(n - 1, n - k - 1, -1))\nz = [0]\nfor i in range(n - k, n):\n t[sushi[i][0]] += 1\n z[0] += sushi[i][1]\n\ny = []\nyd = list(t.keys())\nfor i in range(n - k - 1, -1, -1):\n if sushi[i][0] not in yd:\n y.append(i)\n yd.append(sushi[i][0])\ny = y[::-1]\nk = 1\n\nfor k in range(1, len(y) + 1):\n for i in range(len(x) - 1, -1, -1):\n xi = x[i]\n if t[sushi[xi][0]] > 1:\n t[sushi[xi][0]] -= 1\n z.append(z[-1] - sushi[xi][1] + sushi[y[-k]][1])\n x.pop(i)\n break\n\np = len(t.keys())\nans = 0\nfor i in range(len(z)):\n ans = max(z[i] + (p + i) ** 2)\nprint(ans)\n', 'n, k = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(n)]\nsushi.sort(key=lambda x: x[1])\nt = {}\nx = []\nz = 0\nfor i in range(n - 1, n - k - 1, -1):\n ti, di = sushi[i]\n if ti in t.keys():\n x.append(di)\n t[ti] += 1\n else:\n t[ti] = 1\n z += di\n\np = len(t.keys())\nans = z + p ** 2\nidx = 1\nfor i in range(n - k - 1, -1, -1):\n if idx == len(x) + 1:\n break\n ti, di = sushi[i]\n if ti not in t.keys():\n t[ti] = 1\n z += di - x[-idx]\n p += 1\n idx += 1\n ans = max(ans, z + p ** 2)\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s291524889', 's730905077']
[36140.0, 32176.0]
[2108.0, 478.0]
[816, 598]
p03148
u367130284
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from heapq import*\nn,k=map(int,input().split())\nl=[tuple(map(int,input().split()))for i in range(n)]\nheapify(sorted(l,key=lambda x:x[1])[::-1])\nprint(l[:k])\nprint(l[k:])\n', 'from collections import*\nn,k=map(int,input().split())\nsushi=sorted([tuple(map(int,input().split()))for i in range(n)],key=lambda x:x[1],reverse=1)\nfirst=defaultdict(list)\nsecond=defaultdict(list)\nmenu=set()\n\nfor _,v in sushi[:k]:\n menu.add(_)\n first[_].append(v)\nsecond=sushi[k:][::-1]\nscore=sum(map(sum,first.values()))\nchange=[]\nfor _,v in first.items():\n for i in v[1:]:\n change.append((_,i))\nchange.sort(key=lambda x:x[1],reverse=1)\n\n#print(first,change,second)\nans=[score+len(first)**2]\nwhile change and second:\n _,s=change.pop()\n score-=s\n try:\n while second[-1][0] in menu:\n pp,ss=second.pop()\n pp,ss=second.pop()\n menu.add(pp)\n score+=ss\n ans.append(score+len(menu)**2)\n except:\n break\nprint(max(ans))\n\n']
['Wrong Answer', 'Accepted']
['s255039317', 's312990245']
[23620.0, 31876.0]
[429.0, 598.0]
[170, 792]
p03148
u375616706
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN, K = map(int, input().split())\nsushis = [list(map(int, input().split())) for _ in range(N)]\n\nsushis = sorted(sushis, key=lambda x: (x[1], x[0]), reverse=True)\n\np = 0\n\n\ndef calcPoint(selected_sushis):\n p = 0\n vari = set()\n for i, v in selected_sushis:\n vari.add(i)\n p += v\n p += len(vari)**2\n return p, vari\n\n\nselected = sushis[:K]\nunSelected = sushis[K:]\n\np, vari = calcPoint(selected)\ncand = [p]\n\nva = len(vari)\nv = [0]*(N+1)\nfor i, _ in selected:\n v[i] += 1\n\ncan_del = []\nfor i, v in reversed(selected):\n if vari[i] > 2:\n vari[i] -= 1\n can_del.append(v)\n\ncan_in = []\nfor i, v in unSelected:\n if not i in vari:\n vari.add(i)\n can_in.append(v)\n\nfor od, nd in zip(can_del, can_in):\n nextp = p-od+nd-(vari)**2+(vari+1)**2\n cand.append(nextp)\n vari += 1\nprint(max(cand))\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN, K = map(int, input().split())\nsushis = [list(map(int, input().split())) for _ in range(N)]\n\nsushis = sorted(sushis, key=lambda x: (x[1], x[0]), reverse=True)\n\np = 0\n\n\ndef calcPoint(selected_sushis):\n p = 0\n vari = set()\n for i, v in selected_sushis:\n vari.add(i)\n p += v\n p += len(vari)**2\n return p, len(vari)\n\n\nselected = sushis[:K]\nrest_shushi = sushis[K+1:]\np, nv = calcPoint(selected)\n\nvari = [0]*(N+1)\nfor i, v in selected:\n vari[i] += 1\n\nfor i, v in rest_shushi:\n if vari[i] >= 1:\n continue\n else:\n d = []\n for a, b in reversed(selected):\n if vari[a] > 1:\n next_p = p-b+v + (nv+1)**2 - nv**2\n if next_p > p or True:\n vari[a] -= 1\n vari[i] += 1\n nv += 1\n p = next_p\nprint(p)\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\n\nN, K = map(int, input().split())\nsushis = [list(map(int, input().split())) for _ in range(N)]\n\nsushis = sorted(sushis, key=lambda x: (x[1], x[0]), reverse=True)\n\np = 0\n\n\ndef calcPoint(selected_sushis):\n p = 0\n vari = set()\n for i, v in selected_sushis:\n vari.add(i)\n p += v\n p += len(vari)**2\n return p, vari\n\n\nselected = sushis[:K]\nunSelected = sushis[K:]\n\np, vari = calcPoint(selected)\ncand = [p]\n\nva = len(vari)\nv = [0]*(N+1)\nfor i, _ in selected:\n v[i] += 1\n\ncan_del = []\nfor i, d in reversed(selected):\n if v[i] >= 2:\n v[i] -= 1\n can_del.append(d)\n\ncan_in = []\nfor i, d in unSelected:\n if not i in vari:\n vari.add(i)\n can_in.append(d)\n\n#print("del->", can_del, can_in)\nfor od, nd in zip(can_del, can_in):\n nextp = p-od+nd-(va)**2+(va+1)**2\n p = nextp\n cand.append(p)\n va += 1\nprint(max(cand))\n']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s357596606', 's732378663', 's648192047']
[38036.0, 37220.0, 41776.0]
[402.0, 2106.0, 500.0]
[943, 959, 975]
p03148
u394721319
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n, k = map(int, input().split())\nA = []\nfor _ in range(n):\n t, d = map(int, input().split())\n A.append((d, t))\n\nA.sort(reverse=True)\nX = []\nY = []\nst = set()\n\nprint(A)\n\nfor i in range(k):\n d,t = A[i]\n if t in st:\n X.append(d)\n else:\n Y.append(d)\n st.add(t)\n\nprint(X)\n\nx = sum(X)\ny = sum(Y)\nv = len(Y)\nans = x + y + v**2\nfor i in range(k, n):\n if not X:\n break\n d, t = A[i]\n if t in st:\n continue\n st.add(t)\n x -= X.pop()\n y += d\n v += 1\n ans = max(ans, x + y + v**2)\n\nprint(ans)\n', 'n, k = map(int, input().split())\nA = []\nfor _ in range(n):\n t, d = map(int, input().split())\n A.append((d, t))\n\nA.sort(reverse=True)\nX = []\nY = []\nst = set()\n\nfor i in range(k):\n d,t = A[i]\n if t in st:\n X.append(d)\n else:\n Y.append(d)\n st.add(t)\n\nx = sum(X)\ny = sum(Y)\nv = len(Y)\nans = x + y + v**2\nfor i in range(k, n):\n if not X:\n break\n d, t = A[i]\n if t in st:\n continue\n st.add(t)\n x -= X.pop()\n y += d\n v += 1\n ans = max(ans, x + y + v**2)\n\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s961700515', 's140617128']
[22764.0, 19848.0]
[496.0, 448.0]
[553, 533]
p03148
u476124554
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import collections\nN,K = map(int,input().split())\nt = []\nd = []\nfor _ in range(N):\n i,j = map(int,input().split())\n t.append(i)\n d.append(j)\ntd1 = list(zip(t,d))\ntd1 = sorted(td1,key=lambda x: x[1], reverse=True)\nt1,d1 = zip(*td1)\nans1 = 0\nfor i in range(K):\n ans1 += d1[i]\nans1 = ans1 + len(set(t1[0:K-1])) ** 2\n\ntd2 = list(zip(t,d))\ntd2 = sorted(td2,key=lambda x: x[1], reverse=True)\nt2,d2 = zip(*td2)\ns = set()\nans2 = 0\ncounter = 0\nfor i in range(N):\n if(len(s) == K):\n break\n if(t2[i] not in s):\n ans2 +=d2[i] \n s.add(t2[i])\nprint(ans2)\nans2 = ans2 + K ** 2\nprint(max(ans1,ans2))', 'import collections\nN,K = map(int,input().split())\nt = []\nd = []\nfor _ in range(N):\n i,j = map(int,input().split())\n t.append(i)\n d.append(j)\ntd1 = list(zip(t,d))\ntd1 = sorted(td1,key=lambda x: x[1], reverse=True)\nt1,d1 = zip(*td1)\nans1 = 0\nfor i in range(K):\n ans1 += d1[i]\nans1 = ans1 + len(set(t1[0:K-1])) ** 2\n\ntd2 = list(zip(t,d))\ntd2 = sorted(td2,key=lambda x: x[1], reverse=True)\nt2,d2 = zip(*td2)\ns = set()\nans2 = 0\ncounter = 0\nfor i in range(N):\n if(len(s) == K):\n break\n if(t2[i] not in s):\n ans2 +=d2[i] \n s.add(t2[i])\nans2 = ans2 + K ** 2\nprint(max(ans1,ans2))', 'import collections\n\nindex = 0\n\ndef maxsushi(sushi_list,eaten_sushi):\n global index\n max_val = [0,0]\n for i in range(index,len(sushi_list)):\n if(sushi_list[i][1] not in eaten_sushi):\n tmp = sushi_list[i]\n max_val = sushi_list[i]\n index = i\n break\n return max_val\n\nN,K = map(int,input().split())\nsushi = []\numasa = []\nfor _ in range(N):\n i,j = map(int,input().split())\n sushi.append(i)\n umasa.append(j)\nl = list(zip(umasa,sushi))\nl = sorted(l,reverse=True)\nsushi_list = list(l)\neat_sushi = sushi_list[0:K]\neaten_sushi = set()\ndouble_sushi = []\nfor i in range(K):\n if(sushi_list[i][1] not in eaten_sushi):\n eaten_sushi.add(sushi_list[i][1])\n else:\n double_sushi.append((sushi_list[i]))\nmanzoku = 0\nsushi_list = sushi_list[K:N]\nfor i in range(len(eat_sushi)):\n manzoku += eat_sushi[i][0]\nmanzoku = manzoku + (len(eaten_sushi)) ** 2\ntmp_manzoku = manzoku \nwhile double_sushi:\n tmp1 = double_sushi.pop()\n tmp2 = maxsushi(sushi_list,eaten_sushi)\n if(tmp2[0] == 0 and tmp2[1] == 0):\n break\n eaten_sushi.add(tmp2[1])\n tmp_manzoku = tmp_manzoku + tmp2[0] - tmp1[0] + len(eaten_sushi) ** 2 - (len(eaten_sushi) - 1) ** 2\n if (tmp_manzoku > manzoku):\n manzoku = tmp_manzoku\nprint(manzoku)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s479325540', 's790303018', 's312840667']
[35816.0, 35776.0, 22620.0]
[639.0, 656.0, 487.0]
[623, 611, 1302]
p03148
u476604182
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N,K,*L = map(int, open(0).read().split())\nls = []\nfor i,(t,d) in enumerate(zip(*[iter(L)]*2)):\n ls.append((d,t))\nls.sort()\nS = set()\npre = []\nans = 0\nnum = 0\nfor i in range(K):\n d,t = ls.pop()\n ans += d\n if t not in S:\n S.add(t)\n else:\n pre.append(d)\npre.sort(reverse=True)\nans += num*num\nif pre==[]:\n print(ans)\n exit()\nm = ans\nfor i in range(N-K):\n d,t = ls.pop()\n if t in S:\n continue\n S.add(t)\n m -=pre.pop()\n m += d+2*num+1\n num += 1\n ans = max(ans,m)\n if pre==[]:\n break\nprint(ans)', 'N,K,*L = map(int, open(0).read().split())\nls = []\nfor i,(t,d) in enumerate(zip(*[iter(L)]*2)):\n ls.append((d,t))\nls.sort()\nS = set()\npre = []\nans = 0\nnum = 0\nfor i in range(K):\n d,t = ls.pop()\n ans += d\n if t not in S:\n num += 1\n S.add(t)\n else:\n pre.append(d)\npre.sort(reverse=True)\nans += num*num\nif pre==[]:\n print(ans)\n exit()\nm = ans\nfor i in range(N-K):\n d,t = ls.pop()\n if t in S:\n continue\n S.add(t)\n m -=pre.pop()\n m += d+2*num+1\n num += 1\n ans = max(ans,m)\n if pre==[]:\n break\nprint(ans)']
['Wrong Answer', 'Accepted']
['s682639076', 's831701142']
[25940.0, 25940.0]
[270.0, 255.0]
[514, 527]
p03148
u506689504
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import numpy as np\n\nn, k = map(int, input().split())\nmx = {}\nfor _ in range(n):\n t, d = map(int, input().split())\n if t not in mx:\n mx[t] = d\n elif mx[t] < d:\n mx[t] = d\n sushi.append((t,d))\n\n\ntaste_sorted_sushi = sorted(sushi, key=lambda x:x[1], reverse=True)\n\n\nselected_sushi = taste_sorted_sushi[:k]\n\n\n\nS = set()\nq = []\nfor s in selected_sushi:\n if s[0] in S:\n q.append(s)\n else:\n S.add(s[0])\n\nq = sorted(q, key=lambda x:x[1], reverse=True)\nans = sum(selected_sushi[:][1])+len(S)**2\n\nS = set(selected_sushi[:][0])\nfor i in range(k,n):\n if taste_sorted_sushi[k] not in S:\n ans = max(ans, ans-q.pop()+taste_sorted_sushi[k]-len(S)**2 + (len(S)+1)**2\n S.add(taste_sorted_sushi[k][0])\n\nprint(ans)', "import numpy as np\n\nn, k = map(int, input().split())\nmx = {}\nsushi = []\nfor _ in range(n):\n t, d = map(int, input().split())\n if t not in mx:\n mx[t] = d\n elif mx[t] < d:\n mx[t] = d\n sushi.append([t,d])\n\n\ntaste_sorted_sushi = sorted(sushi, key=lambda x:x[1], reverse=True)\n\n\nselected_sushi = np.array(taste_sorted_sushi[:k], dtype=np.int64)\n\n\n\nS = set()\nq = []\nfor s in selected_sushi:\n if s[0] in S:\n q.append(s[1])\n else:\n S.add(s[0])\n\nq = sorted(q, reverse=True)\nans = sum(selected_sushi[:,1])+len(S)**2\ntmp = ans\n\n#print(selected_sushi, selected_sushi[:,1], 'ans', ans, S, q)\n\n#print(S)\nfor i in range(k,n):\n if not q:\n break\n if taste_sorted_sushi[i][0] not in S:\n #print('ans',ans)\n \n tmp = tmp-q.pop()+taste_sorted_sushi[i][1]-len(S)**2 + (len(S)+1)**2\n ans = max(ans, tmp)\n S.add(taste_sorted_sushi[i][0])\n\nprint(ans)"]
['Runtime Error', 'Accepted']
['s217585313', 's901682138']
[3064.0, 39896.0]
[17.0, 758.0]
[937, 1148]
p03148
u535907456
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N,K = list(map(int,input().split()))\nTDlist = []\n\nfor x in range(0,N):\n TDlist.append(list(map(int,input().split())))\n\nTDlist.reverse(key = lambda x: x[1])\nkinds = []\nseconds = []\nanswer = 0\n\nfor x in TDlist[:K]:\n if not x[0] in kinds:\n kinds.append(x[0])\n else:\n seconds.append(x[1])\n answer += x[1]\n\nanswer += len(kinds)**2\nscore = answer\nmax_score = answer\n\nfor x in TDlist[K:]:\n if seconds == []:\n break\n if x[0] in kinds:\n continue\n kinds.append(x[0])\n y = seconds.pop()\n score += (x[1] - y) + (len(kinds)*2 -1)\n max_score = max(score,answer)\n \n\nanswer = max(answer,max_score)\n\nprint(answer)', 'N,K = list(map(int,input().split()))\nTDlist = []\n\nfor x in range(0,N):\n TDlist.append(list(map(int,input().split())))\n\nTDlist= sorted(TDlist, key = lambda x: x[1],reverse=True)\nkinds = set()\nseconds = []\nanswer = 0\n\nfor x in TDlist[:K]:\n if not x[0] in kinds:\n kinds.add(x[0])\n else:\n seconds.append(x[1])\n answer += x[1]\n\nanswer += len(kinds)**2\nscore = answer\n\nfor x in TDlist[K:]:\n if seconds == []:\n break\n if x[0] in kinds:\n continue\n kinds.add(x[0])\n y = seconds.pop()\n score += (x[1] - y) + (len(kinds)*2 -1)\n answer = max(score,answer)\n\nprint(answer)']
['Runtime Error', 'Accepted']
['s802425120', 's949478968']
[27408.0, 30848.0]
[356.0, 502.0]
[657, 616]
p03148
u545368057
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['\n\n# d = sum(di) + x**x\n\n\n\nfrom collections import defaultdict\n\ndi = defaultdict(list)\nn, k = map(int, input().split())\n\nsushi = []\nkinds = []\nfor i in range(n):\n t,d = map(int, input().split())\n sushi.append((d,t))\n kinds.append(t)\nsushi.sort(reverse=True)\nsushidict = defaultdict(int)\nn_kind_all = len(set(kinds))\n\ncnt = 0\nimport heapq\nsushiq = []\n\nfor i in range(k):\n heapq.heappush(sushiq,(d,t)) \n d,t = sushi[i]\n sushidict[t] += 1\n cnt += d\n\nn_kind = len(sushidict)\nres = []\nres.append(cnt+n_kind**2)\n\nfor i in range(k,n):\n d,t = sushi[i]\n \n if sushidict[t] > 0 : continue\n \n d_min,t_min = heapq.heappop(sushiq)\n \n while sushidict[t_min] == 0:\n d_min, t_min = heapq.heappop(sushiq)\n print(d_min,t_min)\n sushidict[t_min] -= 1\n sushidict[t] += 1\n n_kind += 1\n cnt = cnt - d_min + d\n res.append(cnt+n_kind**2)\n if n_kind == n_kind_all:\n break\n\nprint(max(res))', '\n\n\n\n\nfrom collections import defaultdict\nN, K = map(int,input().split())\n\npairs = [list(map(int,input().split())) for _ in range(N)]\n\npairs = sorted(pairs,reverse=True, key=lambda x: x[1])\nkinds = set()\nchange = [] \n\n\n\ncnt = 0\nfor t,d in pairs[:K]: \n if t in kinds:\n change.append(d) \n kinds.add(t)\n cnt += d\n\nn = len(kinds)\ncnt += len(kinds)\nans = cnt\n\n\nfor t,d in pairs[K:]:\n \n if len(change) == 0:\n break\n \n if t in kinds:\n continue\n d_min = change.pop()\n cnt = cnt - (d_min + n**2) + (d + (n+1)**2)\n kinds.add(t)\n n += 1\n ans = max(cnt,ans)\n\nprint(ans)\n', '\n\n# d = sum(di) + x**x\n\n\n\nfrom collections import defaultdict\n\ndi = defaultdict(list)\nn, k = map(int, input().split())\n\nsushi = []\nkinds = []\nfor i in range(n):\n t,d = map(int, input().split())\n sushi.append((d,t))\n kinds.append(t)\nsushi.sort(reverse=True)\nsushidict = defaultdict(int)\nn_kind_all = len(set(kinds))\n\ncnt = 0\nimport heapq\nsushiq = []\n\nfor i in range(k):\n d,t = sushi[i]\n heapq.heappush(sushiq,(d,t)) \n sushidict[t] += 1\n cnt += d\n\nn_kind = len(sushidict)\nres = []\nres.append(cnt+n_kind**2)\n\nfor i in range(k,n):\n d,t = sushi[i]\n \n if sushidict[t] > 0 : continue\n \n d_min,t_min = heapq.heappop(sushiq)\n \n while sushidict[t_min] == 1 and sushiq:\n d_min, t_min = heapq.heappop(sushiq)\n \n if not sushiq:\n break\n sushidict[t_min] -= 1\n sushidict[t] += 1\n n_kind += 1\n cnt = cnt - d_min + d\n res.append(cnt+n_kind**2)\n if n_kind == n_kind_all:\n break\n\nprint(max(res))\n# print(res)']
['Runtime Error', 'Wrong Answer', 'Accepted']
['s636387366', 's829586507', 's204516573']
[33076.0, 31136.0, 29804.0]
[618.0, 488.0, 587.0]
[1444, 1521, 1519]
p03148
u557494880
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N,K = map(int,input().split())\nans = [0 for i in range(N+1)]\nfood = {}\nfood1 = []\nfor i in range(1,N+1):\n food[i] = 0\nfor i in range(N):\n t,d = map(int,input().split())\n food1.append((d,t))\nfood1.sort()\nsyurui = 0\nsum = 0\nx = []\nfor i in range(1,N+1):\n d,t = food1[-i]\n sum += d\n if food[t] == 0:\n food[t] = 1\n syurui += 1\n if i > K:\n y = x.pop(0)\n sum -= y\n else:\n x.append(d)\n x.sort()\n if syurui == K:\n ans[K] = max(sum + K**2,ans[K])\n break\n else:\n ans[syurui] = max(sum + syurui**2,ans[syurui])\nprint(max(ans))', 'N,K = map(int,input().split())\nans = [0 for i in range(N+1)]\nfood = {}\nfood1 = []\nfor i in range(1,N+1):\n food[i] = 0\nfor i in range(N):\n t,d = map(int,input().split())\n food1.append((d,t))\nfood1.sort()\nsyurui = 0\nsum = 0\nimport heapq\nx = []\nheapq.heapify(x)\nfor i in range(1,N+1):\n d,t = food1[-i]\n if food[t] == 0:\n if i > K:\n if len(x) == 0:\n break\n sum += d\n food[t] = 1\n syurui += 1\n if i > K:\n y = heapq.heappop(x)\n sum -= y\n else:\n if i <= K:\n sum += d\n heapq.heappush(x,d)\n if syurui == K:\n ans[K] = max(sum + K**2,ans[K])\n break\n else:\n ans[syurui] = max(sum + syurui**2,ans[syurui])\nprint(max(ans))']
['Wrong Answer', 'Accepted']
['s735096824', 's327718584']
[30104.0, 29528.0]
[2105.0, 586.0]
[620, 765]
p03148
u562935282
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from collections import defaultdict\nfrom operator import itemgetter\nimport sys\n\ninput = sys.stdin.readline\n\nn, k = map(int, input().split())\ne = defaultdict(list)\nfor _ in range(n):\n t, d = map(int, input().split())\n t -= 1\n e[t].append(d)\n\ntops = []\nrests = []\nfor l in e.values():\n for i, d in enumerate(sorted(l, key=itemgetter(0), reverse=True)):\n if i == 0:\n tops.append(d)\n else:\n rests.append(d)\n\ntops.sort(reverse=True)\nc_tops = [0]\nfor t in tops:\n c_tops.append(c_tops[-1] + t)\n\nrests.sort(reverse=True)\nc_rests = [0]\nfor t in rests:\n c_rests.append(c_rests[-1] + t)\n\nans = 0\nfor i in range(1, min(k, len(tops)) + 1):\n if k - i > len(rests): continue\n ans = max(ans, c_tops[i] + c_rests[k - i] + pow(i, 2))\nprint(ans)\n', "def main():\n from heapq import heappush, heappop\n from operator import itemgetter\n import sys\n input = sys.stdin.readline\n\n N, K = map(int, input().split())\n\n dd = []\n for _ in range(N):\n t, d = map(int, input().split())\n t -= 1\n dd.append((d, t))\n dd.sort(key=itemgetter(0), reverse=True)\n\n ret = 0\n biggest = [-1] * N\n h = []\n kinds = 0\n for d, t in dd[:K]:\n ret += d\n if ~biggest[t]:\n if biggest[t] > d:\n heappush(h, d)\n else:\n heappush(h, biggest[t])\n biggest[t] = d\n else:\n kinds += 1\n ret += kinds * 2 - 1\n biggest[t] = d\n\n ans = ret\n for d, t in dd[K:]:\n if ~biggest[t]: continue\n if not h: break\n kinds += 1\n diff = d + kinds * 2 - 1 - h[0]\n ret += diff\n if ans < ret: ans = ret\n biggest[t] = d\n heappop(h)\n\n print(ans)\n\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Accepted']
['s620507682', 's365550375']
[27684.0, 18396.0]
[223.0, 244.0]
[787, 1014]
p03148
u580502851
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N,K=map(int,input().split())\ntd=[[int a for a in input().split()]for i in range(N)]\n\ntd=sorted(td,key=lambda x:-x[1])\n\nans=0\neat=[]\nnoteat=[]\nfor t,d in td[:K]:\n ans+=d\n if t not in eat:\n eat.append(t)\n else:\n noteat.append(d)\ntemp_result=ans+sum(eat)**2\nmax_result=temp_result\n\nfor t,d in td[K:]:\n if not noteat:\n break\n if t not in eat:\n temp_result+=2*len(eat)+1\n temp_result+=d-noteat.pop()\n eat.add(t)\n max_result=max(max_result,temp_result)\nprint(max_result)\n ', 'N,K=map(int,input().split())\ntd=[[int(a) for a in input().split()]for i in range(N)]\n\ntd=sorted(td,key=lambda x:-x[1])\n\nans=0\neat=[]\nnoteat=[]\nfor t,d in td[:K]:\n ans+=d\n if t not in eat:\n eat.append(t)\n else:\n noteat.append(d)\ntemp_result=ans+len(eat)**2\nmax_result=temp_result\n\nfor t,d in td[K:]:\n if not noteat:\n break\n if t not in eat:\n temp_result+=2*len(eat)+1\n temp_result+=d-noteat.pop()\n eat.add(t)\n max_result=max(max_result,temp_result)\nprint(max_result)\n \n\n', 'N,K=map(int,input().split())\ntd=[[int(a) for a in input().split()]for i in range(N)]\n\ntd=sorted(td,key=lambda x:-x[1])\n\nans=0\neat=set([])\nnoteat=[]\nfor t,d in td[:K]:\n ans+=d\n if t not in eat:\n eat.add(t)\n else:\n noteat.append(d)\ntemp_result=ans+len(eat)**2\nmax_result=temp_result\n\nfor t,d in td[K:]:\n if not noteat:\n break\n if t not in eat:\n temp_result+=2*len(eat)+1\n temp_result+=d-noteat.pop()\n eat.add(t)\n max_result=max(max_result,temp_result)\nprint(max_result)\n ']
['Runtime Error', 'Runtime Error', 'Accepted']
['s354634522', 's542281796', 's572288048']
[2940.0, 26892.0, 26880.0]
[21.0, 2105.0, 456.0]
[492, 495, 495]
p03148
u597374218
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N,K=map(int,input().split())\nTD=[[int(j) for j in input().split()] for i in range(N)]\nTD=sorted(TD,key=lambda x:-x[1])\ndelicious=0\nkind=set()\nstack=[]\nfor t,d in TD[:K]:\n delicious+=d\n if t in kind:stack.append(t)\n else:kind.add(d)\nans1=delicious+len(kind)**2\nans2=ans1\nfor t,d in TD[K:]:\n if not stack:break\n if not t in kind:\n ans2+=d-stack.pop()+2*len(kind)+1\n kind.add(t)\n ans2=max(ans1,ans2)\nprint(ans2)', 'N,K=map(int,input().split())\nTD=[[int(j) for j in input().split()] for i in range(N)]\nTD=sorted(TD,key=lambda x:-x[1])\npoint=0\nstack=[]\nkind=set()\nfor t,d in TD[:K]:\n point+=d\n if t in kind:stack.append(d)\n else:kind.add(t)\nans1=delicious+len(kind)**2\nans2=ans1\nfor t,d in TD[K:]:\n if not stack:break\n if not t in kind:\n ans2+=d-stack.pop()+2*len(kind)+1\n kind.add(t)\n ans2=max(ans1,ans2)\nprint(ans2)', 'N,K=map(int,input().split())\nTD=[[int(j) for j in input().split()] for i in range(N)]\nTD=sorted(TD,key=lambda x:-x[1])\npoint=0\nstack=[]\nkind=set()\nfor t,d in TD[:K]:\n point+=d\n if t in kind:stack.append(d)\n else:kind.add(t)\npoint=point+len(kind)**2\nans=point\nfor t,d in TD[K:]:\n if not stack:break\n if not t in kind:\n point+=d-stack.pop()+2*len(kind)+1\n kind.add(t)\n ans=max(ans,point)\nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s641285397', 's853862680', 's329751023']
[28744.0, 26892.0, 26892.0]
[437.0, 437.0, 489.0]
[444, 436, 432]
p03148
u606045429
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from heapq import heappush, heappop\n\nINF = float("inf")\n\nN, K, *TD = map(int, open(0).read().split())\n\nS = [[] for _ in range(N)]\nfor t, d in zip(*[iter(TD)] * 2):\n S[t - 1].append(d)\n\nE = []\nfor s in S:\n if s:\n E.append(sorted(s, reverse=True))\n else:\n E.append([-INF])\nE.sort(reverse=True)\n\ncur = 0\nQ = []\nfor i in range(K):\n cur += E[i][0]\n for j in range(1, len(E[i])):\n heappush(Q, -E[i][j])\n\nfor i in range(K, N):\n for j in range(len(E[i])):\n heappush(Q, -E[i][j])\n\nres = cur + K * K\nfor x in range(K, 0, -1):\n v, w = E[x][0], -Q[0]\n if v < w:\n heappop(Q)\n cur += w\n heappush(Q, -v)\n cur -= v\n\n res = max(res, cur + x * x)\n\nprint(res)\n\n', "from heapq import heappush, heapreplace\n\ndef main():\n INF = 10 ** 9 + 5\n\n N, K, *TD = map(int, open(0).read().split())\n\n E = [[] for _ in range(N)]\n for t, d in zip(*[iter(TD)] * 2):\n E[t - 1].append(d)\n\n for e in E:\n if e:\n e.sort(reverse=True)\n else:\n e.append(-INF)\n E.sort(key=lambda x: -x[0])\n\n cur = 0\n Q = []\n for ei in E[:K]:\n cur += ei[0]\n for eij in ei[1:]:\n heappush(Q, -eij)\n\n for ei in E[K:]:\n for eij in ei:\n heappush(Q, -eij)\n\n res = cur + K * K\n for x in reversed(range(1, K)):\n v, w = E[x][0], -Q[0]\n if v < w:\n heapreplace(Q, -v)\n cur += w - v\n\n tmp = cur + x * x\n if res < tmp:\n res = tmp\n\n print(res)\n\nif __name__ == '__main__':\n main()\n"]
['Runtime Error', 'Accepted']
['s577894966', 's796942086']
[38148.0, 32964.0]
[557.0, 305.0]
[725, 846]
p03148
u619819312
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from collections import defaultdict as de\nn,k=map(int,input().split())\na=sorted([list(map(int,input().split()))for i in range(n)],reverse=True)\nt=de(int)\np,q=0,0\nfor i in a[:k]:\n p+=i[1]\n if t[i[0]]==0:\n q+=1\n t[i[0]]+=1\ns=0\nd=p+q*q\nc=a[:k][::-1]\nfor i in a[k:]:\n if t[i[0]]==0:\n while s!=k:\n if t[a[s][0]]>0:\n s+=1\n else:\n break\n t[i[0]]+=1\n p-=a[s][1]-i[1]\n q+=1\n d=max(d,p+q*q)\nprint(d)', 'from collections import defaultdict as de\nn,k=map(int,input().split())\na=sorted([list(map(int,input().split()))for i in range(n)],reverse=True)\nt=de(int)\np,q=0,0\nfor i in a[:k]:\n p+=i[0]\n if t[i[1]]==0:\n q+=1\n t[i[1]]+=1\ns=0\nd=p+q*q\nc=a[:k][::-1]\nfor i in a[k:]:\n if t[i[1]]==0:\n while s!=k:\n if t[a[s][1]]>0:\n s+=1\n else:\n break\n t[i[1]]+=1\n p-=a[s][0]-i[0]\n q+=1\n d=max(d,p+q*q)\nprint(d)', 'n,k=map(int,input().split())\na=sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:-x[1])\nt=[0]*(n+1)\np,q=0,0\nfor i in a[:k]:\n p+=i[1]\n if t[i[0]]==0:\n q+=1\n t[i[0]]+=1\ns=0\nd=p+q*q\nc=a[:k][::-1]\nfor i in a[k:]:\n if t[i[0]]==0:\n while s!=k:\n if t[c[s][0]]==1:\n s+=1\n else:\n break\n if s==k:\n break\n else:\n t[i[0]]+=1\n p-=c[s][1]-i[1]\n q+=1\n d=max(d,p+q*q)\n s+=1\nprint(d)']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s549608963', 's897504505', 's981242484']
[37732.0, 39220.0, 33060.0]
[631.0, 667.0, 491.0]
[495, 495, 544]
p03148
u627417051
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from collections import defaultdict\n\ndef getlist():\n\treturn list(map(int, input().split()))\nD = defaultdict(int)\nV = []\n\nN, K = getlist()\nfor i in range(N):\n\tt, d = getlist()\n\tV.append([d, t])\n\nV = sorted(V)\n\nans = []\nex = []\nk = 0\nfor i in range(N):\n\tx = V[-1 - i][1]\n\tif k < K:\n\t\tif D[x] == 0:\n\t\t\tans.append(V[-1 - i])\n\t\t\tD[x] += 1\n\t\t\tk += 1\n\telse:\n\t\tex.append(V[-1 - i])\n\n\nif k < K:\n\tfor i in range(K - k):\n\t\tans.append(ex[i])\n\teex = []\n\tfor i in range(K - k, len(ex)):\n\t\teex.append(ex[i])\nelse:\n\teex = ex\nans = sorted(ans)\neex = sorted(eex)\n\n\nA = 0\nfor i in range(K):\n\tA += ans[i][0]\nA += k * k\nn = min(k, N - K)\nfor i in range(n):\n\tif ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:\n\t\tA += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)\n\telse:\n\t\tbreak\n\nprint(A)', 'from collections import defaultdict\n\ndef getlist():\n\treturn list(map(int, input().split()))\nD = defaultdict(int)\nV = []\n\nN, K = getlist()\nfor i in range(N):\n\tt, d = getlist()\n\tV.append([d, t])\n\nV = sorted(V)\n\nans = []\nex = []\nk = 0\nfor i in range(N):\n\tx = V[-1 - i][1]\n\tif k < K:\n\t\tif D[x] == 0:\n\t\t\tans.append(V[-1 - i])\n\t\t\tD[x] += 1\n\t\t\tk += 1\n\t\telse:\n\t\t\tex.append(V[-1 - i])\n\telse:\n\t\tex.append(V[-1 - i])\n\n\nif k < K:\n\tfor i in range(K - k):\n\t\tans.append(ex[i])\n\teex = []\n\tfor i in range(K - k, len(ex)):\n\t\teex.append(ex[i])\nelse:\n\teex = ex\nans = sorted(ans)\neex = sorted(eex)\n\n\nA = 0\nfor i in range(K):\n\tA += ans[i][0]\nA += k * k\nn = min(k, N - K)\nfor i in range(n):\n\tif ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:\n\t\tA += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)\n\telse:\n\t\tbreak\n\nprint(A)']
['Runtime Error', 'Accepted']
['s831989514', 's534153575']
[26540.0, 26540.0]
[634.0, 747.0]
[802, 834]
p03148
u627886394
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
["from collections import Counter\nN, K = map(int, (input().split(' ')))\nsushi = [tuple(map(int, input().split(' '))) for _ in range(N)]\nall_sushi = sorted(sushi, key=lambda x: -x[1])\nprint(sushi)\ndefault_sushi = all_sushi[:K]\namari = all_sushi[K:]\ncounter = Counter([i[0] for i in default_sushi])\nresult = []\ndef calc_value(sushi):\n return sum([i[1] for i in sushi]) + len(set([i[0] for i in sushi]))**2\n\ndef change_sushi(sushi):\n for s in sushi[::-1]:\n if counter[s[0]] >= 2:\n for i, a in enumerate(amari):\n if a[0] not in counter:\n counter.subtract(s)\n counter.update([a[0]])\n new_sushi = a\n del amari[i]\n #amari = amari[:i] + amari[i+1:]\n sushi = [new_sushi] + sushi[:-1]\n return sushi\n return []\n \n \ndef get_sushi(sushi):\n result.append(calc_value(sushi))\n changed_sushi = change_sushi(sushi)\n if not changed_sushi:\n print(max(result))\n return\n get_sushi(changed_sushi)\n\nget_sushi(default_sushi)\n", "from collections import Counter\nN, K = map(int, (input().split(' ')))\nsushi = [tuple(map(int, input().split(' '))) for _ in range(N)]\nall_sushi = sorted(sushi, key=lambda x: -x[1])\ndefault_sushi = all_sushi[:K]\namari = all_sushi[K:]\nlen_amari = len(amari)\ncounter = Counter([i[0] for i in default_sushi])\nresult = []\ndef calc_value(sushi):\n return sum([i[1] for i in sushi]) + len(counter)**2\n\nfs = []\ndef change_sushi(sushi):\n oishisa = sum([i[1] for i in sushi])\n fs.append(oishisa + len(counter)**2)\n amari_index = 0\n for s in sushi[::-1]:\n if counter[s[0]] >= 2:\n while amari_index < len_amari:\n a = amari[amari_index]\n amari_index += 1\n if a[0] not in counter:\n counter[s[0]] -= 1\n counter[a[0]] += 1\n oishisa = oishisa - s[1] + a[1]\n fs.append(oishisa + len(counter)**2)\n break\n print(max(fs))\n exit()\n \n \ndef get_sushi(sushi):\n #result.append(calc_value(sushi))\n changed_sushi = change_sushi(sushi)\n #if not changed_sushi:\n #print(max(result))\n #return\n #get_sushi(changed_sushi)\n\nget_sushi(default_sushi)\n"]
['Wrong Answer', 'Accepted']
['s105984676', 's191425236']
[74272.0, 23992.0]
[2108.0, 451.0]
[1114, 1233]
p03148
u634208461
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N, K = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(N)]\nsorted(sushi, key=lambda x: x[1])\nsushi.reverse()\ntyp = []\nlstA = []\nlstB = []\nfor item in sushi:\n if item[0] in typ:\n item[0] = 0\n lstB.append(item[1])\n else:\n typ.append(item[0])\n item[0] = 1\n lstA.append(item[1])\nans = 0\nneta = 0\nfor i in range(K):\n ans += sushi[i][1]\n if sushi[i][0] == 1:\n neta += 1\nans += neta ** 2\nC = sum(lstA[:neta])\nD = sum(lstB[:K - neta])\nfor i in range(neta + 1, min(K, len(lstA))):\n tmp = C + lstA[i] + D - lstB[K - i]\n tmp += i ** 2\n ans = max(ans, tmp)\nprint(ans)', 'N, K = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(N)]\nsushi = sorted(sushi, key=lambda x: x[1], reverse=True)\ntyp = set()\nlstA = []\nlstB = []\nfor item in sushi:\n if item[0] in typ:\n item[0] = 0\n lstB.append(item[1])\n else:\n typ.append(item[0])\n item[0] = 1\n lstA.append(item[1])\nans = 0\nneta = 0\nfor i in range(K):\n ans += sushi[i][1]\n if sushi[i][0] == 1:\n neta += 1\nans += neta ** 2\nC = sum(lstA[:neta])\nD = sum(lstB[:K - neta])\nfor i in range(neta + 1, min(K, len(lstA)) + 1):\n C += lstA[i - 1]\n D -= lstB[K - i]\n tmp = C + D + i ** 2\n ans = max(ans, tmp)\nprint(ans)', 'N, K = map(int, input().split())\nsushi = [list(map(int, input().split())) for _ in range(N)]\nsushi = sorted(sushi, key=lambda x: x[1], reverse=True)\ntyp = set()\nlstA = []\nlstB = []\nfor item in sushi:\n if item[0] in typ:\n item[0] = 0\n lstB.append(item[1])\n else:\n typ.add(item[0])\n item[0] = 1\n lstA.append(item[1])\nans = 0\nneta = 0\nfor i in range(K):\n ans += sushi[i][1]\n if sushi[i][0] == 1:\n neta += 1\nans += neta ** 2\nC = sum(lstA[:neta])\nD = sum(lstB[:K - neta])\nfor i in range(neta + 1, min(K, len(lstA)) + 1):\n C += lstA[i - 1]\n D -= lstB[K - i]\n tmp = C + D + i ** 2\n ans = max(ans, tmp)\nprint(ans)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s026591198', 's253706919', 's592655718']
[29928.0, 29888.0, 34236.0]
[2105.0, 441.0, 545.0]
[652, 674, 671]
p03148
u677267454
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import heapq\n\nN, K = map(int, input().split())\nsushi = []\nfor i in range(N):\n t, d = map(int, input().split())\n heapq.heappush(sushi, (-d, t))\n\ntotal = 0\ntypes = set()\nremain = []\nfor i in range(K):\n d, t = heapq.heappop(sushi)\n total -= d\n if t not in types:\n types.append(t)\n else:\n \n heapq.heappush(remain, -d)\n\ntypes_len = len(types)\nans = total + types_len ** 2\n\nwhile sushi and remain:\n d, t = heapq.heappop(sushi)\n if t not in types:\n types.append(t)\n remain_d = heapq.heappop(remain)\n total = total - d - remain_d\n types_len += 1\n ans = max(ans, total + types_len ** 2)\n\nprint(ans)\n', 'import heapq\n\nN, K = map(int, input().split())\nsushi = []\nfor i in range(N):\n t, d = map(int, input().split())\n heapq.heappush(sushi, (-d, t))\n\ntotal = 0\ntypes = set()\nremain = []\nfor i in range(K):\n d, t = heapq.heappop(sushi)\n total -= d\n if t not in types:\n types.add(t)\n else:\n \n heapq.heappush(remain, -d)\n\ntypes_len = len(types)\nans = total + types_len ** 2\n\nwhile sushi and remain:\n d, t = heapq.heappop(sushi)\n if t not in types:\n types.add(t)\n remain_d = heapq.heappop(remain)\n total = total - d - remain_d\n types_len += 1\n ans = max(ans, total + types_len ** 2)\n\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s599789205', 's627407862']
[16688.0, 19332.0]
[353.0, 541.0]
[705, 699]
p03148
u681150536
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['def main():\n N, K = map(int, input().split())\n td = []\n for _ in range(N):\n ti, di = map(int, input().split())\n td.append([ti, di])\n td.sort(key=lambda x: -x[1])\n num = 0\n kind = set()\n changable = []\n for i in range(K):\n num += td[i][1]\n if td[i][0] in kind:\n changable.append(td[i][0])\n else:\n kind.add(td[i][0])\n num += len(kind) ** 2\n ans = num\n\n for i in range(K, N):\n if not changable:\n break\n if td[i][0] not in kind:\n num += td[i][1] + 2 * len(kind) + 1 - changable.pop()\n kind.add(td[i][0])\n ans = max(ans, num)\n\n\nif __name__ == "__main__":\n main()\n', 'def main():\n N, K = map(int, input().split())\n td = []\n for _ in range(N):\n ti, di = map(int, input().split())\n td.append([ti, di])\n td.sort(key=lambda x: -x[1])\n num = 0\n kind = set()\n changable = []\n for i in range(K):\n num += td[i][1]\n if td[i][0] in kind:\n changable.append(td[i][1])\n else:\n kind.add(td[i][0])\n num += len(kind) ** 2\n ans = num\n\n for i in range(K, N):\n if not changable:\n break\n if td[i][0] not in kind:\n num += td[i][1] + 2 * len(kind) + 1 - changable.pop()\n kind.add(td[i][0])\n ans = max(ans, num)\n print(ans)\n\n\nif __name__ == "__main__":\n main()\n']
['Wrong Answer', 'Accepted']
['s870153447', 's343733095']
[24464.0, 24496.0]
[434.0, 432.0]
[709, 724]
p03148
u684120680
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n,k = [int(i) for i in input().split()]\ntd = [[int(i) for i in input().split()] for _ in range(n)]\n\n\ntd.sort(key = lambda x: x[0],reverse=True)\ntd.sort(key = lambda x: x[1],reverse=True)\n\n\n\neated_kind = []\neated_kind_num = 0\neated = []\nfor t,d in td:\n if t not in eated_kind:\n eated_kind.append(t)\n eated_kind_num += 1\n eated.append([t,d])\n \n \n \n if eated_kind_num == k:\n td = td[:i+1]\n break\n\nnot_eated = [i for i in td if i not in eated]\n\n\nif eated_kind_num < k:\n eated += not_eated[:k-eated_kind_num]\n not_eated = not_eated[k-eated_kind_num:]\n #print(eated)\n eated.sort(key = lambda x: x[1],reverse=True)\n \nt_point = eated_kind_num**2\nd_point = sum([i[1] for i in eated])\npoint = t_point + d_point\n\nfor t,d in not_eated:\n eated_last_t, eated_last_d = eated[-1]\n t_point_sub = (eated_kind_num-1)**2 - eated_kind_num**2\n d_point_sub = d - eated_last_d\n eated = eated[:-1]\n point = max(point,point[-1]+t_point_sub+d_point_sub)\n eated_kind_num -= 1 \n#print(eated)\n\nprint(point)', 'n,k = [int(i) for i in input().split()]\ntd = [[int(i) for i in input().split()] for _ in range(n)]\n\n\ntd.sort(key = lambda x: x[0],reverse=True)\ntd.sort(key = lambda x: x[1],reverse=True)\n\n\n\neated_kind = []\neated_kind_num = 0\neated = []\nfor t,d in td:\n if t not in eated_kind:\n eated_kind.append(t)\n eated_kind_num += 1\n eated.append([t,d])\n \n \n \n if eated_kind_num == k:\n td = td[:i+1]\n break\n\nnot_eated = [i for i in td if i not in eated]\n\n\nif eated_kind_num < k:\n eated += not_eated[:k-eated_kind_num]\n not_eated = not_eated[k-eated_kind_num:]\n #print(eated)\n eated.sort(key = lambda x: x[1],reverse=True)\n \nt_point = eated_kind_num**2\nd_point = sum([i[1] for i in eated])\npoint = t_point + d_point\n\nfor t,d in not_eated:\n eated_last_t, eated_last_d = eated[-1]\n t_point_sub = (eated_kind_num-1)**2 - eated_kind_num**2\n d_point_sub = d - eated_last_d\n eated = eated[:-1]\n point = max(point,point+t_point_sub+d_point_sub)\n eated_kind_num -= 1\n if eated_kind_num == 1:\n break\n#print(eated)\n\nprint(point)', 'n,k = [int(i) for i in input().split()]\ntd = [[int(i) for i in input().split()] for _ in range(n)]\n\n\ntd.sort(key = lambda x: x[1],reverse=True)\n\n\nfix_eated_d=[]\n\nchange_eated_d=[]\n\neated_t = set()\nd_point = 0\n\n\nfor t,d in td[:k]:\n \n \n if t in eated_t:\n change_eated_d.append(d)\n \n \n else:\n fix_eated_d.append(d)\n eated_t.add(t)\n \n d_point += d\n \npoint = len(eated_t)**2 + d_point\n\n\nfor t,d in td[k:]:\n \n if not change_eated_d:\n break\n \n \n if t in eated_t:\n continue\n \n \n eated_t.add(t)\n d_point += d - change_eated_d.pop()\n point = max(point, len(eated_t)**2 + d_point)\n \nprint(point)\n\n\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s058721007', 's274302067', 's535766089']
[24320.0, 23012.0, 24716.0]
[2109.0, 2109.0, 435.0]
[1463, 1491, 1142]
p03148
u685263709
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import copy\nfrom collections import defaultdict\nN, K = map(int, input().split())\nTD = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: x[1], reverse=True)\n\ncur = TD[:K]\nbase = sum([x[1] for x in cur])\nvariety = defaultdict(int)\nfor t, d in cur:\n variety[t] += 1\nbonus = len(variety) ** 2\n\nans = base + bonus\nfor i in range(K, N):\n new_cur = copy.copy(cur)\n del new_cur[-1]\n new_cur.append(TD[i])\n new_var = copy.copy(variety)\n new_var[cur[-1][0]] -= 1\n if new_var[cur[-1][0]] == 0:\n del new_var[cur[-1][0]]\n new_var[TD[i][0]] += 1\n new_ans = base - cur[-1][1] + TD[i][1] - len(variety) ** 2 + len(new_var) ** 2\n if new_ans > ans:\n ans = new_ans\n cur = new_cur\n variety = new_var\n print(ans, cur, variety)\n\nprint(ans)', 'N, K = map(int, input().split())\nTD = sorted([list(map(int, input().split())) for i in range(N)], key=lambda x: -x[1])\nq = []\nans = 0\ns = set()\nfor i in range(K):\n ans += TD[i][1]\n if TD[i][0] in s:\n q.append(TD[i][1])\n s.add(TD[i][0])\nans += len(s) ** 2\nk1 = K\nans1 = ans\nwhile k1 < N and q:\n if TD[k1][0] not in s:\n ans1 = ans1 + TD[k1][1] - q.pop() - len(s) ** 2 + (len(s) + 1) ** 2\n ans = max(ans, ans1)\n s.add(TD[k1][0])\n k1 += 1\nprint(ans)\n']
['Wrong Answer', 'Accepted']
['s243544751', 's696494979']
[123368.0, 33024.0]
[2106.0, 494.0]
[802, 489]
p03148
u707124227
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from collections import deque\nn,k= map(int,input().split())\ntd=[]\nfor i in range(n):\n td.append(list(map(int,input().split())))\ntd.sort(key=lambda x:x[1],reverse=True)\nselect=[]\nnoselect=[]\ncat=[]\nfor tdi in td:\n if tdi[0] in cat:\n noselect.append(tdi)\n continue\n select.append(tdi)\n cat.append(tdi[0])\n if len(select)==k:\n break\ni=0\nwhile len(select) < k:\n select.append(noselect[i])\n i+=1\nnoselect=noselect[i:]\n\nselect.sort(key=lambda x:x[1])\nprint(8)\n', 'from collections import deque\nn,k= map(int,input().split())\ntd=[]\nfor i in range(n):\n td.append(list(map(int,input().split())))\ntd.sort(key=lambda x:x[1],reverse=True)\nselect=[]\nnoselect=[]\ncat=[]\nfor tdi in td:\n if tdi[0] in cat:\n noselect.append(tdi)\n continue\n select.append(tdi)\n cat.append(tdi[0])\n if len(select)==k:\n break\ni=0\nwhile len(select) < k:\n select.append(noselect[i])\n i+=1\nnoselect=noselect[i:]\n\nprint(8)\n', '\nfrom collections import deque\nn,k= map(int,input().split())\ntd=[]\nfor i in range(n):\n td.append(list(map(int,input().split())))\ntd.sort(key=lambda x:x[1],reverse=True)\nselect=[]\nnoselect=[]\ncat=[]\nfor tdi in td:\n if len(select) % 3 == 1:\n noselect.append(tdi)\n continue\n select.append(tdi)\n cat.append(tdi[0])\n if len(select)==k:\n break\ni=0\nwhile len(select) < k:\n select.append(noselect[i])\n i+=1\nnoselect=noselect[i:]\n\nprint(8)', 'from collections import deque\nn,k= map(int,input().split())\ntd=[]\nfor i in range(n):\n td.append(list(map(int,input().split())))\ntd.sort(key=lambda x:x[1],reverse=True)\nselect=[]\nnoselect=[]\ncat=[]\nfor tdi in td:\n if tdi[0] in cat:\n noselect.append(tdi)\n continue\n select.append(tdi)\n cat.append(tdi[0])\n if len(select)==k:\n break\nprint(8)\n', 'n,k=map(int,input().split())\ntd=[]\nfor _ in range(n):\n td.append(list(map(int,input().split())))\ntd.sort(key=lambda x:x[1],reverse=True)\ntd_core=[]\ntd_sel=[]\ntd_sub=[]\ncat=[0]*(n+1)\nfor i in range(n):\n if i < k and cat[td[i][0]]==0:\n td_core.append(td[i])\n cat[td[i][0]]=1\n elif i < k:\n td_sel.append(td[i])\n elif cat[td[i][0]]==0:\n td_sub.append(td[i])\n cat[td[i][0]]=1\n\n\n\n\nkiso=sum([x[1] for x in td_core])+sum([x[1] for x in td_sel])\nbns=len(td_core)\nans=kiso+bns**2\n\n\n\ntd_sel.sort(key=lambda x:x[1])\nfor i in range(min(len(td_sel),len(td_sub))):\n kiso-=td_sel[i][1]\n kiso+=td_sub[i][1]\n bns+=1\n ans=max(ans,kiso+bns**2)\nprint(ans)\n']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s052466610', 's781935455', 's783299089', 's961614787', 's305466237']
[29404.0, 29404.0, 29480.0, 29924.0, 29760.0]
[2109.0, 2105.0, 480.0, 2105.0, 547.0]
[496, 465, 472, 375, 1367]
p03148
u708615801
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from math import pow\n\ndef compute_score(target_collection):\n keys = {neta_point[0] for neta_point in target_collection}\n points = [neta_point[1] for neta_point in target_collection]\n cardinality = len(keys)\n score = pow(cardinality, 2) + sum(points)\n return score\n\n# exchange one record and compare\ndef optimize(full_collection, target_collection, target_collection_len, idx):\n while True:\n ex_record = full_collection[idx]\n # check on the idx-th record\n idx += 1\n # bump up for return value\n if ex_record in target_collection:\n continue # cardinality score will not increase\n else:\n for i in range(target_collection_len-1):\n if target_collection[i][0] == target_collection[i-1][0]:\n target_collection[i] = ex_record\n new_score = compute_score(target_collection)\n return new_score, target_collection, idx\n \n return 0, target_collection, idx\n\n\n\ndef cal_score(N, K, records):\n sorted_recs = sorted(records, reverse=True, key=lambda x: x[1])\n target_collection = sorted_recs[0:K]\n score = compute_score(target_collection)\n\n \n idx = K\n for i in range(K):\n new_score, new_target_collection, idx = optimize(sorted_recs, target_collection, K, idx)\n if new_score <= score: \n break\n else:\n score = new_score\n return score\n \nN, K = map(int, input().split())\nrecords = [list(map(int, input().split())) for i in range(N)] \nscore = cal_score(N, K, records)\nprint(score)\n', 'from math import pow\n\n\n\nN, K = map(int, input().split())\nrecords = [map(int, input().split()) for i in range(N)]\n\n\ndef compute_score(target_collection):\n keys = {neta_point[0] for neta_point in target_collection}\n points = [neta_point[1] for neta_point in target_collection]\n cardinality = len(keys)\n score = pow(cardinality, 2) + sum(points)\n return score\n\n# exchange one record and compare\ndef optimize(full_collection, target_collection, target_collection_len, idx):\n while True:\n ex_record = full_collection[idx]\n # check on the idx-th record\n idx += 1\n # bump up for return value\n if ex_record in target_collection:\n continue # cardinality score will not increase\n else:\n for i in range(target_collection_len-1):\n if target_collection[i][0] == target_collection[i-1][0]:\n target_collection[i] = ex_record\n new_score = compute_score(target_collection)\n return new_score, target_collection, idx\n \n return 0, target_collection, idx\n\n\n\ndef cal_score(N, K, records):\n sorted_recs = sorted(records, reverse=True, key=lambda x: x[1])\n target_collection = sorted_recs[0:K]\n score = compute_score(target_collection)\n\n \n idx = K\n for i in range(K):\n new_score, new_target_collection, idx = optimize(sorted_recs, target_collection, K, idx)\n if new_score <= score: \n break\n else:\n score = new_score\n return score\n \nscore =cal_score(N, K, record)\nprint(score)\n', 'from math import pow\n\n\n\n\n\n\ndef compute_score(target_collection):\n keys = {neta_point[0] for neta_point in target_collection}\n points = [neta_point[1] for neta_point in target_collection]\n cardinality = len(keys)\n score = pow(cardinality, 2) + sum(points)\n return score\n\n# exchange one record and compare\ndef optimize(full_collection, target_collection, target_collection_len, idx):\n while True:\n ex_record = full_collection[idx]\n # check on the idx-th record\n idx += 1\n # bump up for return value\n if ex_record in target_collection:\n continue # cardinality score will not increase\n else:\n for i in range(target_collection_len-1):\n if target_collection[i][0] == target_collection[i-1][0]:\n target_collection[i] = ex_record\n new_score = compute_score(target_collection)\n return new_score, target_collection, idx\n \n return 0, target_collection, idx\n\n\n\ndef cal_score(N, K, records):\n sorted_recs = sorted(records, reverse=True, key=lambda x: x[1])\n target_collection = sorted_recs[0:K]\n score = compute_score(target_collection)\n\n \n idx = K\n for i in range(K):\n new_score, new_target_collection, idx = optimize(sorted_recs, target_collection, K, idx)\n if new_score <= score: \n break\n else:\n score = new_score\n return score\n \nN, K = map(int, input().split())\nrecords = [tuple(map(int, input().split())) for i in range(N)] \nscore = cal_score(N, K, records)\nprint(score)\n', 'from math import pow\nfrom collections import deque, Counter\n# from loguru import logger\n\n\ndef cal_score(N, K, records):\n sorted_recs = sorted(records, key=lambda x: -x[1])\n target_queue = deque(sorted_recs[0:K]) # only allow pop() action, so use dequeue\n \n compare_queue = deque(sorted_recs[K:])\n count = Counter()\n for neta_point in target_queue:\n count[neta_point[0]] += 1\n # logger.debug(count)\n\n cardinality = len(count.keys())\n sum_target_points = sum([n_p[1] for n_p in target_queue])\n score = pow(cardinality, 2) + sum_target_points\n score = int(score)\n new_scores = deque()\n new_scores.append(score)\n # start iteration and comparing gain and lost\n while compare_queue:\n comp = compare_queue.popleft()\n if comp[0] in count:\n continue\n while target_queue:\n old = target_queue.pop()\n if count[old[0]] < 2:\n # swap this neta will not increase cardinality but lower neta point\n continue\n else: # check if score will go up\n inc = 2 * cardinality + 1\n dec = old[1] - comp[1]\n delta = inc - dec\n # logger.debug(f"delta is {delta}")\n \n # logger.debug("SOME")\n # logger.debug(f"{old} out")\n # logger.debug(f"{comp} in")\n # cardinality += 1\n \n # count[old[0]] -= 1\n # count[comp[0]] +=1\n # else: #increase cardinality will bring more lost than gain\n # # exit here\n # return score\n new_score = new_scores[-1] + delta\n new_scores.append(new_score)\n\n cardinality += 1\n count[old[0]] -= 1\n count[comp[0]] +=1\n # both queues are drained\n return max(new_scores)\nN, K = map(int, input().split())\nrecords = [map(int, input().split()) for i in range(N)]\nscore = cal_score(N, K, records)\nprint(score)', 'from math import pow\n\n\n\nN, K = map(int, input().split())\nrecords = [map(int, input().split()) for i in range(N)]\n\n\ndef compute_score(target_collection):\n keys = {neta_point[0] for neta_point in target_collection}\n points = [neta_point[1] for neta_point in target_collection]\n cardinality = len(keys)\n score = pow(cardinality, 2) + sum(points)\n return score\n\n# exchange one record and compare\ndef optimize(full_collection, target_collection, target_collection_len, idx):\n while True:\n ex_record = full_collection[idx]\n # check on the idx-th record\n idx += 1\n # bump up for return value\n if ex_record in target_collection:\n continue # cardinality score will not increase\n else:\n for i in range(target_collection_len-1):\n if target_collection[i][0] == target_collection[i-1][0]:\n target_collection[i] = ex_record\n new_score = compute_score(target_collection)\n return new_score, target_collection, idx\n \n return 0, target_collection, idx\n\n\n\ndef cal_score(N, K, records):\n sorted_recs = sorted(records, reverse=True, key=lambda x: x[1])\n target_collection = sorted_recs[0:K]\n score = compute_score(target_collection)\n\n \n idx = K\n for i in range(K):\n new_score, new_target_collection, idx = optimize(sorted_recs, target_collection, K, idx)\n if new_score <= score: \n break\n else:\n score = new_score\n return score\n \nscore = cal_score(N, K, records)\nprint(score)\n', 'from math import pow\nfrom collections import deque, Counter\nimport sys\nstdin = sys.stdin\ndef li(): return map(int, stdin.readline().split())\n\ndef cal_score(N, K, records):\n sorted_recs = sorted(records, key=lambda x: -x[1])\n target_queue = deque(sorted_recs[0:K]) # only allow pop() action, so use dequeue\n compare_queue = deque(sorted_recs[K:])\n distinct_set = set()\n dup_queue = deque()\n score = 0\n for neta_point in target_queue:\n score += neta_point[1]\n if neta_point[0] not in distinct_set:\n distinct_set.add(neta_point[0])\n else:\n dup_queue.append(neta_point)\n\n cardinality = len(distinct_set)\n score += pow(cardinality, 2)\n score = int(score)\n maybe_score = score\n # start iteration and comparing gain and lost\n while compare_queue:\n comp = compare_queue.popleft()\n if comp[0] in distinct_set:\n continue\n elif len(dup_queue) < 1:\n break\n else:\n old = dup_queue.pop()\n inc = 2 * len(distinct_set) + 1\n dec = old[1] - comp[1]\n delta = inc - dec\n maybe_score = maybe_score + delta\n score = max(score, maybe_score)\n\n distinct_set.add(comp[0])\n # both queues are drained\n return score\n\n\nN, K = li()\nrecords = [tuple(li()) for i in range(N)]\nscore = cal_score(N, K, records)\nprint(score)\n']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s346974547', 's673089999', 's746440203', 's794561748', 's968905389', 's222904517']
[32376.0, 49672.0, 21436.0, 52052.0, 50492.0, 22500.0]
[2106.0, 474.0, 2104.0, 444.0, 445.0, 262.0]
[1651, 1645, 1657, 2136, 1647, 1404]
p03148
u729133443
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import heapq\nn,k=map(int,input().split())\nz=[0,1]\nfor i in range(1,n):\n z.append(z[i]+2)\ns=sorted([list(map(int,input().split()))for _ in range(n)],key=lambda x:-x[1])\nq=[]\nv=0\nans=0\nl=[0]*-~n\nfor a in s[:k]:\n if not l[a[0]]:\n v+=1\n ans+=z[v]\n else:\n heapq.heappush(q,a[1])\n l[a[0]]=1\n ans+=a[1]\ntem=ans\nfor a in s[k:]:\n if not q:break\n if l[a[0]]:continue\n l[a[0]]=1\n v+=1\n t=heapq.heappop(q)\n tem=tem-t+a[1]+z[v]\n ans=max(ans,tem)\nprint(tem)', 'import heapq as h;I=lambda:list(map(int,input().split()));n,k=I();z=[i*2+1for i in range(n)];s=sorted([I()for _ in[0]*n],key=lambda x:-x[1]);q=[];v=T=0;l=[0]*-~n\nfor a in s[:k]:\n if l[a[0]]:h.heappush(q,a[1])\n else:A+=z[v];v+=1\n l[a[0]]=1;A+=a[1]\nT=A\nfor a in s[k:]:\n if not q:break\n if l[a[0]]^1:l[a[0]]=1;t=h.heappop(q);T=T-t+a[1]+z[v];v+=1;A=max(A,T)\nprint(A)', "from heapq import*\nI=lambda:list(map(int,input().split()))[::-1]\nk,n=I()\nq=[]\nv=i=T=A=0\nl=[0]*-~n\nfor b,a in sorted(eval('I(),'*n))[::-1]:\n if i<k:\n if l[a]:heappush(q,b)\n else:T+=v*2+1;v+=1\n T+=b\n elif l[a]^1and q:T+=b+v*2+1-heappop(q);v+=1\n A=max(A,T);i+=1;l[a]=1\nprint(A)"]
['Wrong Answer', 'Runtime Error', 'Accepted']
['s278279615', 's552905532', 's561535919']
[37060.0, 36964.0, 113260.0]
[554.0, 553.0, 818.0]
[500, 362, 277]
p03148
u810625173
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n, m = [int(i) for i in input().split()]\ntd = [[int(i) for i in input().split()] for n in range(n)]\ntd.sort(key=lambda x:-x[1])\nmemo = set()\na = []\nfor t, d in td:\n if t in memo:\n a.append((d, 0))\n else:\n a.append((d, 1))\n memo.add(t)\na = [(-x, x, d) for x, d in a]\nimport heapq\nheapq.heapify(a)\nval = 0\nkind = 0\nb = []\nfor _ in range(m):\n ele = heapq.heappop(a)\n val += ele[1]\n kind += ele[2]\n if ele[2] == 0:\n b.append(ele[1])\nans = val + kind ** 2', 'n, m = [int(i) for i in input().split()]\ntd = [[int(i) for i in input().split()] for n in range(n)]\ntd.sort(key=lambda x:-x[1])\nmemo = set()\na = []\nfor t, d in td:\n if t in memo:\n a.append((d, 0))\n else:\n a.append((d, 1))\n memo.add(t)\na = [(-x, x, d) for x, d in a]\nimport heapq\nheapq.heapify(a)\nval = 0\nkind = 0\nb = []\nfor _ in range(m):\n ele = heapq.heappop(a)\n val += ele[1]\n kind += ele[2]\n if ele[2] == 0:\n b.append(ele[1])\nans = val + kind ** 2\nwhile (len(a) > 0 and len(b)>0):\n val -= b.pop()\n flag = False\n while(len(a) > 0):\n elem = heapq.heappop(a)\n if elem[2] == 1:\n flag = True\n break\n if not flag:\n break\n val += elem[1]\n kind += 1\n tmpans = val + kind ** 2\n if tmpans > ans:\n ans = tmpans\nprint(ans)']
['Wrong Answer', 'Accepted']
['s668503416', 's093100517']
[43516.0, 43468.0]
[580.0, 600.0]
[466, 759]
p03148
u814781830
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['from heapq import heappush, heappop\nN, K = map(int, input().split())\nTD = [list(map(int, input().split())) for _ in range(N)]\nTD.sort(key=lambda x:x[1], reverse=True)\nmuptiple = set()\n\nfor i in range(len(TD)):\n flg = 0\n if TD[i][0] not in muptiple:\n muptiple.add(TD[i][0])\n flg = 1\n TD[i][0] = flg\nTD.reverse()\n\nret = []\npoint = 0\nvari = 0\ntotal = 0\nfor i in range(K):\n v = TD.pop()\n vari += v[0]\n point += v[1]\n if not v[0]:\n heappush(ret, t)\n\ntotal = vari ** 2 + point\n\nwhile len(TD) > 0 and len(ret) > 0:\n v = TD.pop()\n if v[0] == 0:\n continue\n pre_t = heappop(ret)\n point -= pre_t - v[1]\n vari += 1\n tmp = vari ** 2 + point\n total = max(total, tmp)\n\nprint(total)', 'n, k = map(int,input().split())\ninputarray = []\nfor i in range(n):\n inputarray.append([int(i) for i in input().split()])\nt = [i[0] for i in inputarray]\nd = [i[1] for i in inputarray]\nprint(n,k)\nprint(t)\nprint(d)\ndef combinationListRecursive(data, r):\n if r == 0 or r > len(data):\n return []\n\n result = []\n _combinationListRecursive(data, r, 0, [], result)\n return result\n\n\ndef _combinationListRecursive(data, r, start, progress, result):\n if r == 0:\n result.append(progress)\n return\n\n for i in range(start, len(data)):\n _combinationListRecursive(data, r - 1, i + 1, progress + [data[i]], result)\n\nresult = combinationListRecursive(range(len(d)), k)\nbest = 0\nfor i in result:\n tarray = []\n dtmp = 0\n for k in range(k):\n dtmp += d[i[k]]\n tarray.append(t[i[k]])\n tlist = list(set(tarray))\n ttmp = len(tlist) ** 2\n if best < dtmp + ttmp:\n best = dtmp + ttmp\nprint(best)', 'n, k = map(int,input().split())\nt = [int(input().split()[0]) for i in range(n)]\nd = [int(input().split()[1]) for i in range(n)]\ndef combinationListRecursive(data, r):\n if r == 0 or r > len(data):\n return []\n\n result = []\n _combinationListRecursive(data, r, 0, [], result)\n return result\n\n\ndef _combinationListRecursive(data, r, start, progress, result):\n if r == 0:\n result.append(progress)\n return\n\n for i in range(start, len(data)):\n _combinationListRecursive(data, r - 1, i + 1, progress + [data[i]], result)\n\nresult = combinationListRecursive(range(len(d)), k)\nbest = 0\nfor i in result:\n tarray = []\n dtmp = 0\n for k in range(k):\n dtmp += d[i[k]]\n tarray.append(t[i[k]])\n tlist = list(set(tarray))\n ttmp = len(tlist) ** 2\n if best < dtmp + ttmp:\n best = dtmp + ttmp\nprint(best)', 'from heapq import heappush, heappop\nN, K = map(int, input().split())\nTD = [list(map(int, input().split())) for _ in range(N)]\nTD.sort(key=lambda x:x[1], reverse=True)\nmuptiple = set()\nfor i in range(len(TD)):\n flg = 0\n if TD[i][0] not in muptiple:\n muptiple.add(TD[i][0])\n flg = 1\n TD[i][0] = flg\nTD.reverse()\nret = []\npoint = 0\nvari = 0\ntotal = 0\nfor i in range(K):\n v = TD.pop()\n vari += v[0]\n point += v[1]\n if not v[0]:\n heappush(ret, v[1])\n\ntotal = vari ** 2 + point\n\nwhile len(TD) > 0 and len(ret) > 0:\n v = TD.pop()\n if v[0] == 0:\n continue\n pre_t = heappop(ret)\n point -= pre_t - v[1]\n vari += 1\n tmp = vari ** 2 + point\n total = max(total, tmp)\n\nprint(total)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s117297600', 's557461610', 's591162474', 's496681259']
[34288.0, 411508.0, 7084.0, 34288.0]
[481.0, 2130.0, 221.0, 525.0]
[736, 925, 838, 737]
p03148
u864197622
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N, K = map(int, input().split())\nX = []\nfor i in range(N):\n x, y = map(int, input().split())\n X.append([i, x, y])\n\nX = sorted(X, key = lambda x:x[2])[::-1]\n\np = 0\nL = [0] * (N+1)\nbonus = 0\nfor i in range(K):\n p += X[i][2]\n if L[X[i][1]] == 0:\n bonus += 1\n \n L[X[i][1]] += 1\n\np += bonus ** 2\nma = p\ni = K-1\nj = K\nwhile True:\n while j < N and L[X[j][0]]:\n j += 1\n if j == N:\n break\n else:\n while i >= 0 and L[X[i][0]] <= 1:\n i -= 1\n if i < 0:\n break\n else:\n L[X[i][0]] -= 1\n L[X[j][0]] += 1\n p -= X[i][2]\n p += X[j][2]\n p += bonus * 2 + 1\n bonus += 1\n ma = max(ma, p)\n \n j += 1\n \nprint(ma)\n', 'N, K = map(int, input().split())\nX = []\nfor i in range(N):\n x, y = map(int, input().split())\n X.append([i, x, y])\n\nX = sorted(X, key = lambda x:x[2])[::-1]\n\np = 0\nL = [0] * (N+1)\nbonus = 0\nfor i in range(K):\n p += X[i][2]\n if L[X[i][1]] == 0:\n bonus += 1\n \n L[X[i][1]] += 1\n\np += bonus ** 2\nma = p\ni = K-1\nj = K\nwhile True:\n while j < N and L[X[j][1]]:\n j += 1\n if j == N:\n break\n else:\n while i >= 0 and L[X[i][1]] <= 1:\n i -= 1\n if i < 0:\n break\n else:\n L[X[i][1]] -= 1\n L[X[j][1]] += 1\n p -= X[i][2]\n p += X[j][2]\n p += bonus * 2 + 1\n bonus += 1\n ma = max(ma, p)\n \n i -= 1\n j += 1\n \nprint(ma)\n\n']
['Wrong Answer', 'Accepted']
['s696011667', 's633770904']
[25276.0, 25276.0]
[470.0, 510.0]
[777, 793]
p03148
u894258749
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import numpy as np\nN, K = map(int,input().split())\ntd = np.empty((N,2),dtype=np.int64)\nfor i in range(N):\n td[i] = list(map(int,input().split()))\n\nt = td[:,0]-1\nd = td[:,1]\norder1=np.argsort(d)[::-1]\nmins = len(set(t[order1[:K]]))\n\nbest = -np.ones(N,dtype=np.int64)\nfor i in range(N):\n if best[t[i]] < 0 or d[i] > d[best[t[i]]]:\n best[t[i]]=i\n\nbestmenu = np.array(list(set(best) - set([-1])),dtype=np.int64)\nothermenu = np.array(list(set(range(N)) - set(bestmenu)),dtype=np.int64)\n\nmaxs = min(len(bestmenu),K)\nans = 0\nbests=0\nsorted_d_best=np.sort(d[bestmenu])\nsorted_d_other=np.sort(d[othermenu])\nbo\nfor s in range(mins,maxs+1):\n score = s*s + sorted_d_best[-s:].sum() + sorted_d_other[-(K-s):].sum()\n if score > ans:\n bests=s\n ans = score\n\nprint(ans)', 'import numpy as np\nN, K = map(int,input().split())\ntd = np.empty((N,2),dtype=np.int64)\nfor i in range(N):\n td[i] = list(map(int,input().split()))\n\nt = td[:,0]-1\nd = td[:,1]\norder1=np.argsort(d)[::-1]\nmins = len(set(t[order1[:K]]))\n\nbest = -np.ones(N,dtype=np.int64)\nfor i in range(N):\n if best[t[i]] < 0 or d[i] > d[best[t[i]]]:\n best[t[i]]=i\n\nbestmenu = np.array(list(set(best) - set([-1])),dtype=np.int64)\nothermenu = np.array(list(set(range(N)) - set(bestmenu)),dtype=np.int64)\n\nmaxs = min(len(bestmenu),K)\nans = 0\nbests=0\nsorted_d_best=np.sort(d[bestmenu])[::-1]\nsorted_d_other=np.sort(d[othermenu])[::-1]\nfor s in range(mins,maxs+1):\n score = s*s + sorted_d_best[:s].sum() + sorted_d_other[:(K-s)].sum()\n if score > ans:\n bests=s\n ans = score\n\nprint(ans)']
['Runtime Error', 'Accepted']
['s172595671', 's714976817']
[34876.0, 34748.0]
[994.0, 1683.0]
[785, 792]
p03148
u901098617
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['n, k = map(int, input().split())\nh = []\nfor i in range(n):\n t, d = map(int, input().split())\n h.append((t,d))\nh.sort(key=lambda x: -x[1])\n\ntaste = 0\ntypen = 0\ntypecnt = {}\nbad = []\n\n\nfor i in range(k):\n typecnt[h[i][0]] = typecnt.get(h[i][0], 0) + 1\n if(typecnt[h[i][0]] == 1):\n typen += 1\n else:\n bad.append(h[i][1])\n taste += h[i][1]\n\n\nans = taste + typen**2\n\nfor i in range(k, n):\n if(len(bad) == 0):\n break\n typen += 1\n taste -= bad.pop()\n taste += h[i][1]\n ans = max(ans, taste + typen**2)\n\nprint(ans)', 'n, k = map(int, input().split())\nh = []\nfor i in range(n):\n t, d = map(int, input().split())\n h.append((t,d))\nh.sort(key=lambda x: -x[1])\n\ntaste = 0\ntypen = 0\ntypecnt = {}\nbad = []\n\n\nfor i in range(k):\n typecnt[h[i][0]] = typecnt.get(h[i][0], 0) + 1\n if(typecnt[h[i][0]] == 1):\n typen += 1\n else:\n bad.append(h[i][1])\n taste += h[i][1]\n\n# print(h)\n# print(typecnt)\n# print(bad)\n\nans = taste + typen**2\n\nfor i in range(k, n):\n if(len(bad) == 0):\n break\n cnt = typecnt.get(h[i][0], 0)\n if(cnt != 0):\n continue\n else:\n typecnt[h[i][0]] = cnt + 1\n typen += 1\n taste -= bad.pop()\n taste += h[i][1]\n ans = max(ans, taste + typen**2)\n\nprint(ans)']
['Wrong Answer', 'Accepted']
['s434941337', 's782400429']
[21552.0, 21664.0]
[459.0, 462.0]
[560, 715]
p03148
u903948194
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['def seek_dup(s):\n t_list = [t for (t, d) in s]\n #d_list = [d for (t, d) in s]\n \n for t, d in reversed(s):\n if t_list.count(t) > 1:\n return (t, d)\n else:\n continue\n \n return None\n \nN, K = map(int, input().split())\nmenu_ = []\n \nfor i in range(N):\n t, d = map(int, input().split())\n menu_.append((t, d))\n \nmenu = sorted(menu_, key = lambda x:x[1], reverse=True)\np = sum([d for (t, d) in menu[:K]]) + len(set([t for (t, d) in menu[:K]]))**2\n \nselected_menu = menu[:K]\n#t_list = [t for (t, d) in selected_menu]\n#d_list = [d for (t, d) in selected_menu]\nans = p\nfor m in menu[K:]:\n t_list = [t for (t, d) in selected_menu]\n d_list = [d for (t, d) in selected_menu]\n \n if m[0] not in t_list:\n d = seek_dup(selected_menu)\n if d == None:\n continue\n \n selected_menu.remove(d)\n selected_menu.append(m)\n \n p += (m[1] - d[1]) + 2 * len(set(t_list)) - 1 \n #print(ans, p)\n ans = max(ans, p)\n \nprint(ans) ', 'def seek_dup(s):\n t_list = [t for (t, d) in s]\n #d_list = [d for (t, d) in s]\n\n for t, d in reversed(s):\n if t_list.count(t) > 1:\n return (t, d)\n else:\n continue\n \n return None\n\nN, K = map(int, input().split())\nmenu = []\n\nfor i in range(N):\n t, d = map(int, input().split())\n menu.append((t, d))\n\nsorted(menu, key = lambda x:x[1], reverse=True)\nans = sum([d for (t, d) in menu[:K]]) + len(set([t for (t, d) in menu[:K]]))**2\n\nselected_menu = menu[:K]\n#t_list = [t for (t, d) in selected_menu]\n#d_list = [d for (t, d) in selected_menu]\np = ans\nfor m in menu[K:]:\n t_list = [t for (t, d) in selected_menu]\n d_list = [d for (t, d) in selected_menu]\n \n if m[0] not in t_list:\n d = seek_dup(selected_menu)\n if d == None:\n continue\n \n selected_menu.remove(d)\n selected_menu.append(m)\n \n p += (m[1] - d[1]) + 2 * len(set(t_list)) - 1 \n #print(ans, p)\n ans = max(ans, p)\n\nprint(ans) ', 'N, K = map(int, input().split())\nmenu = []\n\nfor i in range(N):\n t, d = map(int, input().split())\n menu.append((t, d))\n\nsorted(menu, key = lambda x:x[1], reverse=True)\nneta = set()\nduplicates = []\n\nfor m in menu[:K]:\n if m[0] in neta:\n duplicates.append(m[1])\n else:\n neta.add(m[0])\n\np = sum([d for (t, d) in menu[:K]]) + len(neta)**2\nans = p\n\nfor m in menu[K:]:\n if m[0] not in neta:\n neta.add(m[0])\n duplicate = duplicates.pop()\n \n p += (m[1] - duplicate) + 2 * len(neta) + 1 \n #print(ans, p)\n ans = max(ans, p)\n\nprint(ans) ', '\ndef seek_dup(s):\n t_list = [t for (t, d) in s]\n #d_list = [d for (t, d) in s]\n\n for t, d in reversed(s):\n if t_list.count(t) > 1:\n return (t, d)\n else:\n continue\n \n return None\n\nN, K = map(int, input().split())\nmenu = []\n\nfor i in range(N):\n t, d = map(int, input().split())\n menu.append((t, d))\n\nsorted(menu, key = lambda x:x[1], reverse=True)\nans = sum([d for (t, d) in menu[:K]]) + len(set([t for (t, d) in menu[:K]]))**2\n\nselected_menu = menu[:K]\n#t_list = [t for (t, d) in selected_menu]\n#d_list = [d for (t, d) in selected_menu]\np = ans\nfor m in menu[K:]:\n t_list = [t for (t, d) in selected_menu]\n d_list = [d for (t, d) in selected_menu]\n \n if m[0] not in t_list:\n d = seek_dup(selected_menu)\n if d == None:\n continue\n \n #selected_menu.remove(d)\n #selected_menu.append(m)\n \n p += (m[1] - d[1]) + 2 * len(set(t_list)) + 1 \n #print(ans, p)\n ans = max(ans, p)\n\nprint(ans) \n ', 'import itertools\n\nN, K = map(int, input().split())\nmenu = {}\n\nt0 = time.time()\nfor i in range(N):\n t, d = map(int, input().split())\n menu[i] = (t, d)\n\ndef manzoku(s):\n return sum([menu[i][1] for i in s]) + len(set([menu[i][0] for i in s]))**2\n\nshushi = itertools.combinations(menu, K)\nprint(max([manzoku(c) for c in shushi]))\n', '\nN, K = map(int, input().split())\nmenu = []\n\nfor i in range(N):\n t, d = map(int, input().split())\n menu.append((t, d))\n\nmenu = sorted(menu, key = lambda x:x[1], reverse=True)\nneta = set()\nduplicates = []\n\nfor m in menu[:K]:\n if m[0] in neta:\n duplicates.append(m[1])\n else:\n neta.add(m[0])\n\np = sum([d for (t, d) in menu[:K]]) + len(neta)**2\nans = p\n\nfor m in menu[K:]:\n if m[0] not in neta:\n neta.add(m[0])\n duplicate = duplicates.pop()\n \n p += (m[1] - duplicate) + 2 * len(neta) + 1 \n #print(ans, p)\n ans = max(ans, p)\n\nprint(ans) ', 'def seek_dup(s):\n t_list = [t for (t, d) in s]\n #d_list = [d for (t, d) in s]\n \n for t, d in reversed(s):\n if t_list.count(t) > 1:\n return (t, d)\n else:\n continue\n \n return None\n \nN, K = map(int, input().split())\nmenu_ = []\n \nfor i in range(N):\n t, d = map(int, input().split())\n menu_.append((t, d))\n \nmenu = sorted(menu_, key = lambda x:x[1], reverse=True)\np = sum([d for (t, d) in menu[:K]]) + len(set([t for (t, d) in menu[:K]]))**2\n \nselected_menu = menu[:K]\n#t_list = [t for (t, d) in selected_menu]\n#d_list = [d for (t, d) in selected_menu]\nans = p\nfor m in menu[K:]:\n t_list = [t for (t, d) in selected_menu]\n d_list = [d for (t, d) in selected_menu]\n \n if m[0] not in t_list and len(set(t_list)) == len(t_list):\n d = seek_dup(selected_menu)\n if d == None:\n continue\n \n selected_menu.remove(d)\n selected_menu.append(m)\n \n p += (m[1] - d[1]) + 2 * len(set(t_list)) - 1 \n #print(ans, p)\n ans = max(ans, p)\n \nprint(ans) ', 'N, K = map(int, input().split())\nmenu_ = []\n\nfor i in range(N):\n t, d = map(int, input().split())\n menu_.append((t, d))\n\nmenu = sorted(menu_, key = lambda x:x[1], reverse=True)\nneta = set()\nduplicates = []\n\nfor m in menu[:K]:\n if m[0] in neta:\n duplicates.append(m[1])\n else:\n neta.add(m[0])\n\np = sum([d for (t, d) in menu[:K]]) + len(neta)**2\nans = p\n\nfor m in menu[K:]:\n if m[0] not in neta and duplicates:\n neta.add(m[0])\n duplicate = duplicates.pop()\n \n p += (m[1] - duplicate) + 2 * len(neta) - 1 \n #print(ans, p)\n ans = max(ans, p)\n\nprint(ans) \n ']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s001180598', 's260115160', 's291002516', 's407870666', 's525059478', 's965898880', 's993372050', 's940815988']
[22156.0, 21308.0, 20204.0, 21332.0, 3064.0, 20316.0, 22156.0, 21100.0]
[2105.0, 2105.0, 410.0, 2105.0, 18.0, 428.0, 2105.0, 440.0]
[1020, 1006, 596, 1017, 335, 605, 1056, 629]
p03148
u922901775
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['#!/usr/bin/env python3\nimport sys\nfrom collections import defaultdict\nfrom itertools import accumulate\nimport heapq\n\ndef solve(N: int, K: int, t: "List[int]", d: "List[int]"):\n sushi = defaultdict([])\n for i in range(N):\n sushi[t[i]].append(d[i])\n\n A = [] \n B = [] \n \n for v in sushi.values():\n v.sort(reverse=True)\n A.append(v[0])\n B.extend(v[1:])\n A.sort(reverse=True)\n B.sort(reverse=True)\n\n X = [0] + [x for x in accumulate(A)] \n Y = [0] + [y for y in accumulate(B)] \n\n res = 0\n for i in range(1, min(len(X), K + 1)):\n if K - i < len(Y):\n res = max(res, X[i] + Y[K - i] + i ** 2) \n \n \n \n print(res)\n return\n\n\n# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n t = [int()] * (N) # type: "List[int]" \n d = [int()] * (N) # type: "List[int]" \n for i in range(N):\n t[i] = int(next(tokens))\n d[i] = int(next(tokens))\n solve(N, K, t, d)\n\nif __name__ == \'__main__\':\n main()\n', 'N, K = map(int, input().split())\nsushi = [tuple(map(int, input().split())) for i in range(N)]\npoint = [0 for i in range(K+1)]\n\nsushi.sort(lambda x: x[1])\n\neaten_sushi = [sushi[i] for i in range(K)]\neaten_variation = [s[0] for s in eaten_sushi]\nvariation_number = len(set(eaten_variation))\nbase = sum([s[1] for s in eaten_sushi])\nbonus = variation_number ** 2\npoint[variation_number] = base + bonus\n\nfor i in range(K, N):\n if sushi[i][0] in eaten_variation:\n continue\n\n for j in range(K-1, 0, -1):\n if eaten_variation.count(eaten_sushi[j][0]) == 1:\n continue\n eaten_sushi.pop(j)\n eaten_sushi.append(sushi[i])\n eaten_variation = [s[0] for s in eaten_sushi]\n variation_number = len(set(eaten_variation))\n base = sum([s[1] for s in eaten_sushi])\n bonus = variation_number ** 2\n point[variation_number] = base + bonus\n break\n\nprint(max(point))\n', '#!/usr/bin/env python3\nimport sys\nfrom collections import defaultdict\nfrom itertools import accumulate\nimport heapq\n\ndef solve(N: int, K: int, t: "List[int]", d: "List[int]"):\n sushi = defaultdict(list)\n for i in range(N):\n sushi[t[i]].append(d[i])\n\n A = [] \n B = [] \n \n for v in sushi.values():\n v.sort(reverse=True)\n A.append(v[0])\n B.extend(v[1:])\n A.sort(reverse=True)\n B.sort(reverse=True)\n\n X = [0] + [x for x in accumulate(A)] \n Y = [0] + [y for y in accumulate(B)] \n\n res = 0\n for i in range(1, min(len(X), K + 1)):\n if K - i < len(Y):\n res = max(res, X[i] + Y[K - i] + i ** 2) \n \n \n \n print(res)\n return\n\n\n# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n K = int(next(tokens)) # type: int\n t = [int()] * (N) # type: "List[int]" \n d = [int()] * (N) # type: "List[int]" \n for i in range(N):\n t[i] = int(next(tokens))\n d[i] = int(next(tokens))\n solve(N, K, t, d)\n\nif __name__ == \'__main__\':\n main()\n']
['Runtime Error', 'Runtime Error', 'Accepted']
['s175489886', 's615227103', 's593232471']
[11244.0, 17416.0, 35096.0]
[126.0, 319.0, 301.0]
[1920, 926, 1922]
p03148
u924691798
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import sys\ninput = sys.stdin.readline\n\nN, K = map(int, input().split())\nnums = []\nfor i in range(N):\n t, d = map(int, input().split())\n nums.append((d, t))\nnums.sort(reverse=True)\nse = set()\nkind = 0\na1 = []\na2 = []\nrest = []\nfor i, n in nums:\n if i < K:\n if not n[1] in se:\n se.add(n[1])\n kind += 1\n a1.append(n)\n else:\n a2.append(n)\n else:\n rest.append(n)\npoints = 0\nfor (d, t) in a1: points += d\nfor (d, t) in a2: points += d\nans = points + pow(kind, 2)\na2.sort()\nfor i, (d, t) in enumerate(rest):\n if t in se: continue\n if i >= len(a2): break\n points -= a2[i]\n points += d\n kind += 1\n ans = max(ans, points+pow(kind, 2))\nprint(ans)\n', 'import sys\ninput = sys.stdin.readline\n\nN, K = map(int, input().split())\nnums = []\nfor i in range(N):\n t, d = map(int, input().split())\n nums.append((d, t))\nnums.sort(reverse=True)\nse = set()\ndoubled = []\nrest = []\npoints = 0\nfor i, n in enumerate(nums):\n if i < K:\n if not n[1] in se:\n se.add(n[1])\n else:\n doubled.append(n)\n points += n[0]\n else:\n rest.append(n)\nans = points + pow(len(se), 2)\nidx = len(doubled)-1\nfor d, t in rest:\n if idx < 0: break\n if t in se: continue\n points -= doubled[idx][0]\n idx -= 1\n points += d\n se.add(t)\n ans = max(ans, points+pow(len(se), 2))\nprint(ans)\n']
['Runtime Error', 'Accepted']
['s879834328', 's393319537']
[17640.0, 19188.0]
[266.0, 312.0]
[731, 670]
p03148
u945181840
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['import sys\nfrom operator import itemgetter\nread = sys.stdin.read\n\nN, K, *td = map(int, read().split())\ntd = sorted(zip(*[iter(td)] * 2), key=itemgetter(1), reverse=True)\n\nstack = []\ntaste = 0\nneta_group = set()\nfor t, d in td[:K]:\n taste += d\n if t in neta_group:\n stack.append(d)\n else:\n neta_group.add(t)\n\nvariety = len(neta_group)\npoints = taste + variety ** 2\ncandidates = [points]\n\nif N == K:\n print(points)\n exit()\n\nrest = list(reversed(td[K::]))\n\nwhile rest and stack:\n print(points, variety)\n t1, d1 = rest.pop()\n d2 = stack.pop()\n points = points - d2 + d1 - variety ** 2 + (variety + 1) ** 2\n\n candidates.append(points)\n variety += 1\n\nprint(max(candidates))', 'import sys\nfrom operator import itemgetter\nread = sys.stdin.read\n\nN, K, *td = map(int, read().split())\ntd = sorted(zip(*[iter(td)] * 2), key=itemgetter(1), reverse=True)\n\nstack = []\ntaste = 0\nneta_group = set()\nfor t, d in td[:K]:\n taste += d\n if t in neta_group:\n stack.append(d)\n else:\n neta_group.add(t)\n\nvariety = len(neta_group)\ncandidates = [taste + variety ** 2]\n\nif N == K:\n print(candidates[0])\n exit()\n\nrest = list(reversed(td[K::]))\n\nwhile rest and stack:\n t1, d1 = rest.pop()\n if t1 not in neta_group:\n neta_group.add(t1)\n d2 = stack.pop()\n variety += 1\n taste = taste - d2 + d1\n\n candidates.append(taste + variety ** 2)\n\nprint(max(candidates))']
['Wrong Answer', 'Accepted']
['s100224112', 's549918148']
[25316.0, 25316.0]
[226.0, 201.0]
[714, 726]
p03148
u947883560
2,000
1,048,576
There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: * The satisfaction is the sum of the "base total deliciousness" and the "variety bonus". * The base total deliciousness is the sum of the deliciousness of the pieces you eat. * The variety bonus is x*x, where x is the number of different kinds of toppings of the pieces you eat. You want to have as much satisfaction as possible. Find this maximum satisfaction.
['N, K = [int(x) for x in input().split()]\ntd = [tuple([int(x) for x in input().split()]) for _ in range(N)]\nINF = 10**9\nprint(td)\n\n\ndef score(a):\n kiso = sum([x[1] for x in a])\n # print(a)\n bonus = len(set([x[0] for x in a]))**2\n return kiso + bonus\n\n\ntotal = score(td)\nfor i in range(N, K, -1):\n max_score = -INF\n useless_neta = 0\n for neta in td:\n te = td.copy()\n te.remove(neta)\n kari = score(te)\n if kari > max_score:\n max_score = kari\n useless_neta = neta\n td.remove(useless_neta)\n print(td)\nprint(score(td))\n', 'import itertools\nimport heapq\nN, K = [int(x) for x in input().split()]\norig_td = [tuple([int(x) for x in input().split()]) for _ in range(N)]\ntd = sorted(orig_td.copy(), key=lambda x: x[1], reverse=True)\nINF = 10**9\n# print(td)\n\n\ndef score(a):\n kiso = sum([x[1] for x in a])\n bonus = len(set([x[0] for x in a]))**2\n return kiso + bonus\n\n\nfirst = []\nsecond = []\nkind = set()\nfor i in range(K):\n if td[i][0] not in kind:\n first.append(td[i])\n kind.add(td[i][0])\n else:\n second.append(td[i])\n\nbest_ans = sum([x[1] for x in first + second]) + len(first)**2\n\nfor k in range(K, N):\n if len(second) == 0:\n break\n if td[k] in kind:\n continue\n\n a = second.pop(-1)\n kind.add(td[k][0])\n first.append(td[k])\n ans = sum([x[1] for x in first + second]) + len(first)**2\n # print(first, second, ans)\n if best_ans < ans:\n best_ans = ans\nprint(best_ans)\n', 'N, K = [int(x) for x in input().split()]\ntd = sorted([[int(x) for x in input().split()] for _ in range(N)],\n key=lambda x: x[1], reverse=True)\nINF = 10**9\n# print(td)\n\nfirst = []\nsecond = []\nkind = set()\nfor i in range(K):\n if td[i][0] not in kind:\n first.append(td[i])\n kind.add(td[i][0])\n else:\n second.append(td[i])\n\nyummy = sum([x[1] for x in first + second])\nbest_ans = yummy + len(kind)**2\n\nfor k in range(K, N):\n if len(second) == 0:\n break\n if td[k][0] in kind:\n continue\n\n a = second.pop(-1)\n yummy -= a[1]\n kind.add(td[k][0])\n first.append(td[k])\n yummy += td[k][1]\n ans = yummy + len(kind)**2\n # print(first, second, ans)\n if best_ans < ans:\n best_ans = ans\nprint(best_ans)\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s300221884', 's766947965', 's760649728']
[29108.0, 22784.0, 25472.0]
[2105.0, 2105.0, 477.0]
[590, 917, 774]
p03186
u003928116
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a, b, c = map(int, input().split())\nif a + b + 1 >= c:\n c = b + c\n \nelif a + b > c:\n c = a + b + 1 + b\ninput(c) \n ', 'a, b, c = map(int, input().split())\nif a + b + 1 >= c:\n c = b + c\n \nelif a + b < c:\n c = a + b + 1 + b\ninput(c) \n ', 'a, b, c = map(int, input().split())\nif a+b >= c:\n c = c + 1\n \nelse a + b < c:\n c = c + 1\nprint(c) \n ', 'a,b,c=map(int,input().split())\nif a+b>=c:\n print(b+c)\nelse:\n print(a+2*min(b,c)+1)']
['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted']
['s165367210', 's312968499', 's409775278', 's395260565']
[2940.0, 2940.0, 2940.0, 2940.0]
[17.0, 17.0, 17.0, 18.0]
[128, 128, 114, 84]
p03186
u004025573
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a, b, c = map(int, input().split())\n\nif a+b<=c:\n print(a+b+b+1)\nelse:\n print(b+c)', 'a, b, c = map(int, input().split())\n\nif a+b<c:\n print(a+b+b+1)\nelse:\n print(b+c)']
['Wrong Answer', 'Accepted']
['s484221192', 's719931979']
[2940.0, 2940.0]
[18.0, 18.0]
[87, 86]
p03186
u016282832
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
["print('入力してください')\ninput_list = input().split(' ')\nA = int(input_list[0])\nB = int(input_list[1])\nC = int(input_list[2])\n\nif A + B >= C: \n print(B + C)\nelse: \n print(1 + A + B + B)\n", "input_list = input().split(' ')\nA = int(input_list[0])\nB = int(input_list[1])\nC = int(input_list[2])\n\nif A + B >= C: \n print(B + C)\nelse: \n print(1 + A + B + B)\n"]
['Wrong Answer', 'Accepted']
['s116896899', 's993025848']
[2940.0, 2940.0]
[18.0, 18.0]
[369, 335]
p03186
u018250459
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['A, B, C = map(int, input().split())\nif A + B >= C - 1:\n print("{}".format(B+C)\nelse:\n print("{}".format(A+2*B+1))', 'A, B, C = map(int, input().split())\nif A + B >= C - 1:\n print(B+C)\nelse:\n print(A+2*B+1)']
['Runtime Error', 'Accepted']
['s855982019', 's438757470']
[2940.0, 3064.0]
[18.0, 17.0]
[119, 94]
p03186
u020798319
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c = map(int,input().split())\nif b - 1 >= c:\n print(c+b)\nelif b-1 < c and a+b-1>=c : \n print(b+c)\nelif a+b-1 < c:\n print(b+b+a+1)', 'a,b,c = map(int,input().split())\nif a+b < c:\n print(b+b+a+1)\nelse:\n print(b+c)']
['Wrong Answer', 'Accepted']
['s658815371', 's909817843']
[9064.0, 9048.0]
[25.0, 25.0]
[135, 80]
p03186
u023229441
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c=map(int,input().split())\nprint(min(a+b+1,c))', 'a,b,c=map(int,input().split())\nif a+b>=c:\n print(b+c)\nelse:\n print(a+b+b+1)\n']
['Wrong Answer', 'Accepted']
['s285729587', 's081117257']
[2940.0, 2940.0]
[18.0, 18.0]
[50, 78]
p03186
u025329375
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
["a,b,c = input().split(' ')\nif c>a+b:\n return a+b+1+b\nreturn c+b", 'def main():\n a,b,c = input().split(\' \')\n a = int(a)\n b = int(b)\n c = int(c)\n if c>a+b:\n print(a+b+1+b)\n else:\n print(c+b)\n\nif __name__=="__main__":\n main()']
['Runtime Error', 'Accepted']
['s312492162', 's626094817']
[2940.0, 2940.0]
[18.0, 18.0]
[64, 168]
p03186
u047535298
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['L, N = map(int, input().split())\nX = [0] + [int(input()) for i in range(N)]\nans = 0\nqueue = [(0, 0, X[1], L-X[-1], 1, -1, 0)]\n\nwhile queue:\n q = queue.pop()\n pos, path, l_len, r_len, l, r, cnt = q\n if(l-N-1 == r):\n path += max(l_len, r_len)\n ans = max(ans, path)\n continue\n if(l_len >= r_len):\n queue.append((l, path+l_len, X[l+1] - X[l], l_len + r_len, l + 1, r, cnt+1))\n if(l_len <= r_len):\n queue.append((r, path+r_len, l_len + r_len, X[r] - X[r-1], l, r - 1, cnt+1))\n\nprint(ans)\n', 'A, B, C = map(int, input().split())\n\nprint(min(B+C, A+2*B+1))']
['Runtime Error', 'Accepted']
['s849324482', 's558653450']
[3064.0, 2940.0]
[17.0, 17.0]
[535, 61]
p03186
u048034149
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a, b, c = map(int, input().split())\n\ntakahashi = True\ncount = 0\n\n""" Start eating cookies"""\nwhile a>0 or b>0 or c>0:\n if takahashi:\n if c > 0:\n c -= 1\n takahashi = False\n count += 1\n elif b > 0:\n b -= 1\n takahashi = True\n count += 1\n if b == 0:\n break\n else:\n if a == 0 and b == 0:\n break\n elif b > 0:\n b -= 1\n takahashi = True\n count += 1\n elif a > 0:\n takahashi = True\n a -= 1', '\n\na, b, c = map(int, input().split())\n\ntakahashi = True\ntakahashi_condition = True\ncount = 0\n\n""" Start eating cookies"""\nwhile takahashi_condition:\n if takahashi:\n if c > 0:\n c -= 1\n takahashi = False\n count += 1\n elif b > 0:\n b -= 1\n takahashi = True\n count += 1\n if b == 0:\n break\n else:\n if a == 0 and b == 0:\n break\n elif b > 0:\n b -= 1\n takahashi = True\n count += 1\n elif a > 0:\n takahashi = True\n a -= 1\n \n\nprint(count)', '\na, b, c = map(int, input().split())\n\nif a+b+1 > c:\n count = b+c\nelse\n count = b+(a+b+1)\n\nprint(count)', '\na, b, c = map(int, input().split())\n\nif a+b+1 > c:\n count = b+c\nelse:\n count = b+(a+b+1)\n\nprint(count)']
['Wrong Answer', 'Time Limit Exceeded', 'Runtime Error', 'Accepted']
['s072782925', 's298892700', 's543061032', 's778548795']
[3064.0, 3064.0, 2940.0, 2940.0]
[2104.0, 2104.0, 18.0, 18.0]
[578, 853, 108, 109]
p03186
u057964173
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['def resolve():\n a,b,c=map(int, input().split())\n cnt=0\n if a+b>=c-1:\n print(b+c)\n else:\n print(a+b+1+)\nresolve()', 'import sys\ndef input(): return sys.stdin.readline().strip()\n\ndef resolve():\n a,b,c=map(int, input().split())\n cnt=0\n if a+b>=c-1:\n print(b+c)\n else:\n print(a+b+1+b)\nresolve()']
['Runtime Error', 'Accepted']
['s815203573', 's512085577']
[2940.0, 2940.0]
[17.0, 17.0]
[138, 200]
p03186
u058861899
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c=map(int,input().split())\nanti=a+b\n\nif c+1<= anti:\n print(b+c)\nelse:\n print(anti+1+b)', 'a,b,c=map(int,input().split())\nanti=a+b\n\nif c+1<= anti:\n k= b+c\nelif c+2>=anti:\n k=anti+1+b\n \nprint(k)', 'a,b,c=map(int,input().split())\nanti=a+b\nif c> anti-1:\n print(a+b)\nelse :\n print(anti*+1+b)', 'a,b,c=map(int,input().split())\nanti=a+b\n\nif c+1<= anti:\n k= b+c\nelse:\n k=anti+1+b\n \nprint(k)', 'a,b,c=map(int,input().split())\nanti=a+b\nif c+1< anti:\n print(b+c)\nelse :\n print(anti+1+b)', 'a,b,c=map(int,input().split())\nanti=a+b\nif c> anti-1:\n print(a+b)\nelse :\n print(anti*+1+a)', 'a,b,c=map(int,input().split())\nanti=a+b\nif c+1<= anti:\n print(b+c)\nelse :\n print(anti+1+b)', 'a,b,c=map(int,input().split())\nanti=a+b\n\nif c<= anti+1:\n k= b+c\nelse :\n k=anti+1+b\n \nprint(k)']
['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s264726814', 's278474150', 's324893450', 's456919284', 's660913975', 's870830375', 's895144039', 's749312406']
[2940.0, 3064.0, 3316.0, 3060.0, 2940.0, 2940.0, 2940.0, 2940.0]
[18.0, 17.0, 19.0, 18.0, 17.0, 17.0, 17.0, 17.0]
[96, 111, 96, 101, 95, 96, 96, 102]
p03186
u061984624
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a, b, c = map(int, input().split())\nc = max(c, a + b + 1)\nprint(b + c)\n', 'a, b, c = map(int, input().split())\nc = min(c, a + b + 1)\nprint(b + c)\n']
['Wrong Answer', 'Accepted']
['s406997500', 's323057869']
[3064.0, 2940.0]
[17.0, 17.0]
[71, 71]
p03186
u069602573
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a, b, c = map(int, input().split()) \n\nif a + b >= c+1:\n print(b + c)\nelse:\n print(a+b+1+b)\n', 'a, b, c = map(int, input().split()) \n\nif a + b >= c-1:\n print(b + c)\nelse:\n print(a+b+1+b)\n']
['Wrong Answer', 'Accepted']
['s214653818', 's984352567']
[2940.0, 2940.0]
[18.0, 18.0]
[118, 118]
p03186
u089230684
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a = input("enter : ")\nb = list(a)\nc = [];\nfor i in b:\n if(i != " "):\n c.append(i)\nd = 0;\nif int(c[2])-1>=int(c[0])+int(c[1]):\n d = int(c[0])+int(c[1])+int(c[1])+1\nelse:\n d = int(c[1])+int(c[2])\n\nprint(d)\n \n', 'x=input().split()\na=int(x[0])\nb=int(x[1])\nc=int(x[-1])\nn=0\nif b>=c:\n n+=b+c\n print(n)\nelse:\n n+=2*b\n c-=b\n if a>=c:\n n+=c\n print(n)\n else:\n n+=a+1 \n print(n)\n']
['Wrong Answer', 'Accepted']
['s678544684', 's802253166']
[3060.0, 2940.0]
[17.0, 17.0]
[225, 205]
p03186
u090994275
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c=map(int,input().split())\nprint(a+min(a+b+1,c))', 'a,b,c=map(int,input().split())\nprint(b+min(a+b+1,c))']
['Wrong Answer', 'Accepted']
['s211587577', 's097289209']
[2940.0, 2940.0]
[17.0, 17.0]
[52, 52]
p03186
u091051505
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c = map(int, input().split())\n\nif (c+1 > (a+b)):\n ans = a + 2*b + 1\nelse:\n ans = c+b\nprint(ans)', 'a,b,c = map(int, input().split())\n\nif (c > (a+b)):\n ans = a + 2*b + 1\nelse:\n ans = c+b\nprint(ans)']
['Wrong Answer', 'Accepted']
['s219336592', 's211882689']
[2940.0, 2940.0]
[17.0, 17.0]
[105, 103]
p03186
u092926023
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
["input_str = input()\n#input_str = '100 1 8'\n\na, b, c = input_str.split()\na = int(a)\nb = int(b)\nc = int(c)\n\nif a + b >= c:\n print(c * 2 + 1)\nelse:\n print((a + b) * 2 + 1)", "#input_str = input()\ninput_str = '8 8 1'\nA, B, C = input_str.split()\nA = int(A)\nB = int(B)\nC = int(C)\n\nif A + B > C + 1:\n print(C*2+1)\nelse\n\tprint((A+B)*2+1", 'input_str = input()\n\na, b, c = input_str.split()\na = int(a)\nb = int(b)\nc = int(c)\n\nif a + b >= c:\n print(b + c)\nelse:\n print((a+b)*2 +1 - a)']
['Wrong Answer', 'Runtime Error', 'Accepted']
['s194773590', 's327877711', 's600081668']
[3060.0, 2940.0, 2940.0]
[17.0, 18.0, 18.0]
[174, 159, 146]
p03186
u095384238
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a, b, c = input(int(i) for i in input().split())\nif a + b >= c:\n result = c + b\nelif a + b < c:\n result = a + b + b\nprint(result)', 'a, b, c = input(int(i) for i in input().split())\nif a + b >= c:\n result = c + b\nelif a + b < c:\n result = a + b\nprint(result)', 'a, b, c = (int(i) for i in input().split())\nif a + b + 1 >= c:\n result = b + c\nelse:\n result = a + 2 * b + 1\nprint(result)']
['Runtime Error', 'Runtime Error', 'Accepted']
['s107614419', 's825313875', 's619330395']
[2940.0, 3060.0, 2940.0]
[18.0, 18.0, 17.0]
[131, 127, 124]
p03186
u095426154
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c=map(int,input().split())\nif a+b-1>=c:\n print(c+b)\nelse:\n print(2*b+a+1)', 'a,b,c=map(int,input().split())\nif a+b+1>=c:\n print(c+b)\nelse:\n print(2*b+a+1)']
['Wrong Answer', 'Accepted']
['s605216343', 's816478080']
[2940.0, 2940.0]
[17.0, 17.0]
[83, 83]
p03186
u102242691
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['\na,b,c = map(int,input().split())\n\nif a + b >= c:\n print(a + b)\nelse:\n print(a + b + b + 1)\n', '\na,b,c = map(int,input().split())\n\nif a + b >= c:\n print(b+c)\nelse:\n print(b+(a+b+1))\n\n']
['Wrong Answer', 'Accepted']
['s930700535', 's293966134']
[2940.0, 2940.0]
[17.0, 17.0]
[98, 93]
p03186
u102461423
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['A,B,C = map(int,input().split())\n\nC = min(C, A+B+1)\nanswer = A+C\nprint(answer)', 'import sys\nread = sys.stdin.buffer.read\nreadline = sys.stdin.buffer.readline\nreadlines = sys.stdin.buffer.readlines\n\nA,B,C = map(int,read().split())\n\nanswer = 0\n# C,B,C,B,...\nx = min(B,C)\nanswer += x + x\nB -= x\nC -= x\nif B:\n answer += B\nelse:\n # C,A,C,A,\n x = min(C,A+1)\n answer += x\nprint(answer)']
['Wrong Answer', 'Accepted']
['s116849969', 's362424623']
[2940.0, 3064.0]
[17.0, 17.0]
[78, 309]
p03186
u111365959
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c = [int(x) for x in input().split()]\nco = b*2 if c-b>0 else c*2+b-c\nif c<b: print(co)\nc -= b\nco += c if c-a<=0 else a+1\nif c+b==0 or c+a==0: print(co)', 'a,b,c = [int(x) for x in input().split()]\nco = b*2 if c>b else c*2+b-c\nc -= b\nif c>0: co += c if c <=a else a+1\nprint(co)\n']
['Wrong Answer', 'Accepted']
['s583703069', 's273587746']
[2940.0, 2940.0]
[17.0, 17.0]
[155, 122]
p03186
u111652094
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['A,B,C = map(int,input().split())\n\nif A+B>=C:\n print(B+C)\nprint(A+2*B+1)', 'A,B,C = map(int,input().split())\n\nif A+B>=C:\n print(B+C)\nelse:\n print(A+2*B+1)']
['Wrong Answer', 'Accepted']
['s352281044', 's804125303']
[2940.0, 2940.0]
[17.0, 17.0]
[74, 84]
p03186
u117193815
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a, b, c= map(int, input().split())\nif b<c:\n print((c-(b*2))*2)\nelse:\n print(b+c)', 'a, b, c= map(int, input().split())\nif c-1<=b:\n print(c+b)\nelif a+b<=c-1:\n print(a+b+b+1)\nelif a+b>=c:\n print(b+c)']
['Wrong Answer', 'Accepted']
['s880725384', 's344002447']
[2940.0, 2940.0]
[17.0, 17.0]
[86, 122]
p03186
u126300147
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
["nums = input().split(' ')\n\nBadCookie = int(nums[0])\nGoodCookie = int(nums[1])\nGoodPoson = int(nums[2])\n\nprint(GoodCookie+(GoodPoson-(GoodCookie+BadCookie)))", 'line = list(input())\nnums = [int(n) for n in line]\nBadCookie = nums[0]\nGoodCookie = nums[1]\nGoodPoson = nums[2]\n\nprint(GoodCookie+(GoodPoson-(GoodCookie+BadCookie)))', "nums = input().split(' ')\n\nBadCookie = int(nums[0])\nGoodCookie = int(nums[1])\nGoodPoson = int(nums[2])\nif GoodCookie + BadCookie > GoodPoson:\n print(GoodCookie+GoodPoson)\nelse:\n print(GoodCookie+BadCookie+2)\n\n", "nums = input().split(' ')\n\nBadCookie = int(nums[0])\nGoodCookie = int(nums[1])\nGoodPoson = int(nums[2])\nif GoodCookie + BadCookie > GoodPoson:\n print(GoodCookie+GoodPoson)\nelse:\n print(GoodCookie+BadCookie+GoodCookie+1)\n\n", "nums = input().split(' ')\n\nBadCookie = int(nums[0])\nGoodCookie = int(nums[1])\nGoodPoson = int(nums[2])\nif GoodCookie + BadCookie > GoodPoson:\n print(GoodCookie+GoodPoson)\nelif GoodCookie + BadCookie < GoodPoson:\n print(GoodCookie+BadCookie+GoodCookie+1)\nelse:\n print(GoodCookie+GoodPoson)\n"]
['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Accepted']
['s048561929', 's162919855', 's241627641', 's382321145', 's257520285']
[2940.0, 2940.0, 2940.0, 2940.0, 2940.0]
[17.0, 17.0, 20.0, 17.0, 17.0]
[156, 165, 215, 226, 298]
p03186
u126348486
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['A, B, C = map(int, input().split())\n\nif C < A+B:\n print(C+B)\nelse:\n print(A+2*B+1)', 'A, B, C = map(int, input().split())\n\nif C <= A+B:\n print(C+B)\nelse:\n print(A+2*B+1)']
['Wrong Answer', 'Accepted']
['s679968577', 's098238466']
[2940.0, 3060.0]
[17.0, 19.0]
[84, 85]
p03186
u129836004
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['A, B, C = map(int, input().split())\nif C <= B:\n print(B+C)\nelse:\n print((min(A+B, C)+1) + B)', 'A, B, C = map(int, input().split())\nif C <= B:\n print(B+C)\nelif A+B<C:\n print((min(A+B, C)+1) + B)\nelse:\n print(B+C)']
['Wrong Answer', 'Accepted']
['s924994142', 's413331969']
[2940.0, 2940.0]
[17.0, 18.0]
[98, 125]
p03186
u130900604
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c=map(int,input().split())\n\nif a+b+1=>c:\n ans=b+c\nelse:\n ans=a+b+1+b\n \nprint(ans)', 'a,b,c=map(int,input().split())\n\nif a+b+1>=c:\n ans=b+c\nelse:\n ans=a+b+1+b\n \nprint(ans)']
['Runtime Error', 'Accepted']
['s093235749', 's576508256']
[2940.0, 2940.0]
[18.0, 17.0]
[94, 94]
p03186
u131406572
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c=map(int,input().split())\nif a+b<=c:\n print(b+a+b+1)\nelse:\n print(b+c)', 'a,b,c=map(int,input().split())\nif a+b<c:\n print(b+a+b)\nelif a+b==c:\n print(b+a+b+1)\nelse:\n print(b+c)', 'a,b,c=map(int,input().split())\nprint(b+min(a+b+1,c))\n']
['Wrong Answer', 'Wrong Answer', 'Accepted']
['s005271135', 's079844461', 's352506251']
[2940.0, 2940.0, 2940.0]
[17.0, 17.0, 18.0]
[81, 110, 53]
p03186
u142415823
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['A, B, C = map(int, input().split())\n\nif A + B > C:\n print(B + C)\nelse:\n print(2 * B + A + 1)', 'A, B, C = map(int, input().split())\n\nif A + B >= C:\n print(B + C)\nelse:\n print(2 * B + A + 1)']
['Wrong Answer', 'Accepted']
['s684429538', 's565715357']
[2940.0, 2940.0]
[17.0, 17.0]
[98, 99]
p03186
u158034562
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['A,B,C=(int(i) for i in input().split())\ncounter=0\n\n\nif C>=B:\n counter+=B*2\n B=0\n C=C-B\n if C>A:\n counter+=A+1\n else:\n counter+=C\n \nelse:\n counter+=C*2\n C=0\n B-=C\n counter+=B\n \nprint(counter)\n', 'A,B,C=(int(i) for i in input().split())\ncounter=0\n\n\nif C>=B:\n counter+=B*2\n C=C-B\n B=0\n if C>A:\n counter+=A+1\n else:\n counter+=C\n \nelse:\n counter+=C*2\n B-=C\n C=0\n counter+=B\n \nprint(counter)\n']
['Wrong Answer', 'Accepted']
['s385255231', 's500610776']
[2940.0, 2940.0]
[18.0, 19.0]
[220, 220]
p03186
u161201983
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['a,b,c = map(int,input().split())\nif b<c:\n print(c)\nelse:\n print(b)', 'a,b,c = map(int,input().split())\nif a+b <c:\n C = a+b+1+b\n print(C)\nif a+b >=c:\n print(b+c)']
['Wrong Answer', 'Accepted']
['s029081804', 's261332051']
[2940.0, 2940.0]
[17.0, 17.0]
[72, 99]
p03186
u167908302
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['#coding:utf-8\na, b, c = map(int, input().split())\n\n\nif a+b > c:\n print(b+c)\n\nelse:\n print((a+b+1)+b)', '#coding:utf-8\na, b, c = map(int, input().split())\n\n\nif a+b+1 >= c:\n print(b+c)\n\nelse:\n print((a+b+1)+b)']
['Wrong Answer', 'Accepted']
['s947728011', 's608064854']
[2940.0, 2940.0]
[17.0, 17.0]
[207, 293]
p03186
u173374079
2,000
1,048,576
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in such a situation. Eating a cookie containing antidotes while having a stomachache cures it, and there is no other way to cure stomachaches. Find the maximum number of tasty cookies that Takahashi can eat.
['#!/usr/bin/python\n# coding: UTF-8\n\na, b, c = map(int,input().split("/"))\n\nif a * b == 0:\n print(0)\nelif a + b >= c:\n print(b + c)\nelse:\n print(a + b * 2 + 1)', '#!/usr/bin/python\n# coding: UTF-8\n\na, b, c = map(int,input().split())\n\nif a + b >= c:\n print(b + c)\nelse:\n print(a + b * 2 + 1)']
['Runtime Error', 'Accepted']
['s098491953', 's841444206']
[3060.0, 2940.0]
[17.0, 17.0]
[160, 129]