Codeforces Round #421 (Div. 2), problem: (D) Mister B and PR Shifts Solution In C/C++

By | 2017-08-05T22:15:33+00:00 August 5th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , , |

#include<stdio.h> #include<stdlib.h> #define LL long long int p[1000005], cur[2000005]; int main(void) { LL ans, sum; int n, L, r, i, temp; scanf("%d", &n); sum = L = r = temp = 0; for(i=1;i<=n;i++) scanf("%d", &p[i]); for(i=1;i<=n;i++) { sum += abs(p[i]-i); if(p[i]>=i) L++, cur[p[i]-i]++; else [...]