fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct gv{
  5. long long value , pref , prefk;
  6. };
  7. gv a[100007];
  8. struct gv1{
  9. long long value , place;
  10. };
  11. gv1 b[100007];
  12. bool cmp(gv1 x , gv1 y){
  13. if (x.value < y.value){
  14. return true;
  15. }
  16. if (x.value == y.value){
  17. return x.place < y.place;
  18. }
  19. return false;
  20. }
  21.  
  22. int main(){
  23. freopen("DUONGDEP.INP","r",stdin);
  24. freopen("DUONGDEP.OUT","w",stdout);
  25. ios_base::sync_with_stdio(false);
  26. cin.tie(NULL);
  27. int n;
  28. long long k;
  29. cin >> n >>k;
  30. for (int i=1 ; i<=n ; i++){
  31. cin >> a[i].value;
  32. a[i].pref = a[i - 1].pref + a[i].value;
  33. a[i].prefk = a[i - 1].prefk + k;
  34. b[i].value = a[i].pref - a[i].prefk;
  35. b[i].place = i;
  36. }
  37. b[0].place = 0;
  38. b[0].value = 0;
  39. sort(b,b+n+1,cmp);
  40. int i=0 ;
  41. long long ans = 0;
  42. while (i <= n){
  43. int j = i;
  44. while (b[j + 1].value == b[i].value && j < n){
  45. j++;
  46. }
  47. ans = max(ans , b[j].place - b[i].place);
  48. i = j + 1;
  49. }
  50. if (ans == 0){
  51. cout << 0;
  52. return 0;
  53. }
  54. i = 0;
  55. long long Id = n + 1;
  56. while (i <= n){
  57. int j = i;
  58. while (b[j + 1].value == b[i].value && j < n){
  59. j++;
  60. }
  61. if (ans == b[j].place - b[i].place){
  62. Id = min(b[i].place + 1 , Id);
  63. }
  64. i = j + 1;
  65. }
  66. cout << Id << " " << ans;
  67. return 0;
  68. }
  69.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty