ACM (Association for Computing Machinery) organizes the International Collegiate Programming Contest (ICPC) worldwide every year.

In the ICPC, a team of three students is presented with a problem set that contains N! possible problem solving orders that the team wants to use. This is called the “contest strategy” and teams who are expecting to do well in an ICPC should use the optimal contest strategy for their team.

However, when a contest has ‘First to Solve Problem [‘A’/‘B’/.../‘A’+(N−1)] award’ – like this ICPC SG Regional Contest 15 – sponsored by Kattis, then some of the teams may throw the optimal contest strategy out of the window in order to grab the (smaller) award.

Input

The input describes a hypothetical scenario of a 300 minute contest.

The first line contains two non-negative integers N−1 problems.

The next line contains i according to your team. You have discussed with your team mates that your team will not put the same estimation for two different problems, so there is no ambiguity.

As an ACM ICPC duration is j during contest time.

In this problem, you can assume that all your team’s estimations are perfectly accurate, i.e. if your team estimates that your team needs 30+300=330 minutes as per the ICPC rules.

Output

Print two integers Penalty_Time separated by a single space in one line.

N−1 problems.

For the example scenario above, if your team decides to solve problem 270+300=570 minutes.

Sample Input 1 Sample Output 1
7 0
30 270 995 996 997 998 999
2 330
Sample Input 2 Sample Output 2
7 1
30 270 995 996 997 998 999
2 570
Sample Input 3 Sample Output 3
7 2
30 270 995 996 997 998 999
0 0
Sample Input 4 Sample Output 4
3 0
1 300 299
2 301

Footnotes

  1. N=13.
  2. 299) in order to be considered valid.

题意

解释一下样例,输入n,p,n代表总题数,p代表第一个开始做第p题(位置从0开始),后面输入的是每一道题至少需要的时间,做了第一题后,选择最少需要的时间加上累积的时间<=300的话就是可做的,因为一道题的限制时间是300,问做出来的总题数和总时间。

思路

首先判断a[p]是否<=300,然后把a[0]与a[p]替换,将数组排序,先存下做出每一题的总时间,然后遍历判断

代码

#include<bits/stdc++.h>
using namespace std;
int main() {
    int n, p;
    while(cin >> n >> p) {
        int a[n];
        int nn = 0, pp = 0, cnt = 0;
        for(int i = 0; i < n; i++)
            cin >> a[i];
        if(a[p] <= 300) {
            int tmp = a[0];
            a[0]=a[p];
            a[p]=tmp;
            sort(a+1, a + n);
            for(int i=1;i<n;i++){
                a[i]+=a[i-1];
            }
            for(int i = 0; i < n; i++) {
                if(a[i] <= 300) {
                    pp += a[i];
                    cnt++;
                } else if(a[i] > 300)
                    break;
            }
        }
        cout << cnt << " " << pp << endl;
    }
}

 

相关文章:

  • 2021-12-04
  • 2021-10-16
  • 2021-08-21
  • 2021-06-16
  • 2021-08-12
  • 2021-09-22
  • 2022-01-28
  • 2021-06-14
猜你喜欢
  • 2022-01-16
  • 2022-12-23
  • 2021-09-24
  • 2022-02-08
  • 2021-12-09
  • 2022-12-23
  • 2021-08-21
相关资源
相似解决方案