fork(11) download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int n;
  7. int sum;
  8. int l, r;
  9. int ans = 360;
  10. int a[360];
  11.  
  12. int main()
  13. {
  14. cin >> n;
  15. for (int i = 0; i < n; i++)
  16. cin >> a[i];
  17. while (r < n)
  18. {
  19. sum += a[r];
  20. while (sum >= 180)
  21. {
  22. ans = min(ans, 2 * abs(180 - sum));
  23. sum -= a[l];
  24. l++;
  25. }
  26. ans = min(ans, 2 * abs(180 - sum));
  27. r++;
  28. }
  29. cout << ans << endl;
  30. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
360