λ¬Έμ |
μ½λ©ν μ€νΈ μ°μ΅ - μμ° | νλ‘κ·Έλλ¨Έμ€
Sμ¬μμλ κ° λΆμμ νμν λ¬Όνμ μ§μν΄ μ£ΌκΈ° μν΄ λΆμλ³λ‘ λ¬Όνμ ꡬ맀νλλ° νμν κΈμ‘μ μ‘°μ¬νμ΅λλ€. κ·Έλ¬λ, μ 체 μμ°μ΄ μ ν΄μ Έ μκΈ° λλ¬Έμ λͺ¨λ λΆμμ λ¬Όνμ κ΅¬λ§€ν΄ μ€ μλ μμ΅λλ€. κ·Έλμ μ΅λν λ§μ λΆμμ λ¬Όνμ κ΅¬λ§€ν΄ μ€ μ μλλ‘ νλ €κ³ ν©λλ€. λ¬Όνμ κ΅¬λ§€ν΄ μ€ λλ κ° λΆμκ° μ μ²ν κΈμ‘λ§νΌμ λͺ¨λ μ§μν΄ μ€μΌ ν©λλ€. μλ₯Ό λ€μ΄ 1,000μμ μ μ²ν λΆμμλ μ νν 1,000μμ μ§μν΄μΌ νλ©°, 1,000μλ³΄λ€ μ μ κΈμ‘μ μ§μ
programmers.co.kr
μ½λ |
#include <iostream> | |
#include <algorithm> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int solution(vector<int> d, int budget) { | |
int answer = 0,i = 0; | |
sort(d.begin(), d.end()); | |
for ( ; i < d.size(); i++) | |
{ | |
if (d[i] > budget) break; | |
budget -= d[i]; | |
} | |
return i; | |
} |
'π€ PS(Problem Solving) > νλ‘κ·Έλλ¨Έμ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Level2/c++] 124 λλΌμ μ«μ (0) | 2019.09.26 |
---|---|
[Level2/c++] λ€λ¦¬λ₯Ό μ§λλ νΈλ (0) | 2019.09.23 |
[Level1/c++] μ§μ¬κ°ν λ³μ°κΈ° (0) | 2019.09.23 |
[Level1/c++] xλ§νΌ κ°κ²©μ΄ μλ nκ°μ μ«μ (0) | 2019.09.23 |
[Level1/c++] νλ ¬μ λ§μ (0) | 2019.09.23 |