Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <stack>
- using namespace std;
- int main() {
- string line;
- getline(cin, line);
- int quantity, dress, racks = 1, sum = 0;
- cin >> quantity;
- stack<int> clothes;
- istringstream ss(line);
- while (ss >> dress) {
- clothes.push(dress);
- }
- while (!clothes.empty()) {
- sum += clothes.top();
- if (sum <= quantity) {
- clothes.pop();
- }
- else {
- racks++;
- sum = 0;
- }
- }
- cout << racks << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement