Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <climits>
- #include <stack>
- #include <string>
- #include <vector>
- #include <sstream>
- using namespace std;
- int main()
- {
- string buffer;
- getline(cin, buffer);
- istringstream istr(buffer);
- stack<int> pile;
- int curElt;
- while(istr >> curElt)
- pile.push(curElt);
- int rackSize;
- cin >> rackSize;
- int racks = 1;
- int curRackSize = rackSize;
- while(pile.size())
- {
- int curPiece = pile.top();
- pile.pop();
- if(curPiece <= curRackSize)
- {
- curRackSize -= curPiece;
- }else{
- //initialize new rack
- racks++;
- curRackSize = rackSize;
- //put the piece on the rack
- curRackSize -= curPiece;
- }
- }
- cout << racks << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement