Http://codeforces.com/contest/887/problem/D
A model has two kinds of activities.
① take pictures and make money A. ② a concert and spends B
a schedule for both types of work for a given model. The
model can choose a time to hold a symposium, then his photo is changed to C. It will cost D to start a concert. The
requires no loss of money before and after the Model Symposium. Requires you to output the smallest number of symposium days. No output-1.
Idea: Enumerate the first day as the time of the Tea Party (the Tea party can be hit with other events of the day and have an impact on that day) and then calculate whether there are negative numbers after Len Day.
T anymore.
The correct wording is similar to the ruler, maintain the prefix of the normal number of days and recalculate the I activity for the initial, (I activity has been affected as early as possible, so the time again I-
an activity next day to hold the Tea Party), length asked Len for the special days of the Tea party. The green part of the
is the time that the Tea Party was held, I was the first number of days affected. The red section is Len. A lot of the code on CF has an effect on the number of days I start with, and I'm puzzled that
is the proof of some big guy. Or the data is not stuck.
#include <bits/stdc++.h> using namespace std;
/* Originally wanted to write a preliminary idea time to change again.
The results of the primary idea WA a day.
Similar to the ruler, the problem has the following directions I did not consider.
That is ① hold talkshow time is immediately, can coincide with other time ② if I as the beginning, then start talkshow the shortest time can be node[i-1]+1.
③ If you calculate with I, if not feasible, then continue to calculate from the i+1, the TM is certainly not feasible.
This TM is almost as N2 as a matching string. The best way to do this is to double pointer maintenance prefix and (small name ruler fetch). Method.
When I is opening, maintain a prefix and.
When not available, subtract the prefix of the first part and (in this question is the replacement CD for AB)/typedef long LL;
const int MAXN=3E5; struct{ll Kin,cos;}
NODE[MAXN];
int n;
ll A,b,c,d,lim,sta;
int main () {while (~scanf ("%d%lld%lld%lld%lld%lld%lld", &n,&a,&b,&c,&d,&sta,&lim)) {
for (int i=0;i<n;i++) {scanf ("%lld%d", &node[i].cos,&node[i].kin);
ll Mn=1e17;
ll Ans=sta;
ll Sum2=0;
int now=0;
BOOL Flag=false;
int KK;
for (int i=0;i<n;i++) {ll TT;
if (i==0) tt=0; else tt=node[i-1].cos+1;//The date the Tea Party begins when the first is affected by the I activity (now<n&& node[now].cOS-TT) <lim) {if (node[now].kin==0) Sum2-=d;
else sum2+=c;
Mn=min (SUM2,MN);
now++;
} if (mn+ans>=0) {flag=true;
Kk=i;
if (kk==0) printf ("0\n");
else printf ("%lld\n", node[kk-1].cos+1); Break
} if (node[i].kin==1) {mn-=c;
Sum2-=c;
Ans+=a;
else {mn+=d;
Sum2+=d;
Ans-=b;
} if (ans<0) {puts ("-1");
Flag=true;
Break
} if (!flag) printf ("%lld\n", node[n-1].cos+1);
return 0; }