Advertisement
erfanul007

UVa 394

Jun 8th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5.  
  6. #define read() freopen("input.txt", "r", stdin)
  7. #define write() freopen("output.txt", "w", stdout)
  8.  
  9. void fastIO()
  10. {
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13. }
  14.  
  15. int main()
  16. {
  17. //read();
  18. //write();
  19. fastIO();
  20. map< string , pair< pair< int , int > , pair< int, vector< pair< int, int > > > > > mp;
  21. int n,m;
  22. cin>>n>>m;
  23. for(int i=0;i<n;i++){
  24. string s;
  25. cin>>s;
  26. int x,y,z;
  27. cin>>x>>y>>z;
  28. vector< pair<int,int> > v;
  29. for(int j=0;j<z;j++){
  30. int a,b;
  31. cin>>a>>b;
  32. v.push_back(make_pair(a,b));
  33. }
  34. mp[s] = make_pair(make_pair(x,y),make_pair(z,v));
  35. }
  36. for(int i=0;i<m;i++){
  37. string s;
  38. cin>>s;
  39. cout<<s<<"[";
  40. int x,y,z;
  41. x = mp[s].first.first;
  42. y = mp[s].first.second;
  43. z = mp[s].second.first;
  44. vector< pair<int,int> > v;
  45. v = mp[s].second.second;
  46. vector<int>t;
  47. for(int j=0;j<z;j++){
  48. if(j) cout<<", ";
  49. int a;
  50. cin>>a;
  51. cout<<a;
  52. t.push_back(a);
  53. }
  54. cout<<"] = ";
  55. int total = x,next = 1;
  56. for(int j=z-1;j>=0;j--){
  57. int u,d,a,diff;
  58. u = v[j].second;
  59. d = v[j].first;
  60. diff = u - d + 1;
  61. a = t[j] - d;
  62. a*=y;
  63. a*=next;
  64. total+=a;
  65. next*=diff;
  66. }
  67. cout<<total<<'\n';
  68. }
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement