#include using namespace std; int d,n,m,i,j,cur,r,a[1010],f[1010],st[1010],en[1010],k[1010]; pair b[1010]; bool cmp(int i, int j) { return b[i]=b[i].second) st[i]=j; if (a[j]>b[i].first) break; en[i]=j; } if (st[i]==0) st[i]=en[i]+1; k[i]=i; } sort(k,k+m+1,cmp); r=1000000000; for (i=1; i<=m; i++) { f[i]=1000000000; cur=st[k[i]]-1; for (j=0; j