Sponsors

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

#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 r++;
}
ans = sum;
for(i=0;i<n-1;i++)
{
L -= cur[i]; r += cur[i];
sum = sum-L+r-abs(p[n-i]-n-1)+p[n-i]-1;
cur[p[n-i]+i]++;
L++, r–;
if(sum<ans)
ans = sum, temp = i+1;
}
printf(“%lld %d\n”, ans, temp);
return 0;
}

Major Disney World rival...

A Major Disney World Rival Is Demolishing Two Iconic...

Introducing Apache Spark upgrade...

AWS Simplifies Big Data Migration with Apache Spark Upgrade...

In an act of...

Malaysia’s Consumer Boycott Fuels the Rise of Home-Grown Fast...

Couples on N70,000 minimum...

The Price of Parenthood: Why N70,000 Minimum Wage Couples...

Fobi AI Announces Partial...

Fobi AI Secures Partial Revocation Order, Launches Strategic Private...

Beautiful AI-Generated Alloy of...

AI-Generated "Pretty" Aloy Sparks Predictable Fury Across Social Media The...

Major Disney World rival is demolishing two iconic theme park rides

A Major Disney World Rival Is Demolishing Two Iconic Theme Park Rides The landscape of American amusement parks is defined by constant evolution, intense rivalry,...

Introducing Apache Spark upgrade agent for Amazon EMR

AWS Simplifies Big Data Migration with Apache Spark Upgrade Agent for EMR Amazon Web Services (AWS) has rolled out a crucial new tool for big...

In an act of boycott, Malaysia makes its own ‘McDonald’s’

Malaysia’s Consumer Boycott Fuels the Rise of Home-Grown Fast Food Alternatives A significant shift is reshaping the Malaysian quick-service restaurant (QSR) landscape. Driven by widespread...

Couples on N70,000 minimum wage can’t afford fertility treatment — Specialists

The Price of Parenthood: Why N70,000 Minimum Wage Couples Can't Afford Fertility Treatment in Nigeria The dream of starting a family is facing an insurmountable...

Fobi AI Announces Partial Revocation Order and Non-Brokered Private Placement

Fobi AI Secures Partial Revocation Order, Launches Strategic Private Placement VANCOUVER, BC – Fobi AI Inc. (TSXV: FOBI) (Pink: FOBIF), a leading provider of real-time...

Beautiful AI-Generated Alloy of Horizon Zero Dawn Attracts the Usual Ire

AI-Generated "Pretty" Aloy Sparks Predictable Fury Across Social Media The intersection of fan art, AI generation, and hotly debated video game character design erupted once...

Do GloFish glow under black light?

Do GloFish Glow Under Black Light? Unveiling the Fluorescent Secret The aquarium world is full of dazzling colors, but few sights are as mesmerizing as...

NASCAR Trial Intensifies As Jim France And Richard Childress Testify

NASCAR Trial Heats Up as Jim France and Richard Childress Face the Court The high-stakes legal battle surrounding NASCAR’s governance and team economics reached a...

Google previews upcoming Android XR smart glasses equipped with Gemini

Google Unveils Android XR Smart Glasses Powered by Gemini AI Google LLC is pulling back the curtain on its long-awaited foray into the next generation...