1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| #include<bits/stdc++.h> using namespace std; #define N 10010 #define M 1010 #define rep(i,l,r) for(int i=l;i<=r;++i) const int INF=0x3f3f3f3f; bool wall[N]; vector<int> now,las; int n,m,q; int a[N],b[N]; int l[N],r[N]; int main() { scanf("%d%d%d",&n,&m,&q); rep(i,0,n-1) { scanf("%d%d",a+i,b+i); l[i]=0; r[i]=m+1; } l[n]=0;r[n]=m+1; rep(i,1,q) { int x; scanf("%d",&x); scanf("%d%d",&l[x],&r[x]); wall[x]=true; }
now.resize(m+5); las.resize(m+5); rep(i,1,m) las[i]=0; las[0]=INF; int ans1=INF,ans2=0; rep(i,1,n) { int x=a[i-1]; rep(j,0,m) now[j]=INF; rep(j,x,m) { now[j]=min(now[j],las[j-x]+1); now[j]=min(now[j],now[j-x]+1); } rep(j,m-x,m) { now[m]=min(now[m],las[j]+1); now[m]=min(now[m],now[j]+1); } rep(j,l[i]+1,r[i]-1) if(j+b[i-1]<=m) now[j]=min(now[j],las[j+b[i-1]]); rep(j,0,l[i]) now[j]=INF; rep(j,r[i],m) now[j]=INF; if(wall[i]) rep(j,l[i]+1,r[i]-1) if(now[j]<INF) { ++ans2; break; } swap(now,las); } rep(j,1,m) ans1=min(ans1,las[j]); if(ans1<INF) { puts("1"); printf("%d\n",ans1); } else { puts("0"); printf("%d\n",ans2); } }
|