Continue to answer questions, you can’t make any more mistakes! !
The main idea of the question:
Requires t hours of study in n days, Give the minimum and maximum time you can study each day. Ask if it can be implemented and if the timetable can be output.
Solution ideas:
A simple question, guaranteed to be greedy directly within the range.
Here is the code:
#include <set>#include <map>#include <queue>#include <math.h>#include <vector>#include <string>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <cctype>#include <algorithm>#define eps 1e-10#define pi acos(-1.0)#define inf 107374182#define inf64 1152921504606846976#define lc l,m,tr<<1#define rc m + 1,r,tr<<1|1#define zero(a) fabs(a)<eps#define iabs(x) ((x) > 0 ? (x) : -(x))#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))#define clearall(A, X) memset(A, X, sizeof(A))#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))#define memcopyall(A, X) memcpy(A , X ,sizeof(X))#define max( x, y ) ( ((x) > (y)) ? (x) : (y) )#define min( x, y ) ( ((x) < (y)) ? (x) : (y) )using namespace std;struct node{ int min1,max1;}da[35];int main(){ int d,t,uplim=0,downlim=0; scanf("%d%d",&d,&t); for(int i=0;i<d;i++) { scanf("%d%d",&da[i].min1,&da[i].max1); downlim+=da[i].min1; uplim+=da[i].max1; } if(uplim<t||downlim>t) { puts("NO"); } else { puts("YES"); t-=downlim; for(int i=0;i<d;i++) { if(t>=da[i].max1-da[i].min1) { printf("%d ",da[i].max1); t-=da[i].max1-da[i].min1; } else if(t==0) { printf("%d ",da[i].min1); } else if(t<da[i].max1-da[i].min1) { printf("%d ",t+da[i].min1); t=0; } } } return 0;}