-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
35-pknujsp #137
35-pknujsp #137
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
present_count, money, original_sale_count = map(int,input().split())
present_prices = sorted(list(map(int,input().split())))
stack = []
total_price = 0
sale_idx = 0
sale_count = original_sale_count
for price in present_prices:
if original_sale_count > 0:
if sale_count > 0 and money < (total_price + price//2): break
if sale_count > 0 and money >= (total_price + price//2):
stack.append(price//2)
total_price += price//2
sale_count -= 1
elif money >= (total_price + stack[sale_idx] + price //2):
stack.append(price//2)
total_price += price//2
total_price += stack[sale_idx]
stack[sale_idx] *= 2
sale_idx += 1
else: break
else:
if money >= total_price + price:
stack.append(price)
total_price += price
else: break
print(len(stack))
μ μ μ΄ λ¬Έμ κ° κ·Έλ¦¬λ μΈ μ€ μ ν λͺ°λμ΄μ.
κ·Έλ₯ λ¨μ μ€νμΈμ€ μμλ€μ.
μ λ μΌλ¨ ν μΈν μ μλ 물건 λ§νΌ ν μΈλ κ°κ²©μΌλ‘ μ¬κ³ ,
μ΄μ ν μΈ κ°λ₯ν κ°μκ° λλ¬μ κ²½μ° μ¬λ €κ³ νλ 물건μ aλΌκ³ νμ λ
κ°μ₯ μΈκ² ν μΈν 물건 λΆν° μ κ°λ‘ μ¬λ¦° λ€, aμ 물건μ λ°κ°μΌλ‘ ν μΈν΄μ μ΄ μ μλ? λ₯Ό 체ν¬νλ μμΌλ‘ μ€νμΌλ‘ μ μ₯ν΄λκ°μ΄μ.
λκ° νμ΄λ λΉμ·ν κ² κ°μλ°..
μ λ κ·Έλ₯ λ¨μ μ€νμ΄λΌκ³ μκ°ν΄μ νμ΄μ κ·Έλ°μ§ λΉκ΅μ μ½κ² λκ»΄μ‘λ κ² κ°λ€μ.
μ§μ§ μ½κ² νΈμ ¨λ€μ μ λ¬Έμ μμ μ νλ λμΌλ‘ μ΅λν λ§μ΄ μ¬λ΄λΌκ³ ν΄μ 그리λκ° λ μ¬λμ΄μ λ‘μ§ λ§νμ κ² μ²λΌ λκ² λ΄€μ λ λΉμ·νκ±° κ°μμ μ μ½λλ μ²μ ν μΈλ°μ λ μ κ°λ₯ν κ°μλ§νΌ λ°λ‘ ν μΈλ°μλ³΄κ³ , λ μ΄μ ν μΈ λͺ»λ°μ λ λ€μ μ λ¬Όλ‘ λμ΄κ°μ νκ·λμ μ λ¬Όμ νλμ© νμΈνλ©΄μ λ€ μ²λ¦¬νλ λ°©μμ΄κ΅°μ νΉν ꡬ맀λμ κ΄λ¦¬ν λκ° μ°¨μ΄κ° μλ€μ μ λ νμ°Έ ν€λ§€λ€ 보λ ν μΈ κ°μλ₯Ό μ’μ° μΈλ±μ€λ‘ κ΄λ¦¬νλκ² λ μ¬λΌμ μΈλ±μ€λ‘ νλλ° |
"μ λ¬Όκ°κ²©μ μ€λ¦μ°¨μ μ λ ¬ν΄μ λ°κ°ν μΈμ΄ κ°λ₯ν μλ§νΌ ν μΈμ ν΄μ ꡬ맀λ₯Ό νκ³ μ΄ νμ΄νλ¦μ μ΄ν΄νλλ° μκ°μ λ€ μΌλ€μ |
Code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, b, a;
cin >> n >> b >> a;
vector<int> gifts(n);
for (int &gift: gifts) {
cin >> gift;
}
sort(gifts.begin(), gifts.end());
int answer = 0;
int cost = 0;
while (true) {
if (answer >= a) {
cost += gifts[answer - a] / 2;
}
cost += gifts[answer] / 2;
if (cost > b) break;
answer++;
if (answer == n) break;
}
cout << answer;
return 0;
} μ΄λ»κ² κΉλνκ² κ΅¬νν μ§ κ³ λ―Όνλ€ |
π λ¬Έμ λ§ν¬
μ λ¬Όν μΈ
βοΈ μμλ μκ°
μ€λ μκ°
β¨ μλ μ½λ
N
κ°μ μ λ¬Όμ΄ μμ λ, μ΅λA
κ°μ μ λ¬Όμ λν΄μ λ°κ° ν μΈμ μ μ©νμ¬ μ£Όμ΄μ§ μμ°B
λ‘ κ΅¬λ§€κ°λ₯ν μ λ¬Όμ μ΅λ κ°μλ₯Ό ꡬνλ λ¬Έμ μμ°, μ΅λ ν μΈ κ°μ
μ ν¬κΈ°λ₯Ό μ λλ‘ νμΈνμ§ μμκ³ , κ°κ°0
μ΄ νμ©λλλ°, μ΄λ₯Ό λͺ¨λ₯΄λ μνμμ λ¬Έμ λ₯Ό ννμ΄
min_price_gift
: ꡬ맀ν μ λ¬Ό μ€ μ κ°κ° κ°μ₯ μ λ ΄ν κ²max_price_gift
: κ°μ₯ μ΅κ·Όμ ꡬ맀ν κ²μ΅λ ν μΈ κ°μ
λ§νΌ μ λ ΄ν κ² λΆν° ν μΈλ°μ ꡬ맀max_price_gift++
: μλ‘ μ΄λ λ§λ€ μ΄λ€ μ λ¬Όμ μλμ§ κΈ°λ‘max_price_gift < N
μ 쑰건μΌλ‘ λ°λ³΅0
μ΄λ©΄, ν μΈ μμ΄ μ κ°λ‘ ꡬ맀νμ¬ μ λ¬Ό(max_price_gift)
ν μΈλ°μ ꡬ맀, μμ° λλλ©΄ μ’ λ£min_price_gift
λ₯Ό μ κ°λ‘ λ³κ²½ν΄ ꡬ맀max_price_gift
μΆλ ₯π μλ‘κ² μκ²λ λ΄μ©