Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
- #define NeedForSpeed \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- #define int long long
- #define all(x) (x).begin(), (x).end()
- typedef vector<int> vi;
- const int INF = 1e18;
- void solve()
- {
- int n, p;
- cin >> n >> p;
- vi a(n);
- int sum = 0;
- for (int i = 0; i < n; i++)
- {
- cin >> a[i];
- sum += a[i];
- }
- int l = 0, r = 0, cur_sum = 0;
- int min_length = INF, start = -1;
- while (r < 2 * n)
- {
- cur_sum += a[r % n];
- while (cur_sum >= p)
- {
- if (r - l + 1 < min_length)
- {
- min_length = r - l + 1;
- start = l % n;
- }
- cur_sum -= a[l % n];
- l++;
- }
- r++;
- }
- if (min_length == INF)
- // means no subarray, and we have to take the whole array
- {
- int ans = p / sum;
- ans *= n;
- int actsum = (p / sum) * sum;
- for (int i = 0; i < n; i++)
- {
- actsum += a[i];
- if (actsum >= p)
- {
- ans += i + 1;
- break;
- }
- }
- // start from 1, and take the whole array
- cout << 1 << " " << ans << endl;
- }
- else
- {
- cout << start + 1 << " " << min_length << endl;
- }
- }
- signed main()
- {
- NeedForSpeed;
- int t = 1;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment