orazma

l.cpp

May 12th, 2026
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define s second
  4. #define f first
  5. #define mp make _pair
  6. #define ld long double
  7. #define pb push_back
  8. #define ull unsigned long long
  9.  
  10. using namespace std;
  11. const int MAXN = 4e6 + 7;
  12. const int INF = 1e9 + 7;
  13. const int MOD = 1e9 + 7;
  14. const double EPS = 1e-6;
  15.  
  16. bool dp[MAXN];
  17. ll l, r, ans[MAXN], nxt[MAXN];
  18. int n, a[MAXN], pr[MAXN], pos[505];
  19.  
  20. void solve () {
  21.     cin >> n >> l >> r;
  22.     // n = 200'000;
  23.     // l = (ll)1e17, r = (ll)1e18;
  24.     for (int i = 1; i <= n; i++) {
  25.         cin >> a[i];
  26.         // a[i] = rand() % 51;
  27.         l -= a[i];
  28.         r -= a[i];
  29.         if (!pos[a[i]])
  30.             pos[a[i]] = i;
  31.     }
  32.     if (r < 0) {
  33.         cout << -1;
  34.         return;
  35.     }
  36.     l = max(0ll, l);
  37.     dp[0] = 1;
  38.     for (int i = 1; i <= 500; ++i) {
  39.         if (!pos[i])
  40.             continue;
  41.         for (int j = i; j <= 1'000'000; ++j) {
  42.             if (!dp[j] && dp[j - i]) {
  43.                 dp[j] = 1;
  44.                 pr[j] = i;
  45.             }
  46.         }
  47.     }
  48.     nxt[1'000'001] = (ll)2e18;
  49.     for (int i = 1'000'000; i >= 0; --i)
  50.         nxt[i] = (dp[i] ? i : nxt[i + 1]);
  51.     for (int i = 0; i <= 1'000'000; i++) {
  52.         if (!dp[i]) continue;
  53.         ll rem = (i ? l % i : l);
  54.         ll cnt = (i ? l / i : 0);
  55.         ll r1 = r - cnt * i;
  56.         if (rem > 1'000'000 || nxt[rem] > 1'000'000 || nxt[rem] > r1 || !dp[nxt[rem]])
  57.             continue;
  58.         for (int j = 1; j <= n; j++)
  59.             ans[j] = 1;
  60.         int s = i;
  61.         while (s) {
  62.             ans[pos[pr[s]]] += cnt;
  63.             s -= pr[s];
  64.         }
  65.         s = nxt[rem];
  66.         while (s) {
  67.             ans[pos[pr[s]]]++;
  68.             s -= pr[s];
  69.         }
  70.         for (int j = 1; j <= n; j++)
  71.             cout << ans[j] << " ";
  72.         return;
  73.     }
  74.     cout << -1;
  75. }
  76.  
  77. int main() {
  78.     cin.tie(NULL);
  79.     cout.tie(NULL);
  80.     ios_base::sync_with_stdio(false);
  81.  
  82.     int t = 1;
  83.     //cin >> t;
  84.     while (t--) {
  85.         solve();
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment