Advertisement
a53

tri

a53
Feb 9th, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /// Marius Nicoli, oficial
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. int n, x, primul, ultimul, i, pozImpAntAnt, pozImpAnt, impare;
  6. long long sumaCurenta, sumaAnterioara, minim, dif;
  7.  
  8. int main () {
  9. ifstream fin ("tri.in");
  10. ofstream fout("tri.out");
  11.  
  12.  
  13. fin>>n;
  14. minim = 2000000000;
  15. for (i=1;i<=n;i++) {
  16. fin>>x;
  17. if (x % 2 == 0)
  18. sumaCurenta += x;
  19. else {
  20. impare++;
  21. if (impare >= 3) {
  22. dif = sumaCurenta - sumaAnterioara;
  23. if (dif < 0)
  24. dif = -dif;
  25. if (dif <= minim) {
  26. minim = dif;
  27. primul = pozImpAntAnt;
  28. ultimul = i;
  29. }
  30. }
  31. pozImpAntAnt = pozImpAnt;
  32. pozImpAnt = i;
  33. sumaAnterioara = sumaCurenta;
  34. sumaCurenta = 0;
  35. }
  36. }
  37. fout<<primul<<" "<<ultimul;
  38. return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement