D
//一看是绝对值就想到数轴,让找min值则运用中位数定理,虽然让-i,但实际在读入的时候把每个读入的数-i就可以了。
#include<bits/stdc++.h>
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define fi first
#define se second
#define endl '\n'
#define bug printf("bug\n");
using namespace std;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
const long long LNF=0x3f3f3f3f3f3f3f3f;
const long long mod=1e9+7;
long long s[N];
long long fastpower(long long down,long long power,long long mod){
long long res=1;
while(power){
if(power&1) res=res*down%mod;
down=down*down%mod;
power=power>>1;
}
return res;
}
void solve(){
int n; scanf("%d",&n);
for(int i=1;i<=n;i++){
long long x; scanf("%lld",&x);
s[i]=x-i;
}
sort(s+1,s+n+1);
long long pos;
if(n%2==0) pos=(s[n/2]+s[n/2+1])/2;
else pos=s[n/2+1];
long long sum=0;
for(int i=1;i<=n;i++){
sum=sum+abs(s[i]-pos);
}
printf("%lld\n",sum);
}
int main(){
int t=1;
//scanf("%d",&t);
while(t--){
solve();
}
return 0 - 0;
}
E
//经典贪心,按r升序排序,然后尽量往后取,看最少需要多少个
#include<bits/stdc++.h>
#define PII pair<int,int>
#define PLL pair<long long,long long>
#define fi first
#define se second
#define endl '\n'
#define bug printf("bug\n");
using namespace std;
const int N=2e5+10;
const int INF=0x3f3f3f3f;
const long long LNF=0x3f3f3f3f3f3f3f3f;
const long long mod=1e9+7;
struct node{
int l,r;
friend bool operator < (node w,node z){
return w.r<z.r;
}
}q[N];
long long fastpower(long long down,long long power,long long mod){
long long res=1;
while(power){
if(power&1) res=res*down%mod;
down=down*down%mod;
power=power>>1;
}
return res;
}
void solve(){
int n,m; scanf("%d %d",&n,&m);
for(int i=1;i<=m;i++){
int a,b; scanf("%d %d",&a,&b);
q[i]={a,b};
}
sort(q+1,q+m+1);
int nw=q[1].r;
int cnt=1;
for(int i=1;i<=m;i++){
if(q[i].l<nw) continue;
else{
nw=q[i].r;
cnt++;
}
}
printf("%d\n",cnt);
}
int main(){
int t=1;
//scanf("%d",&t);
while(t--){
solve();
}
return 0 - 0;
}
F
//只有2^3=8种情况,暴力排序处理即可
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int i,j,k;
struct node{
long long a,b,c;
friend bool operator < (node w,node z){
long long num1=w.a*i+w.b*j+w.c*k;
long long num2=z.a*i+z.b*j+z.c*k;
return num1>num2;
}
}s[N];
int main(){
int t=1;
//scanf("%d",&t);
while(t--){
int n,m; scanf("%d %d",&n,&m);
long long res=0;
for(int i=1;i<=n;i++){
long long a,b,c; scanf("%lld %lld %lld",&a,&b,&c);
s[i]={a,b,c};
}
for(i=-1;i<=1;i+=2){
for(j=-1;j<=1;j+=2){
for(k=-1;k<=1;k+=2){
sort(s+1,s+n+1);
long long num1=0,num2=0,num3=0;
for(int h=1;h<=m;h++){
num1+=s[h].a,num2+=s[h].b,num3+=s[h].c;
}
res=max(res,num1*i+num2*j+num3*k);
}
}
}
printf("%lld\n",res);
}
return 0 - 0;
}