Advertisement
erfanul007

UVa 10670

Dec 13th, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // #pragma GCC optimize("Ofast,no-stack-protector")
  5. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. // #pragma GCC optimize("unroll-loops")
  7.  
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10. typedef long double lld;
  11. typedef vector<int> vi;
  12. typedef vector<ll> vll;
  13. typedef vector<vi> vvi;
  14. typedef pair<int,int > pii;
  15. typedef vector< pii > vpii;
  16. typedef set<int> sti;
  17.  
  18. #define sc scanf
  19. #define pf printf
  20. #define sci(n) scanf("%d",&n)
  21. #define scii(n,m) scanf("%d %d",&n,&m)
  22. #define scl(n) scanf("%lld",&n)
  23. #define scd(n) scanf("%lf",&n)
  24. #define scs(s) scanf("%s",s)
  25. #define pfi(n) printf("%d",n)
  26. #define pfl(n) printf("%lld",n)
  27. #define pff(n) cout<<n
  28. #define spc printf(" ")
  29. #define line printf("\n")
  30. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  31. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  32. #define cspf(i) printf("Case %d\n", i)
  33. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  34. #define clr(a,x) memset(a,x,sizeof(a))
  35. #define tp(v,j) get<j>(v)
  36. #define pb push_back
  37. #define mp make_pair
  38. #define mt make_tuple
  39. #define ff first
  40. #define ss second
  41. #define all(v) v.begin(),v.end()
  42. #define rall(v) v.rbegin(),v.rend()
  43. #define read() freopen("input.txt", "r", stdin)
  44. #define write() freopen("output.txt", "w", stdout)
  45. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  46. /// Constants
  47. #define eps 1e-6
  48. #define PI acos(-1.0) // 3.1415926535897932
  49. #define MAX (int)1000000009
  50.  
  51. int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
  52. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  53.  
  54.  
  55. int main()
  56. {
  57. #ifdef VAMP
  58. clock_t tStart = clock();
  59. freopen("input.txt", "r", stdin);
  60. freopen("output.txt", "w", stdout);
  61. #endif
  62.  
  63. int t;
  64. sci(t);
  65. loop(ca,1,t){
  66. cspf(ca);
  67. vector< pair<int,string> > ans;
  68. ll n,m,l;
  69. scanf("%lld %lld %lld",&n,&m,&l);
  70. loop(i,1,l){
  71. ll a,b;
  72. int j=0;
  73. getchar();
  74. string s="";
  75. while(1){
  76. char c;
  77. scanf("%c",&c);
  78. if(c==':') break;
  79. s+=c;
  80. }
  81. scanf("%lld,%lld",&a,&b);
  82. ll y = n;
  83. ll sum=0;
  84. while(y>=m*2){
  85. ll z = y/2;
  86. z = y-z;
  87. ll u = z*a;
  88. sum+=min(u,b);
  89. y/=2;
  90. }
  91. sum+=((y-m)*a);
  92. ans.pb(mp(sum,s));
  93.  
  94. }
  95. sort(all(ans));
  96. loop(i,0,ans.size()-1){
  97. cout<<ans[i].ss<<' '<<ans[i].ff<<'\n';
  98. }
  99. }
  100.  
  101. #ifdef VAMP
  102. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  103. #endif
  104.  
  105. return 0;
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement