#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
struct good{int s,e,x;}d[10005];
bool cmp(good a, good b){
return a.s == b.s ? a.e > b.e : a.s < b.s;
}
bool operator<(good a, good b){return a.e < b.e;}
int n,c,m;
int a[2005],cdone;
priority_queue<good> pq;
int main(){
scanf("%d %d %d",&n,&c,&m);
for (int i=0; i<m; i++) {
scanf("%d %d %d",&d[i].s,&d[i].e,&d[i].x);
a[d[i].s] += d[i].x;
a[d[i].e] -= d[i].x;
cdone += d[i].x;
}
a[1] -= c;
a[n] += c;
sort(d,d+m,cmp);
for (int i=1; i<=n; i++) {
a[i] += a[i-1];
}
int piv = 0;
for (int i=1; i<=n; i++) {
while (piv < m && d[piv].s <= i) {
pq.push(d[piv]);
piv++;
}
while (a[i] > 0) {
good t = pq.top();
pq.pop();
int dx = min(t.x,a[i]);
for (int j=i; j<t.e; j++) {
a[j] -= dx;
}
cdone -= dx;
t.x -= dx;
if(t.x > 0) pq.push(t);
}
}
printf("%d",cdone);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1336 KB |
Output is correct |
2 |
Correct |
0 ms |
1336 KB |
Output is correct |
3 |
Correct |
0 ms |
1336 KB |
Output is correct |
4 |
Correct |
0 ms |
1336 KB |
Output is correct |
5 |
Correct |
0 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1336 KB |
Output is correct |
2 |
Correct |
0 ms |
1336 KB |
Output is correct |
3 |
Correct |
0 ms |
1336 KB |
Output is correct |
4 |
Correct |
0 ms |
1336 KB |
Output is correct |
5 |
Correct |
0 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1336 KB |
Output is correct |
2 |
Correct |
0 ms |
1336 KB |
Output is correct |
3 |
Correct |
0 ms |
1336 KB |
Output is correct |
4 |
Correct |
0 ms |
1336 KB |
Output is correct |
5 |
Correct |
0 ms |
1336 KB |
Output is correct |
6 |
Correct |
0 ms |
1336 KB |
Output is correct |
7 |
Correct |
0 ms |
1336 KB |
Output is correct |
8 |
Correct |
0 ms |
1336 KB |
Output is correct |
9 |
Correct |
0 ms |
1336 KB |
Output is correct |
10 |
Correct |
0 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1336 KB |
Output is correct |
2 |
Correct |
0 ms |
1336 KB |
Output is correct |
3 |
Correct |
0 ms |
1336 KB |
Output is correct |
4 |
Correct |
0 ms |
1336 KB |
Output is correct |
5 |
Correct |
0 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1336 KB |
Output is correct |
2 |
Correct |
0 ms |
1336 KB |
Output is correct |
3 |
Correct |
12 ms |
1336 KB |
Output is correct |
4 |
Correct |
4 ms |
1720 KB |
Output is correct |
5 |
Correct |
8 ms |
1336 KB |
Output is correct |