자라는 개발자/문제풀이
백준 c++ 1817 짐 챙기는 숌
자란다
2022. 8. 23. 18:04
728x90
반응형
1817 짐 챙기는 숌
문제풀이
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void fast_io(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int num,weight,cnt;
vector<string> v;
int main(void)
{
fast_io();
cin >> num >> weight;
int tmp = weight;
while(num--)
{
int book;
cin >> book;
if(tmp-book<0)
{
cnt++;
tmp=weight;
}
tmp-=book;
}
if(tmp==weight)
cout << cnt;
else
cout << cnt +1;
}
무게만큼 빼는 작업을 반복한 뒤 마지막에 돌때 무게변경이 있었다면 +1을 해주었다.
728x90
반응형