Advertisement
a53

gta

a53
May 10th, 2020
1,454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. const int dim=1004;
  4. int a[dim][dim],x[dim],pv[dim],pc[dim],Max[dim],w[dim];
  5.  
  6. int main()
  7. {
  8. ifstream f("gta.in");
  9. ofstream cout("gta.out");
  10. int i,j,c,g,ii,N,K,G,maxx=-2000,m=0,v;
  11. f>>N>>G>>K;
  12. for(i=1;i<=N;++i)
  13. {
  14. f>>pv[i]>>pc[i];
  15. c=pv[i]-pc[i];
  16. if(pc[i]<=G and maxx<c)
  17. maxx=c;
  18. }
  19. if(maxx==-2000)
  20. {
  21. cout<<"GIGEL NU ARE BANI";
  22. return 0;
  23. }
  24. if(maxx<=0) {cout<<G+maxx; return 0;}
  25. if(K==N)
  26. {
  27. for(i=1;i<=N;++i)
  28. {
  29. g=pc[i];
  30. c=pv[i]-pc[i];
  31.  
  32. if(c<=0 or g>G)
  33. continue;
  34.  
  35. for(j=G;j>=g;--j)
  36. {
  37. if(x[j]<x[j-g]+c)
  38. x[j]=x[j-g]+c;
  39. }
  40. }
  41. cout<<G+x[G];
  42. return 0;
  43. }
  44. for(ii=1;ii<=N;++ii)
  45. {
  46. g=pc[ii];
  47. c=pv[ii]-pc[ii];
  48. if(c<=0 or g>G)
  49. continue;
  50. if(g==0) /// gestionam cazul in care s-a achizitionat o masina gratis
  51. {
  52. for(j=G;j>=0;--j)
  53. {
  54. if(w[j]<K)
  55. ++w[j];
  56.  
  57. for(i=w[j];i>=1;--i)
  58. {
  59. if(a[j][i]<a[j][i-1]+c)
  60. {
  61. a[j][i]=a[j][i-1]+c;
  62. if(Max[j]<a[j][i])
  63. Max[j]=a[j][i];
  64. }
  65. }
  66. }
  67.  
  68. if(a[0][1]<c)
  69. a[0][1]=c;
  70. continue;
  71. }
  72. for(j=G-g;j>=0;--j)
  73. {
  74. /// verificam cate nivele sunt pentru valoarea j
  75. m=w[j];
  76. if(m==K)
  77. m=K-1;
  78. for(i=0;i<=m;i++)
  79. {
  80. //nivelul m
  81. if(m<K)
  82. {
  83. if(a[g+j][i+1] < a[j][i]+ c )
  84. {
  85. v=a[j][i]+c ;
  86. a[g+j][i+1] = v ;
  87.  
  88. if(w[g+j]<i+1)
  89. w[g+j]=i+1;
  90. if(Max[g+j]<v)
  91. Max[g+j]=v;
  92. }
  93. }
  94. }
  95. }
  96. }
  97. cout<<G+Max[G];
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement