lalalalalalalaalalla

Untitled

May 19th, 2021
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ostream>
  4. #include <istream>
  5. #include <set>
  6. #include <unordered_set>
  7. #include <map>
  8. #include <unordered_map>
  9. #include <bitset>
  10. #include <vector>
  11. #include <string>
  12. #include <stack>
  13. #include <queue>
  14. #include <deque>
  15. #include <array>
  16. #include <algorithm>
  17. #include <functional>
  18. #include <cmath>
  19. #include <time.h>
  20. #include <random>
  21. #include <chrono>
  22. #include <cassert>
  23. #include <cstring>
  24. #include <limits>
  25.  
  26. using namespace std;
  27.  
  28. #define int long long
  29. #define pb push_back
  30. #define ppb pop_back
  31. #define all(a) (a).begin(), (a).end()
  32. #define pii pair<int, int>
  33. #define ld long double
  34.  
  35. istream& operator>> (istream& in, pii& b) {
  36.     in >> b.first >> b.second;
  37.     return in;
  38. }
  39.  
  40. ostream& operator<< (ostream& out, const pii& b) {
  41.     out << "{" << b.first << ", " << b.second << "}";
  42.     return out;
  43. }
  44.  
  45. template<typename T> ostream& operator<< (ostream& out, const vector<T>& a) {
  46.     for (auto k : a) out << k << " ";
  47.     return out;
  48. }
  49.  
  50. template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
  51. template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}
  52.  
  53. #ifdef LOCAL
  54.     #define dbg(x) cout << #x << " : " << (x) << endl;
  55.     const long long INF = 1e18;
  56.     // const long long mod = 2600000069;
  57.     // const long long p = 10;
  58. #else
  59.     #define dbg(x) 57
  60.     const long long INF = 1e18;
  61.     // const long long mod = 2600000069;  
  62.     // const long long p = 179;
  63. #endif
  64.  
  65. const ld PI = 4 * atan(1);
  66.  
  67. #define time clock() / (double) CLOCKS_PER_SEC
  68.  
  69. // #pragma GCC optimize("Ofast,no-stack-protector")
  70. // #pragma GCC target("sse,sse2,sse3,sse3,sse4")
  71. // #pragma GCC optimize("unroll-loops")
  72. // #pragma GCC optimize("fast-math")
  73. // #pragma GCC target("avx2")
  74.  
  75. mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
  76.  
  77. const int N = 1010;
  78.  
  79. int m, n;
  80. int a[N][3];
  81. int ans[N];
  82.  
  83. bool check(int t) {
  84.     int sum = 0;
  85.     for (int i = 0; i < n; i++) {
  86.         int one = a[i][0], mx = a[i][1], rest = a[i][2];
  87.         int len = one * mx + rest;
  88.         ans[i] = t / len * mx + min((t % len) / one, mx);
  89.         sum += ans[i];
  90.     }
  91.     return sum >= m;
  92. }
  93.  
  94. signed main() {
  95.     ios_base::sync_with_stdio(0);
  96.     cin.tie(0);
  97.     cout.tie(0);
  98.     cin >> m >> n;
  99.     for (int i = 0; i < n; i++) {
  100.         for (int j = 0; j < 3; j++) {
  101.             cin >> a[i][j];
  102.         }
  103.     }
  104.     int l = -1, r = 1e10; // upper bound is actually 14999 * 200 + 100
  105.     while (r - l > 1) {
  106.         int mid = (l + r) / 2;
  107.         if (check(mid)) {
  108.             r = mid;
  109.         } else {
  110.             l = mid;
  111.         }
  112.     }
  113.     cout << r << "\n";
  114.     check(r);
  115.     for (int i = 0; i < n; i++) {
  116.         cout << min(ans[i], m) << " ";
  117.         m -= min(ans[i], m);
  118.     }
  119.     cout << "\n";
  120. }
  121. /*
  122.  
  123. */
  124.  
Advertisement
Add Comment
Please, Sign In to add comment