This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<algorithm>
using namespace std;
struct pp{
int from;
int to;
int dil;
}ar[100001];
int aa[20001];
int int_max(int a,int b){
if(a>b) return a;
return b;
}
bool cmp(struct pp a,struct pp b){
if(a.to==b.to){
if(a.from==b.from) return a.dil>b.dil;
return a.from>b.from;
}
return a.to<b.to;
}
int main()
{
int n,m,c,i,j,t,ans=0;
scanf("%d %d",&n,&c);
scanf("%d",&m);
for(i=1;i<=m;i++)
scanf("%d %d %d",&ar[i].from,&ar[i].to,&ar[i].dil);
sort(ar+1,ar+m+1,cmp);
for(i=1;i<=m;i++){
t=0;
for(j=ar[i].from;j<ar[i].to;j++) t=int_max(t,aa[j]);
if(t+ar[i].dil<=c){
for(j=ar[i].from;j<ar[i].to;j++) aa[j]+=ar[i].dil;
ans+=ar[i].dil;
}
else{
for(j=ar[i].from;j<ar[i].to;j++) aa[j]+=c-t;
ans+=c-t;
}
}
printf("%d",ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |