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
| #include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=10000+10; const int maxm=2000+10; int n,m,p; int x[maxn],y[maxn]; int low[maxn],high[maxn]; int f[maxn][maxm]; bool e[maxn]; int main() { scanf("%d%d%d",&n,&m,&p); for(int i=1; i<=n; ++i) scanf("%d%d",&x[i],&y[i]); for(int i=1; i<=n; ++i) { low[i]=1; high[i]=m; } int a,b,c; for(int i=1; i<=p; ++i) { scanf("%d%d%d",&a,&b,&c); e[a]=1; low[a]=b+1; high[a]=c-1; } memset(f,0x3f,sizeof(f)); for(int i=1; i<=m; ++i) f[0][i]=0; for(int i=1; i<=n; ++i) { for(int j=x[i]+1; j<=m+x[i]; ++j) f[i][j]=min(f[i-1][j-x[i]]+1,f[i][j-x[i]]+1); for(int j=m+1; j<=m+x[i]; ++j) f[i][m]=min(f[i][m],f[i][j]); for(int j=1; j<=m-y[i]; ++j) f[i][j]=min(f[i][j],f[i-1][j+y[i]]); for(int j=1; j<low[i]; ++j) f[i][j]=f[0][0]; for(int j=high[i]+1; j<=m; ++j) f[i][j]=f[0][0]; } int ans=f[0][0]; for(int j=1;j<=m;++j) { ans=min(ans,f[n][j]); } if(ans<f[0][0]) printf("1\n%d\n",ans); else{ int i,j; for(i=n;i>=1;i--) { for(j=1;j<=m;++j) { if(f[i][j]<f[0][0]) break; } if(j<=m) break; } ans=0; for(int j=1;j<=i;++j) { if(e[j]) ans++; } printf("0\n%d\n",ans); } return 0; }
|