Codeforces Round #436 (Div. 2), problem: (D) Make a Permutation! Solution In C/C++

By | 2017-09-26T16:38:06+00:00 September 26th, 2017|Categories: Uncategorized|Tags: , , , , , , , |

#include<stdio.h> int a[200005], b[200005], sum[200005], flag[200005]; int main(void) { int n, i, p, k; scanf("%d", &n); for(i=1;i<=n;i++) { scanf("%d", &a[i]); sum[a[i]]++; } k = 0; for(i=1;i<=n;i++) { if(sum[i]==0) b[++k] = i; } printf("%d\n", k); p = 1; for(i=1;i<=n;i++) { if(sum[a[i]]==1) continue; if(b[p]<a[i] || flag[a[i]]==1) [...]