Submission #2767290


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 2e5+1;

int a[N];
int main(){
	int n, b;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		a[i] -= i;
	}
	sort(a+1, a+n+1);
	if(n%2)
		b = a[(n+1)/2];
	else b = (a[n/2] + a[n/2 + 1])/2;
	ll ans = 0;
	for(int i = 1; i <= n; i++){
		ans += abs(a[i]-b);
	}
	cout << ans << endl;
	return 0;
}

Submission Info

Submission Time
Task C - Linear Approximation
User harshit_27
Language C++14 (GCC 5.4.1)
Score 300
Code Size 407 Byte
Status
Exec Time 117 ms
Memory 1024 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All 300 / 300 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB
sample_04.txt 1 ms 256 KB
subtask_1_01.txt 1 ms 256 KB
subtask_1_02.txt 23 ms 384 KB
subtask_1_03.txt 19 ms 384 KB
subtask_1_04.txt 54 ms 640 KB
subtask_1_05.txt 93 ms 896 KB
subtask_1_06.txt 107 ms 1024 KB
subtask_1_07.txt 117 ms 1024 KB
subtask_1_08.txt 109 ms 1024 KB
subtask_1_09.txt 110 ms 1024 KB
subtask_1_10.txt 109 ms 1024 KB
subtask_1_11.txt 110 ms 1024 KB