Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <iomanip>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <deque>
  12.  
  13.  
  14.  
  15.  
  16. using namespace std;
  17.  
  18. int main() {
  19. long long m;
  20. vector <long long> a(30);
  21. cin >> m;
  22.  
  23. for(long long i = 0; i < 30; ++i) {
  24. cin >> a[i];
  25. }
  26.  
  27. long long ans = 0;
  28. long long count = 0;
  29.  
  30. while(count < m) {
  31.  
  32. long double bettercost = (1 << 30) + 1;
  33. long long idans2 = -1;
  34.  
  35. for(long long i = 0; i < 30; ++i) {
  36. if(a[i] > m - count) {
  37. a[i] = m - count;
  38. }
  39. long double curcost = (1 << i) / (long double) a[i];
  40. if(curcost < bettercost) {
  41. bettercost = curcost;
  42. idans2 = i;
  43. }
  44. }
  45.  
  46. long long necess = m - count;
  47. long long vozmu = necess / a[idans2];
  48. count += vozmu * a[idans2];
  49. ans += vozmu * (1 << idans2);
  50. }
  51.  
  52. cout << ans;
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement