fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define file(name) if(fopen(name".inp","r")){freopen(name".INP","r",stdin);freopen(name".OUT","w",stdout);}
  4. #define Fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  5. #define int long long
  6. #define endl '\n'
  7. const int N = 1e6 + 5;
  8. const int mod = 1e9 + 7;
  9. vector<int> res;
  10. int n,a[5005];
  11.  
  12. void check(int target){
  13. int sum = 0;
  14. vector<int> p;
  15. bool flag = true;
  16. for (int i = 1; i <= n; i++) {
  17. sum += a[i];
  18. if (sum == target) {
  19. p.push_back(i);
  20. sum = 0;
  21. }
  22. }
  23. if(sum == 0 && p.back() != n) p.pop_back() , p.push_back(n);
  24. if (sum == 0 && res.size() < p.size()) res = p;
  25. }
  26.  
  27. void solve() {
  28. cin >> n;
  29. for (int i = 1; i <= n; ++i) {
  30. cin >> a[i];
  31. }
  32. int sum = 0;
  33. for (int i = 1; i <= n; ++i) {
  34. sum += a[i];
  35. check(sum);
  36. }
  37. if(res.size() == 0){
  38. cout << 1 << "\n";
  39. cout << n;
  40. }
  41. else{
  42. cout << res.size() << '\n';
  43. for (int x : res) cout << x << ' ';
  44. }
  45. }
  46. signed main(){
  47. Fastio
  48. //file("");
  49. solve();
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
1
0