CF140D New Year Contest
The meaning of the question: a game asks you to solve the number of problems in the game time and the penalty time gives you a number n the number of problems, and the n numbers each problem corresponds to the time required to solve Then the game rule is that the game time is 18 o'clock Submit questions before 00:00 at 06:00 the next day, no penalty will be counted, and you need to analyze all questions in the first 10 minutes after the start of the game
problem analysis:
Simple greed. . . . The original title is really difficult to understand,,,,
sort it again, and solve as many problems as possible at 0:00.
I divided it into two parts before 0:00 and after 0:00.
Don't forget the first ten minutes after the start of the game. . .
Looking at the penalty time analyzed by others, it may be a negative number that needs to be the maximum value of 0.
This situation seems to be true (all are resolved before 0 points), but it seems that
it can be AC without this special judgment.
AC code:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<sstream>
#include<string.h>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
#define ll long long
#define lowbit(x) (x)&(-x)
#define mem(a,b) memset((a),(b),sizeof(a));
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
const ll inf=0x3f3f3f3f;//1061109567,2*未超int,allinf=mem(a,0x3f,sizeof(a));
typedef pair<int ,int > PII;
const int nn=1e6+10;
int a[nn],mx=0,n;
void slove(){
int ans=0;
int cnt=0;
sort(a,a+n);
int x=6*60;
int xx=10;
forn(i,n){
xx+=a[i];
if(xx<=x){
ans++;
}else break;
}
xx-=a[ans];
// cout<<ans<<endl;
forr(i,ans,n-1){
if(xx+a[i]<=720){
xx+=a[i];
ans++;
// cout<<ans<<endl;
cnt+=xx-360;
} else break;
}
cout<<ans<<" "<<max(cnt,0)<<endl;
}
int main()
{
//#define io
#ifdef io
freopen("in.txt","r",stdin);
#endif
int t;
cin>>n;
forn(i,n) cin>>a[i];
slove();
return 0;
}