Advertisement
artemgf

Чудо техники

May 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #pragma once
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #define _USE_MATH_DEFINES
  4. #include <iostream>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9. #include <vector>
  10. #include <stdio.h>
  11. #include <cmath>
  12. #include <math.h>
  13. #include <queue>
  14. #include <stack>
  15. #include <climits>
  16. #include <deque>
  17. #include <ctime>
  18. #include <iomanip>
  19. #include <bitset>
  20. #include <unordered_map>
  21. #include <unordered_set>
  22.  
  23. using namespace std;
  24.  
  25. typedef long long ll;
  26. typedef unsigned long long ull;
  27. typedef unsigned int ui;
  28.  
  29. #define mh() make_heap()
  30. #define poph() pop_heap()
  31. #define pushh() push_heap()
  32. #define sor(n) n.begin(), n.end()
  33. #define rsor(n) n.rbegin(), n.rend()
  34. #define mp make_pair
  35. #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
  36. #define p(T) pair<T,T>
  37. #define toch(x) cout.precision(x), cout.setf(ios::fixed)
  38. #define znac(l) abs(l)/l
  39. #define IOS ios::sync_with_stdio(false)
  40. #define IOSB cin.tie(0), cout.tie(0);
  41. const ll ok = ll(1e9 + 7);
  42.  
  43. int main()
  44. {
  45.     IOSB;
  46.     IOS;
  47. #ifdef TheCompiler
  48.     files;
  49. #endif 
  50.     ll m, k, d;
  51.     cin >> k >> m >> d;
  52.     ll answ = 0;
  53.     ll frs = 0;
  54.     ll pr = 1;
  55.     for (int i = d; i <= 7; i++)
  56.     {
  57.         if (i != 7 && i != 6)
  58.         {
  59.             m += k;
  60.         }
  61.         if (m - pr < 0)
  62.         {
  63.             cout << i - d << endl;
  64.             return 0;
  65.         }
  66.         m -= pr;
  67.         pr++;
  68.     }
  69.     answ = 7 - d + 1;
  70.     if (pr > k + m)
  71.     {
  72.         cout << answ << endl;
  73.         return 0;
  74.     }
  75.     answ+=((k - pr) >= 0 ? (k - pr) : 0 * 6) / 7;
  76.     pr += 7 * (((k - pr) >= 0 ? (k - pr) : 0 * 6) / 7);
  77.     ll ost = ((k - pr)>=0? (k - pr):0 * 6) % 7;
  78.     answ += ost;
  79.     for (int i = ost; i <= 7; i++)
  80.     {
  81.         if (i != 7 && i != 6)
  82.         {
  83.             m += k;
  84.         }
  85.         if (m - pr < 0)
  86.         {
  87.             cout << answ+i-ost<< endl;
  88.             return 0;
  89.         }
  90.         m -= pr;
  91.         pr++;
  92.     }
  93.     answ += 7 - ost + 1;
  94.     if ((2 * pr - 7) + 8 * m * 7 < 0)
  95.     {
  96.         for (int i = ost; i <= 7; i++)
  97.         {
  98.             if (i != 7 && i != 6)
  99.             {
  100.                 m += k;
  101.             }
  102.             if (m - pr < 0)
  103.             {
  104.                 cout << answ + i - ost << endl;
  105.                 return 0;
  106.             }
  107.             m -= pr;
  108.             pr++;
  109.         }
  110.     }
  111.     else
  112.     {
  113.         double dec = sqrt((2 * pr - 7) + 8 * m * 7);
  114.         double x1 = ((-(2 * pr - 7)) + dec) / 14.0;
  115.         double x2 = ((-(2 * pr + 7)) + dec) / 14.0;
  116.         ll n;
  117.         if (x1 < 0 || x2 < 0)
  118.         {
  119.             n = max(x1, x2);
  120.         }
  121.         else
  122.         {
  123.             n = min(x1, x2);
  124.         }
  125.         pr += 7 * (n - 1);
  126.         m -= ((pr * 2 + 7 * (n - 1))*n) / 2;
  127.         answ += n;
  128.         for (int i = ost; i <= 7; i++)
  129.         {
  130.             if (i != 7 && i != 6)
  131.             {
  132.                 m += k;
  133.             }
  134.             if (m - pr < 0)
  135.             {
  136.                 cout << answ + i - ost << endl;
  137.                 return 0;
  138.             }
  139.             m -= pr;
  140.             pr++;
  141.         }
  142.         answ += 7 - ost + 1;
  143.     }
  144.     cout << answ;
  145.     return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement