#include<cstdio> #include<algorithm> const int MAXN=1000+5; struct data{double start,keep,end;}; int hascs=1,k,n,m,totuse;double now,start,keep;data d[MAXN];bool used[MAXN]; bool comp(data a,data b){return a.start+a.keep<b.start+b.keep;} int main() { scanf("%d %d %d",&n,&k,&m); for(int i=1;i<=m;i++) { scanf("%lf %lf",&d[i].start,&d[i].keep); d[i].end=d[i].start+d[i].keep; } for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) { if((d[i].start<d[j].start && d[i].start+d[i].keep>d[j].start)) { d[i].start=d[j].start=std::min(d[i].start,d[j].start); d[i].keep=d[j].keep=std::max(d[j].end,d[i].end)-d[i].start; d[i].end=d[j].end=d[i].start+d[i].keep; } } std::sort(d+1,d+m+1,comp); for(int i=1;i<=m;i++) { start=d[i].start;keep=d[i].keep; for(;now+1<=start;now++) { hascs+=std::min(hascs,k); if(hascs>=n) { printf("%.2lf",now+1); return 0; } } now=start+keep; } for(;hascs<n;now++) { hascs+=std::min(hascs,k); if(hascs>=n) { printf("%.2lf",now+1); return 0; } } return 0; }
|