Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin ("subsecv.in");
  6. ofstream fout ("subsecv.out");
  7.  
  8. short n;
  9. short R[10007]; /// R[j]=i -> a[i]%n=j;
  10. short st, dr;
  11.  
  12. int main()
  13. {
  14. short i, rest = 0;
  15. int x;
  16. fin >> n;
  17. st = n + 1;
  18. dr = 0;
  19. for (i = 1; i <= n; i++)
  20. {
  21. fin >> x;
  22. rest = (rest + x) % n;
  23. if (rest == 0)
  24. {
  25. fout << "1 " << i << "\n";
  26. return 0;
  27. }
  28. if (R[rest] != 0) /// Acest rest s-a mai obtinut
  29. {
  30. if (st > R[rest] + 1)
  31. {
  32. st = R[rest] + 1;
  33. dr = i;
  34. }
  35. }
  36. else R[rest] = i;
  37. }
  38. fout << st << " " << dr << "\n";
  39. return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement