Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- ifstream cin("test.in");
- ofstream cout("test.out");
- struct pr
- {
- int first, second;
- bool third;
- };
- vector < pr > v(370);
- vector < pair<int, int> > John;
- vector < bool > JohnFrecventa(370);
- int maxx;
- int s, nr;
- bool cmp(pair<int, int> a, pair<int, int> b)
- {
- if(a.first != b.first)
- return a.first < b.first;
- return a.second > b.second;
- }
- void backt(int poz, int val, int limita)
- {
- if(s == val || nr == 4)
- return ;
- // cout << poz << ' ' << val << ' ' << limita << '\n';
- // if(poz == 3 && val == 150 && limita == 4)
- // cout << "AICI " << s << ' ' << nr << '\n';
- for(int i = 0 ; i < John.size() ; i++)
- {
- if(s + John[i].second <= val && !JohnFrecventa[i]
- && John[i].first >= poz && John[i].first <= limita )
- {
- s += John[i].second, nr++;
- JohnFrecventa[i] = 1;
- if(s == val && nr <= 4)
- return;
- backt(poz, val, limita);
- if(s == val && nr <= 4)
- return;
- nr--;
- s -= John[i].second;
- JohnFrecventa[i] = 0;
- }
- }
- return ;
- }
- void rez()
- {
- char ch;
- int poz;
- int val, limita;
- while(cin >> ch )
- {
- if(ch == 'F')
- {
- cin >> poz >> limita >> val;
- v[poz].first = val, v[poz].second = limita,
- v[poz].third = 0;
- }
- else break;
- }
- //v[poz].first = val, v[poz].second = limita, v[poz].third = 0;
- cin >> poz >> val;
- John.push_back(make_pair(poz, val));
- while(cin >> ch >> poz >> val )
- John.push_back(make_pair(poz, val));
- //cout << "JON " << John.size() << '\n';
- sort(John.begin(), John.end(), cmp);
- for(int i = 1 ; i <= 365 ; i++)
- if(v[i].first)
- {
- s = 0, nr = 0;
- backt(i, v[i].first, v[i].second);
- if(s == v[i].first && nr <= 4)
- v[i].third= 1;
- //cout << v[i].third << ' ' << i << ' ' <<
- // v[i].first << ' ' << s << " " << nr << '\n';
- }
- }
- void print()
- {
- for(int i = 1 ; i <= 365 ; i++)
- if(!v[i].third && v[i].first)
- cout << i << ' ';
- }
- int main()
- {
- rez();
- print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement