fork download
  1. /* Author : Nguyen Thanh Tung */
  2.  
  3. #include <bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. long long n, k, a[100006], q;
  8. pair<long long, long long> p[100006];
  9.  
  10. int tknp(int l, int r, int x) {
  11. int ans = -1;
  12. while(l <= r) {
  13. int mid = (l + r) / 2;
  14. if(p[mid].first == x) {
  15. ans = mid;
  16. r = mid - 1;
  17. }
  18. else if(p[mid].first > x) {
  19. r = mid - 1;
  20. }
  21. else {
  22. l = mid + 1;
  23. }
  24. }
  25. return ans;
  26. }
  27.  
  28. void solve() {
  29. cin >> n >> k;
  30. for(int i = 1; i <= n; ++i) {
  31. cin >> a[i];
  32. }
  33. int s = 0;
  34. for(int i = 1; i <= n; i++){
  35. s += a[i];
  36. if(i >= k) {
  37. p[i] = {s, i - k + 1};
  38. s -= a[i - k + 1];
  39. }
  40. }
  41. sort(p + k, p + n + 1);
  42. cin >> q;
  43. while(q--) {
  44. int x;
  45. cin >> x;
  46. int pos = tknp(k, n, x);
  47. if(pos != -1) {
  48. cout << p[pos].second << " " << p[pos].second + k - 1 << endl;
  49. }
  50. else {
  51. cout << 0 << " " << 0 << endl;
  52. }
  53. }
  54. }
  55.  
  56. int main () {
  57. solve();
  58. return 0;
  59. }
  60.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty