[λ°±μ€] μ λ ¬ /νμ΄μ¬ 2217 λ‘ν, 1764 λ£λ³΄μ‘
π 2217 λ‘ν
2217λ²: λ‘ν
N(1 ≤ N ≤ 100,000)κ°μ λ‘νκ° μλ€. μ΄ λ‘νλ₯Ό μ΄μ©νμ¬ μ΄λ° μ λ° λ¬Όμ²΄λ₯Ό λ€μ΄μ¬λ¦΄ μ μλ€. κ°κ°μ λ‘νλ κ·Έ κ΅΅κΈ°λ κΈΈμ΄κ° λ€λ₯΄κΈ° λλ¬Έμ λ€ μ μλ 물체μ μ€λμ΄ μλ‘ λ€λ₯Ό μλ μλ€. ν
www.acmicpc.net
μ²μ μκ°
n κ°μλ₯Ό λ°μν λλ©΄μ μ΅λ μ€λμ listλ‘ λ°μ
μ μΌ μμ μ΅λ μ€λ * n κ°κ° λ‘νλ€μ μ΅λμ€λμ΄λΌκ³ μκ°
import sys
input= sys.stdin.readline
n=int(input())
weight = list(int(input()) for _ in range(n))
weight.sort();
print(weight[0]*n)
μμλ μ€λ΅.
μ€λ₯: λ‘νλ₯Ό μ λΆ μ΄ κ²½μ° < μ΅μ μ λ‘νλ₯Ό μ΄ κ²½μ°μ μ΅λ μ€λμ΄ ν΄ μ μλ€λ μ μ κ°κ³Όνλ€.
μ μ¬ν μκ°ν΄λ³΄λ,
κ° λ‘νλ€μ΄ λ€ μ μλ μ΅λμ€λμ λ΄λ¦Όμ°¨μμΌλ‘ μ λ ¬ν νμ
μ΅λμ€λ * λ‘ν κ°μ (+1 μ© μ¦κ°) μ΄ κ°μ΄ κ°μ₯ ν° κ²½μ°κ° μ΅λ μ€λμ΄λΌλ μκ°μ΄ λ€μλ€.
λμ νμ΄
import sys
input= sys.stdin.readline
n=int(input())
weight = list(int(input()) for _ in range(n))
weight.sort(reverse=True)
max_weight=0
for i in range(len(weight)):
if max_weight<weight[i]*(i+1):
max_weight=weight[i]*(i+1)
print(max_weight)
weightλΌλ listμ μ΅λμ€λμ λ°μ
λ°λλ‘ μ λ ¬ν ν
μ΅λμ€λ * μ΅λμ€λμ λ€ μ μλ λ‘νμ κ°μ λ₯Ό max_weightμ λ£κ³ λΉκ΅νμ¬
κ°μ₯ ν° κ°μ μ»μ΄λλ€.
λ€λ₯Ένμ΄
import sys
input= sys.stdin.readline
n=int(input())
weight = list(int(input()) for _ in range(n))
weight.sort()
weight_max=0
for i in weight:
weight_max=max(i*n,weight_max)
n-=1
print(weight_max)
λ€λ₯Έ νμ΄λ₯Ό μ°Ύμλ΄λ weight_maxλ₯Ό λλ©° λ°λ‘λ°λ‘ maxλ₯Ό κ³μ°νλ λ°©λ²λ μμλ€.
λ€λ§ λμ νμ΄λ³΄λ€ μ΄μ§ λλ Έλ€.
λ΄νμ΄λ λΉκ΅λμμ΄ νλμ΄κ³ λ¨μ μ°μ°μ΄μ§λ§ λ€λ₯Ένμ΄μμλ λ§€λ² maxλ₯Ό ν΄μ£ΌκΈ° λλ¬ΈμΈ κ² κ°λ€.
π μ΄λ€κ² λ λΉ λ₯Έ λ°©λ²μΈμ§ κ³ λ―Όνλ μ΅κ΄μ κΈ°λ₯΄μ. max λ³΄λ¨ < λ¨μμ°μ°μ!
π 1764 λ£λ³΄μ‘
1764λ²: λ£λ³΄μ‘
첫째 μ€μ λ£λ λͺ»ν μ¬λμ μ N, 보λ λͺ»ν μ¬λμ μ Mμ΄ μ£Όμ΄μ§λ€. μ΄μ΄μ λμ§Έ μ€λΆν° Nκ°μ μ€μ κ±Έμ³ λ£λ λͺ»ν μ¬λμ μ΄λ¦κ³Ό, N+2μ§Έ μ€λΆν° 보λ λͺ»ν μ¬λμ μ΄λ¦μ΄ μμλλ‘ μ£Όμ΄μ§λ€.
www.acmicpc.net
λ¬Έμ λ³΄κ³ μ’ μκ²Όλ€. κ·Έλ¦¬κ³ νμλλ° λκ° μ°μ°νλ€.
μ΄ μ―€ μ΄λ°λ¬Έμ κ° λμ¨λ€κ΅¬?
λ£λλͺ»ν μ¬λμ listλ₯Ό λ°κ³
λλ¦ μκ° μ€μΈλ€κ³ 보λλͺ»ν μ¬λμ λ°μΌλ©΄μ λ£λλͺ»ν μ¬λμ listμμλ μ°Ύμμ§λ§
listμμ inμΌλ‘ μ°Ύλκ±°λ μμλ μκ°μ΄κ³Όμ΄λ€ γ γ
λ΄νμ΄1
import sys
input = sys.stdin.readline
h,s = map(int,input().split())
hList = [input() for _ in range(h)]
ans=[]
for i in range(s):
never_seen = input()
if never_seen in hList:
ans.append(never_seen)
print(len(ans))
for i in ans:
print(i.strip())
μμλ~~
λ΄νμ΄2
import sys
input = sys.stdin.readline
h,s = map(int,input().split())
hList = list(input() for _ in range(h))
sList = list(input() for _ in range(h))
hSet=set(hList)
sSet=set(sList)
ans=[]
ans = sorted(list(hSet & sSet))
print(len(ans))
for i in ans:
print(i.strip())
κ·Έλ λ΄ list λ§κ³ setμΌλ‘ μ²λ¦¬νμ! ν΄μ λ§λ λ¬Έμ
listλ‘ λ°κ³ -> setμΌλ‘ λ°κΏμ κ΅μ§ν©νκ³ -> listλ‘ λ°κΏ μ€λ³΅ μ κ±°
μ λ΅μ λμμ§λ§ μ’μ μ½λλΌλ λλμ μλ€ ..γ
λ€λ₯Έ νμ΄
import sys
input = sys.stdin.readline
def binarySearch(list,ele,low,high):
while low<=high:
mid = (low+high)//2
if list[mid] == ele:
return True
if ele > list[mid]:
low = mid+1
else:
high = mid-1
return False
h,s = map(int,input().split())
hList = [input().strip() for _ in range(h)]
sList = [input().strip() for _ in range(s)]
hList.sort()
ans=[]
for i in sList:
if binarySearch(hList, i, 0,h-1):
ans.append(i)
print(len(ans))
for i in sorted(ans):
print(i)
λ€λ₯Έ νμ΄ λ°©λ²μ μ°Ύμλλ°
μ΄λΆνμ ν¨μλ₯Ό μ΄μ©ν΄μ SListλ₯Ό λλ©° μ΄λΆνμ ν¨μλ₯Ό ν΅ν΄ hListμ μλμ§ νμΈνλ λ°©λ²μ΄λ€.
μ΄ μμ μ λ΅μΌλ‘ λμμ§λ§ μκ°μ΄ setμ μ΄μ©νκ²λ³΄λ€ 2λ°°κ° λμλ€.
μ무λλ μ΄λΆνμμ λ°μ΄ν°λ₯Ό μ λ ¬νλ κ³Όμ μμ μκ°μ΄ μμ λλλ°
setμ μ§ν©μ΄κΈ° λλ¬Έμ κ΅μ§ν©μ°μ°μΌλ‘ νλ²μ ν΄κ²°νκΈ° λλ¬Έμ λ λΉ¨λλ κ²κ°λ€.
π μ€λμ λͺ¨λ νμ΄μ μκ°μ΄κ³Όκ° λμμ λΉν©νμ§λ§ μκ°μ΄κ³Όκ° λμ€λ μ νλ€μ μκ²λκ³ νΌνλ μ€ν¬μ μμλλ€.
λ°°μ΄μ μ‘΄μ¬μ¬λΆλ inμ΄ μλ set κ΅μ§ν© νΉμ μ΄λΆνμμΌλ‘!
max 보λ€λ λ¨μ μ°μ°μλ‘!