Start Time:2016-08-20 13:00:00 End Time:2016-08-20 18:00:00 Refresh Time:2017-11-12 19:51:52 Public
Time Limit:2s Memory Limit:64MByte
Submissions:394Solved:119
Eric has an array of integers a1,a2,...,ana1,a2,...,an. Every time, he can choose a contiguous subsequence of length kk and increase every integer in the contiguous subsequence by 11.
He wants the minimum value of the array is at least mm. Help him find the minimum number of operations needed.
#include <bits/stdc++.h> using namespace std; int a[1000000+10]; int main() { int t,n,m,k; cin>>t; while(t--) { cin>>n>>m>>k; for(int i=0;i<n;i++) { cin>>a[i]; } int ans=0; int tmp; for(int i=0;i<n;i++) { if(a[i]<m) { tmp=m-a[i]; ans+=tmp; for(int j=i;j<i+k;j++) //连续长度k内元素都加上差值 { a[j]+=tmp; } } } printf("%d\n",ans); } return 0; }