51Nod 1294 Modifying an array

Source: Internet
Author: User
Tags time limit

Source: Hackerrank Base time limit: 1 seconds space limit: 131072 KB score: 160 Difficulty: 6-level algorithm problem collection focus on giving an integer array A, you can change any number to any positive integer, eventually making the entire array strictly incremented and all positive integers. What are the minimum number of changes to ask? Input
Line 1th: A number N indicates the length of the sequence (1 <= n <= 100000). 2-n + 1 lines: 1 numbers per line, corresponding to array elements. (0 <= A[i] <= 10^9)
Output
The minimum number of outputs required to be modified makes the entire array strictly incremented.
Input example
512234
Output example
3
1 //2018-07-16 17:15:292#include <iostream>3#include <cstdio>4#include <algorithm>5 using namespacestd;6 7 Const intN =1000005;8 9 intN;Ten intA[n], d[n], b[n], ans; One  A intMain () { -scanf"%d", &n); -     intHead =0; the      for(intI=1; i<=n; i++){ -scanf"%d", &b[i]); -         if(b[i]==0&& i==1) A[++head] = B[i];//a lazy place. -         if(B[i]-i >=0) A[++head] = b[i]-i; +         Elseans++; -     } +d[1] = a[1]; A     intLen =1; at      for(intI=2; i<=head; i++){ -         if(A[i] >= D[len]) D[++len] =A[i]; -         Else{ -             intj = Upper_bound (d+1, d+len+1, A[i])-D; -D[J] =A[i]; -         } in     } -printf"%d\n", head-len+ans); to      +     return 0; -}

51Nod 1294 Modifying an array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.