Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int visina[100010];
- struct child
- {
- int l, r, k;
- };
- struct struk
- {
- int r, k;
- };
- child dete[100010];
- multiset<struk> skup;
- bool res[10];
- inline bool operator<(const struk& a, const struk& b)
- {
- return a.r<b.r;
- }
- bool sortiraj(child a, child b)
- {
- if (a.l == b.l) return a.r < b.r;
- return a.l < b.l;
- }
- void ulaz(int m)
- {
- for(int i = 0; i < m; i++)
- {
- int x;
- cin >> x;
- dete[i].l = x-1;
- }
- for(int i = 0; i < m; i++)
- {
- int x;
- cin >> x;
- dete[i].r = x-1;
- }
- for(int i = 0; i < m; i++)
- {
- int x;
- cin >> x;
- dete[i].k = x;
- }
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int t;
- cin >> t;
- for(int u = 0; u < t; u++)
- {
- int n, m;
- cin >> n >> m;
- for(int i = 0; i < n; i++) cin >> visina[i];
- ulaz(m);
- sort(dete, dete + m, sortiraj);
- int pok = 0;
- bool ok = true;
- for(int i = 0 ; i < n; i++)
- {
- while(pok < m) /// dodajem decu
- {
- if(dete[pok].l==i)
- {
- struk pom;
- pom.k = dete[pok].k;
- pom.r = dete[pok].r;
- skup.insert(pom);
- pok++;
- }
- else break;
- }
- while(!skup.empty()) /// brisem decu
- {
- struk pom = *skup.begin();
- if(pom.r < i) skup.erase(*skup.begin());
- else break;
- }
- while(visina[i] > 0)
- {
- if(skup.empty()) {ok = false; break; }
- struk pom = *skup.begin();
- if(pom.k < visina[i])
- {
- visina[i]-=pom.k;
- skup.erase(skup.begin());
- }
- else
- {
- if(pom.k == visina[i]) skup.erase(*skup.begin());
- else
- {
- pom.k -= visina[i];
- skup.erase(*skup.begin());
- skup.insert(pom);
- }
- visina[i] = 0;
- }
- }
- if(!ok) break;
- }
- if(ok) res[u] = true;
- skup.clear();
- }
- for(int i = 0; i < t; i++)
- {
- if(res[i]) cout << "DA" << "\n";
- else cout << "NE" << "\n";
- }
- return 0;
- }
- /*
- 1
- 3 2
- 1 4 2
- 1 2
- 3 3
- 3 4
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement