4 solutions
-
0
#include <iostream> #include <cstring> #include <algorithm> #include <queue> #define x first #define y second using namespace std; typedef pair<int, int> PII; const int N = 2e5+5; int n, m; int a,b,c,d,s[N]; priority_queue<PII, vector<PII>, greater<PII>> q[N]; int main() { ios::sync_with_stdio(false); cin>>n>>m; for (int i=1;i<=n;i++) cin>>s[i]; while(m--) { cin>>a>>b>>c>>d; while (!q[b].empty()&&q[b].top().x<=a) { s[b]+=q[b].top().y; q[b].pop(); } if (s[b]>=d) { q[b].push({a+c,d}); s[b]-=d; cout<<s[b]<<endl; } else cout<<-1<<endl; } return 0; }
Information
- ID
- 1548
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 4
- Tags
- # Submissions
- 188
- Accepted
- 37
- Uploaded By