Saleh127

UVA 394

Jul 27th, 2021
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  5.  
  6. stringstream ss;
  7.  
  8. string name[2000],nam;
  9.  
  10. ll b[1000],cd,d[1000];
  11. ll l[100][20],u[100][20];
  12. ll c[100][20];
  13.  
  14. int main()
  15. {
  16. ios_base::sync_with_stdio(0);
  17. cin.tie(0);cout.tie(0);
  18.  
  19. ll n,m,i,j,k;
  20.  
  21. string s;
  22.  
  23. while(cin>>n>>m)
  24. {
  25. for(i=1;i<=n;i++)
  26. {
  27. cin>>name[i]>>b[i]>>cd>>d[i];
  28.  
  29. for(j=1;j<=d[i];j++)
  30. {
  31. cin>>l[i][j]>>u[i][j];
  32. }
  33.  
  34. c[i][d[i]]=cd;
  35.  
  36. for(ll dd=d[i]-1;dd>0;dd--)
  37. {
  38. c[i][dd]=c[i][dd+1]*(u[i][dd+1]-l[i][dd+1]+1);
  39. }
  40.  
  41. c[i][0]=b[i];
  42.  
  43. for(j=1;j<=d[i];j++)
  44. {
  45. c[i][0]-=c[i][j]*l[i][j];
  46. }
  47. }
  48.  
  49. cin.ignore();
  50.  
  51. while(m--)
  52. {
  53. vector<ll>x;
  54.  
  55. ll q,ans=0;
  56.  
  57. getline(cin,s);
  58.  
  59. ss.clear();
  60.  
  61. ss.str(s);
  62.  
  63. ss>>nam;
  64.  
  65. while(ss>>q)
  66. {
  67. x.push_back(q);
  68. }
  69.  
  70. for(j=1;j<=n;j++)
  71. {
  72. if(name[j]==nam)
  73. {
  74. ans=c[j][0];
  75.  
  76. for(k=1;k<=x.size();k++)
  77. {
  78. ans+=(c[j][k]*x[k-1]);
  79. }
  80. }
  81. }
  82.  
  83. cout<<nam<<"[";
  84.  
  85. for(k=0;k<x.size();k++)
  86. {
  87. if(k!=0) cout<<", ";
  88.  
  89. cout<<x[k];
  90. }
  91.  
  92. cout<<"] = "<<ans<<endl;
  93. }
  94.  
  95. }
  96.  
  97. return 0;
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment