Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<algorithm>
- using namespace std;
- bool cmp(pair<int,int> a, pair<int,int> b){
- return a.second < b.second;
- }
- int main(){
- /*iostream::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);*/
- pair<int,int> p;
- vector< pair<int,int> >vet;
- int n;
- cin >> n;
- for(int i = 0; i<n;i++){
- cin >> p.first >> p.second;
- vet.push_back(p);
- }
- sort(vet.begin(),vet.end(),cmp);
- /*for(int j = 0; j<vet.size();j++){
- cout << vet[j].first << " " << vet[j].second <<endl;
- }*/
- int m,valor;
- char op;
- cin >> m;
- for(int i = 0;i<m;i++){
- cin >> op;
- if(op == 'C'){
- cin >> valor;
- if(!vet.empty()){
- while(valor > 0){
- if(!vet.empty()){
- int i = vet[0].first;
- int sum = valor - i;
- //cout << "valor" << valor << "feno" << vet[0].first;
- if(sum < 0){
- vet[0].first = i - valor;
- valor = 0;
- }
- else if(sum > 0) {
- vet.erase(vet.begin());
- valor = sum;
- }
- else if(sum == 0){
- valor = 0;
- vet.erase(vet.begin());
- }
- } else break;
- }
- }
- }
- else if(op == 'V'){
- cin >> p.first >> p.second;
- vet.push_back(p);
- sort(vet.begin(),vet.end(),cmp);
- }
- }
- if(vet.empty()) cout << "Sem estoque";
- else{
- for(int i = 0; i<vet.size();i++){
- cout << vet[i].first << " " << vet[i].second << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement