Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend 贪心
2016-10-03 15:41
585 查看
C. Sonya and Problem Wihtout a Legend
题目连接:
http://codeforces.com/contest/713/problem/CDescription
Sonya was unable to think of a story for this problem, so here comes the formal description.You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array.Next line contains n integer ai (1 ≤ ai ≤ 109).
Output
Print the minimum number of operation required to make the array strictly increasing.Sample Input
72 1 5 11 5 9 11
Sample Output
9Hint
题意
给你一个长度为n个序列,然后你每次操作可以使得一个数减小一,或者使得一个数增加一,问你最少多少次操作,可以使得这个序列为单增的。题解:
我们让每一个数,一开始-=i,然后就可以把单增变成不降序列了。这下我们就可以贪心了,扔到一个堆里面去,每次拿出最大的元素,变成x就好了
代码
#include<bits/stdc++.h> using namespace std; int n; long long ans; priority_queue<int>s; int main() { scanf("%d",&n); for(int i=0;i<n;i++) { int x;scanf("%d",&x); x-=i; s.push(x); if(s.top()>x) { ans+=s.top()-x; s.pop(); s.push(x); } } cout<<ans<<endl; }
相关文章推荐
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend(贪心+DP)
- Codeforces Round #371 (Div. 2) E. Sonya and Problem Wihtout a Legend (DP/LIS变形)
- Codeforces Round #371 (Div. 1) C. Sonya and Problem Wihtout a Legend
- cf 372 div2 E. Sonya and Problem Wihtout a Legend dp
- Codeforces Round #371 (Div. 2)E. Sonya and Problem Wihtout a Legend[DP 离散化 LIS相关]
- Codeforces Round #371 (Div. 2) E. Sonya and Problem Wihtout a Legend(技巧 + 离散化dp)
- [堆与斜率] Codeforces 713C - Sonya and Problem Wihtout a Legend
- Codeforces 713 C Sonya and Problem Wihtout a Legend
- 动态规划,离散化(Sonya and Problem Wihtout a Legend,cf 713C)
- Codeforces Round 371 C Sonya and Problem Wihtout a Legend
- hihocoder#1529 : 不上升序列&&Codeforces-713C:Sonya and Problem Wihtout a Legend(思维)
- 【CF 713C】Sonya and Problem Wihtout a Legend(离散化+dp)<POJ 3666变形>
- Codeforces Round #371 C. Sonya and Problem Wihtout a Legend (DP)
- cf 714 e Sonya and Problem Wihtout a Legend
- cf/Codeforces Round #371 714E - Sonya and Problem Wihtout a Legend - dp +lis
- 【CodeForces】713 C. Sonya and Problem Wihtout a Legend
- 【CF713C】Sonya and Problem Wihtout a Legend(离散化,DP)
- 【DP】[CodeForces - 713C]Sonya and Problem Wihtout a Legend
- Codeforces 713C C. Sonya and Problem Wihtout a Legend (经典DP)
- codeforces 713C C. Sonya and Problem Wihtout a Legend(dp)(将一个数组变成严格单增数组的最少步骤)