Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <stack>
- #include <queue>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- queue <pair <string, long> > stones;
- stack < pair <string, long> > whiteStones;
- vector <long> num;
- string str;
- long n, k;
- cin>>n;
- for(int i = 0; i < n; i++)
- {
- cin>>str;
- cin>>k;
- stones.push(make_pair(str, k));
- }
- while(!stones.empty())
- {
- long sum = 0;
- if(stones.front().first == "white")
- {
- whiteStones.push(make_pair("white", stones.front().second));
- stones.pop();
- }else if(stones.front().first == "green")
- {
- for(int i =0 ; i < stones.front().second; i++)
- {
- sum += whiteStones.top().second;
- whiteStones.pop();
- }
- whiteStones.push(make_pair("white", sum));
- stones.pop();
- }else if(stones.front().first == "blue")
- { int maxi = 0;
- for(int i =0 ; i < stones.front().second; i++)
- {
- if(maxi < whiteStones.top().second)
- {
- maxi = whiteStones.top().second;
- }
- whiteStones.pop();
- }
- whiteStones.push(make_pair("white", maxi));
- stones.pop();
- }
- }
- while(!whiteStones.empty())
- {
- num.push_back(whiteStones.top().second);
- whiteStones.pop();
- }
- reverse(num.begin(),num.end());
- for(int i = 0; i < num.size(); i++)
- {
- cout<<num[i]<<" ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement