fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e6+14;
  4. long long n, s, pre[maxn];
  5. void solve(){
  6. cin >> n >> s;
  7. pre[0] = 0;
  8. unordered_map < long long , int > m;
  9. for (int i = 1; i <= n; i++){
  10. int x;
  11. cin >> x;
  12. pre[i] = pre[i - 1] + x;
  13. if (m[pre[i]] == 0) m[pre[i]] = i;
  14. }
  15.  
  16. m[0] = 0;
  17. for (int i = 1; i <= n; i++) {
  18. for (int j = 0; j < i; j++){
  19. if (pre[i] - pre[j] == s){
  20. cout << "YES" << endl << j + 1 << ".." << i ;
  21. return ;
  22. }
  23. }
  24. }
  25.  
  26. cout << "NO";
  27. return;
  28. }
  29. int main(){
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0); cout.tie(0);
  32. if (fopen("input.txt","r")){
  33. freopen("input.txt","r",stdin);
  34. freopen("output.txt","w",stdout);
  35. }
  36. solve();
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
NO