• Home
  • About
    • Jiwon Jeong photo

      Jiwon Jeong

      끊임없이 배우며 성장하는 엔지니어

    • Learn More
    • Email
    • Github
  • Posts
    • All Posts
    • All Tags
    • All Categories
  • Projects

[프로그래머스] - 예산

11 May 2021

Reading time ~1 minute

풀이 (시간내 성공)

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool compare(int a, int b){
    if(a<b){
        return true;
    }else{
        return false;
    }
}
int solution(vector<int> d, int budget) {
    int answer = 0;
    sort(d.begin(), d.end(), compare);
    int i=0;
    int sum=0;
    while(sum<=budget && i<=d.size()){
        sum += ad[i];
        answer++;
        i++;
    }
    answer-=1;
    return answer;
}


PS Share Tweet +1