Portal @ Baidu ..
Background
Orz4-3 (jump)
Description
The lhx teacher is very capable of jumping because there are too many orz members. It consumes 1 point of energy for the instructor to jump. If the instructor has a lot of energy, it can jump very high.
In order to collect energy, the teacher came to a mysterious place where mortals could not enter. Here, there is an energy ball at the top of the instructor every 100 meters (that is, these energy balls are at an altitude of 100,200,300 ...... In meters), each energy ball can provide different energy, a total of N energy balls (that is, the last energy ball in n × 100 meters ). In order to collect the energy, the instructors want to skip and finish all the energy balls. The instructor can freely control the height of each hop. Then, when he jumps up and eats all the energy balls below the height, he can get the energy in the ball, and then the energy ball he eats will be lost. The instructor will not be light-performing, and the instructor will not skip the second hop. Therefore, the instructor cannot change the height of this hop because of the new energy. The instructors still live on the earth, so the instructors will fall down after each hop.
Ask the instructors how much energy they can retain if they want to finish all their energy balls.
Format input format
The first row contains twoPositive IntegerN, m, indicates the number of energy balls and the initial energy of the lhx instructors.
The first row contains NNon-negative integerThe number I from left to right describes the energy contained in the energy ball at the I × 100 meters position from bottom to top. integers are separated by spaces.
Output Format
Only oneNon-negative integerThe maximum amount of energy retained by the instructors after all the energy balls.
Example 1 input 1 [copy]
3 200200 200 200
Sample output 1 [copy]
400
Restrictions
For 10% of the data, n ≤ 10;
For 20% of data, n ≤ 100;
For 40% of data, n ≤ 1000;
For 70% of data, n ≤ 100000;
For 100% of data, n ≤ 2000000.
Ensure that the instructor can eat all the energy balls for all data, and the sum of energy contained in the energy balls cannot exceed 2 ^ 31-1.
The time limit is 1 s.
Prompt
1st million hops, 100 of the energy, and 200 of the energy consumed. Therefore, 100 of the energy is generated after the project is launched.
2nd million jumps, 300 million meters, and the remaining 3rd Energy balls consume 300 of your energy and get 400 energy.
If 1st hops are 200 meters, 2nd hops are 300 meters, and the remaining 300 energy is exceeded.
I haven't done any questions these days .. I feel that the status is really not more funny.
Bare question of monotonous queue
#include<set>#include<queue>#include<vector>#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int N = 2000010;#define Rep(i,n) for(int i=1;i<=n;i++)#define For(i,l,r) for(int i=l;i<=r;i++)int A[N],sum[N],n,m,q[N],dp[N];int main(){ scanf("%d%d",&n,&m); Rep(i,n){ scanf("%d",&A[i]); sum[i]+=sum[i-1]+A[i]; } dp[0]=m; int Left=0,Right=0; Rep(i,n){ while(Left<Right&&dp[i-1]-sum[i-1]>dp[q[Right-1]]-sum[q[Right-1]]) Right--; q[Right++]=i-1; dp[i]=dp[q[Left]]+sum[i]-sum[q[Left]]-i*100; while(Left<Right&&dp[q[Left]]-(i+1)*100<0) Left++; } printf("%d\n",dp[n]); return 0;}
Vijos1617 super instructor