fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6. inline int power(int a, int b) {
  7. int x = 1;
  8. while (b) {
  9. if (b & 1) x *= a;
  10. a *= a;
  11. b >>= 1;
  12. }
  13. return x;
  14. }
  15.  
  16.  
  17. const int M = 1000000007;
  18. const int N = 3e5+9;
  19. const int INF = 2e9+1;
  20. const int LINF = 2000000000000000001;
  21.  
  22. //_ ***************************** START Below *******************************
  23.  
  24. vector<int> a;
  25.  
  26. pair<int,int> consistency(int n, int k){
  27.  
  28. //* k = total*x + y
  29. //* [ _ _ _ _ ( _ _ _] [ ] [ ] ... [ ] [ _ _ _) _ _ _ _ ]
  30. //* y1 n * x y2
  31. //* y1 + y2 == y
  32.  
  33. //* l
  34. //* [ _ _ _ _ ( _ _ _] [ _ _ _) _ _ _ _ ]
  35. //* y
  36.  
  37. int total = 0;
  38. for(int i=0; i<n; i++) total += a[i];
  39. int x = k/total;
  40. int y = k%total;
  41. k = y;
  42.  
  43. if(y==0) return {1, x*n};
  44.  
  45.  
  46. vector<int> b(a);
  47. for(int i=0; i<n; i++){
  48. b.push_back(a[i]);
  49. }
  50. int m = b.size();
  51.  
  52.  
  53.  
  54. int minLen = INT32_MAX;
  55. int left = -1;
  56. int sum = 0;
  57.  
  58. int s = 0, e = 0;
  59. while(e<m){
  60. sum += b[e];
  61.  
  62. if(sum < k){
  63. e++;
  64. }
  65. else{
  66. while(s<=e && sum >= k){
  67. int len = e-s+1;
  68. if(len < minLen){
  69. minLen = len;
  70. left = s+1;
  71. }
  72. sum -= b[s];
  73. s++;
  74. }
  75. e++;
  76. }
  77. }
  78.  
  79. return {left, x*n + minLen};
  80. }
  81.  
  82.  
  83.  
  84.  
  85. void solve() {
  86.  
  87. int n, k;
  88. cin>>n >> k;
  89.  
  90. a.resize(n);
  91. for(int i=0; i<n; i++) cin >> a[i];
  92.  
  93. auto ans = consistency(n, k);
  94.  
  95. cout << ans.first << " " << ans.second << endl;
  96.  
  97.  
  98. }
  99.  
  100.  
  101.  
  102.  
  103.  
  104. int32_t main() {
  105. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  106.  
  107. int t = 1;
  108. // cin >> t;
  109. while (t--) {
  110. solve();
  111. }
  112.  
  113. return 0;
  114. }
Success #stdin #stdout 0s 5320KB
stdin
3 20
5 2 3
9 10
1 2 3 4 5 4 3 2 1
3 100
10 10 10
stdout
1 6