From 669f3d29315435001bc4da30b899ba82091deec1 Mon Sep 17 00:00:00 2001 From: vmundra Date: Fri, 2 Oct 2020 17:13:39 +0530 Subject: [PATCH] added C++ solution of 285C Div2 Codeforces --- 285C - Beautiful Permutation.cpp | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 285C - Beautiful Permutation.cpp diff --git a/285C - Beautiful Permutation.cpp b/285C - Beautiful Permutation.cpp new file mode 100644 index 0000000..0e906bf --- /dev/null +++ b/285C - Beautiful Permutation.cpp @@ -0,0 +1,38 @@ +/* +*Problem Name (C. Building Permutation) +*Problem Statement :- +You have a sequence of integers a1, a2, ..., an. In one move, you are allowed to decrease or increase any number by one. +Count the minimum number of moves, needed to build a permutation from this sequence. +*/ + +#include +using namespace std; +typedef long long ll; + +int main(){ + + ll n;cin>>n; // ll is long long data type as defined above + ll arr[n]; + for(ll i=0; i>arr[i]; + } + + sort(arr,arr+n); //first we sort the array + ll diff =0, sum =0; + + for(ll i=0; i