Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f("politic.in");
- ofstream g("politic.out");
- int n;
- int v[20001], nrp;
- int main()
- {
- int i, j, x1, x2, nr = 1;
- f >> n >> x1;
- for(i = 2; i <= n; ++i){
- f >> x2;
- if(x2 - x1 == 1){
- ++nr;
- } else {
- v[++nrp] = nr;
- nr = 1;
- }
- x1 = x2;
- }
- v[++nrp] = nr;
- g << nrp << '\n';
- for(i = 2; i <= nrp; ++i){
- v[i] += v[i-1];
- }
- i = j = 1;
- int nrc = 0, med = n / 2;
- while(j <= nrp){
- if(v[j] - v[i - 1] > med){
- nrc += (nrp - j + 1);
- ++i;
- } else {
- ++j;
- }
- }
- g << nrc;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement