CodeForces Round #559 Div.2
A. A pile of stones
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; int N; string s; int main() { scanf("%d", &N); cin >> s; int len = s.length(); int ans = 0, temp = -1; for(int i = len - 1; i >= 0; i --) { if(s[i] == '-') { temp = i; break; } } if(temp == -1) ans = len; else { int minn = 1010; ans = 0; for(int i = 0; i <= temp; i ++) { if(s[i] == '+') ans ++; else ans --; minn = min(minn, ans); } if(minn < 0) ans = -minn; else ans = 0; for(int i = 0; i <= temp; i ++) { if(s[i] == '+') ans ++; else ans --; } ans += len - temp - 1; } printf("%d\n", ans); return 0; }
B. Expansion coefficient of the array
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; int N; int a[maxn]; int main() { scanf("%d", &N); int ans = INT_MAX; for(int i = 1; i <= N; i ++) { scanf("%d", &a[i]); ans = min(ans, a[i] / max(i - 1, N - i)); } printf("%d\n", ans); return 0; }
C. The Party and Sweets
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int N, M; long long g[maxn], b[maxn]; int main() { scanf("%d%d", &N, &M); for(int i = 1; i <= N; i ++) scanf("%lld", &b[i]); for(int i = 1; i <= M; i ++) { scanf("%lld", &g[i]); } sort(b + 1, b + 1 + N); sort(g + 1, g + 1 + M); if(b[N] > g[1]) printf("-1\n"); else { long long ans = 0; for(int i = N; i >= 1; i --) ans += b[i] * M; for(int i = 2; i <= M; i ++) ans += g[i] - b[N]; if(g[1] != b[N]) ans += g[1] - b[N - 1]; printf("%lld\n", ans); } return 0; }
D. The minimal unique substring
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> using namespace std; int N, M; int main() { scanf("%d%d", &N, &M); string s = ""; if(M == 1) { s += '1'; for(int i = 0; i < N - 1; i ++) s += '0'; } else { int cnt = (N - M) / 2 + 1; for(int i = 0; i < N; i ++) { if(i % cnt == 0) s += '1'; else s += '0'; } } cout << s << endl; return 0; }