Untitled
unknown
plain_text
a month ago
988 B
9
Indexable
Never
#include <bits/stdc++.h> using namespace std; int kuma[1200],c=0; bool chech(int k, int tong, int n, int a[]) { int cur = 0; int sodem = 0; int target = tong / k; if (tong % k != 0) return false; for (int i = 0; i < n; i++) { cur += a[i]; if (cur == target) { sodem++; cur = 0; kuma[c]=i; c++; } else if (cur > target) { c=0; return false; } } if (cur !=0) c=0; return (sodem == k); } int main() { int n; cin >> n; int a[1205]; int sum = 0; for (int u = 0; u < n; u++) { cin >> a[u]; sum += a[u]; } for (int k = n; k > 0; k--) { c=0; if (chech(k, sum, n, a)) { cout << k << endl; break; } } for (int u=0;u<c;u++) { cout << kuma[u]+1<<" "; } return 0; }
Leave a Comment