[BOJ/C+]2012号スコア

Code #include <iostream>
#include <algorithm>
#include <math.h>
#define MAX 500001
using namespace std;
int n;
int wish[MAX];
int cnt=0;
void Input(){
cin>>n;
for(int i=0; i<n; i++){
cin>>wish[i];
}
}
void Solution(){
sort(wish, wish+n);
for(int i=0; i<n; i++){
cnt+=abs(i+1-wish[i]);
}
cout<<cnt<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
Input();
Solution();
return 0;
}
Reference
この問題について([BOJ/C+]2012号スコア), 我々は、より多くの情報をここで見つけました
https://velog.io/@xx0hn/BOJ-C-2012번-등수-매기기
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
#include <iostream>
#include <algorithm>
#include <math.h>
#define MAX 500001
using namespace std;
int n;
int wish[MAX];
int cnt=0;
void Input(){
cin>>n;
for(int i=0; i<n; i++){
cin>>wish[i];
}
}
void Solution(){
sort(wish, wish+n);
for(int i=0; i<n; i++){
cnt+=abs(i+1-wish[i]);
}
cout<<cnt<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
Input();
Solution();
return 0;
}
Reference
この問題について([BOJ/C+]2012号スコア), 我々は、より多くの情報をここで見つけました https://velog.io/@xx0hn/BOJ-C-2012번-등수-매기기テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol