CCF-CSP Zhenti "202303-2 Land Cultivation Plan" ideas + python, c++ full score solution

Students who want to check the real questions and solutions of other questions can go to: CCF-CSP real questions with solutions


Question No.: 202303-2
Question name: Cultivation plan
time limit: 1.0s
Memory limit: 512.0MB
Problem Description:

Problem Description

Dunton selected a total of n areas to prepare for land reclamation. Since the sizes of each area are different, the time required for reclamation is also different. It is estimated that the reclamation time of the i-th block (1≤i≤n) is ti days. These n areas can be reclaimed at the same time, so the total time tTotal depends on the area with the longest time, that is: tTotal=max{t1,t2,⋯,tn}

In order to speed up the reclamation progress, Dunton plans to invest additional resources in some areas to shorten the reclamation time. Specifically:

  • For every ci unit of resources invested in the i-th area , the time spent on its reclamation can be shortened by 1 day;

  • The number of time-consuming and shortened days is recorded as an integer, that is, the amount of resources invested in the i-th area must be an integer multiple of ci;

  • A maximum of ci×(ti−k) units of resources can be invested in the i-th area, shortening its reclamation time to k days;

  • Here k represents the minimum number of days for reclaiming an area, satisfying 0<k≤min{t1,t2,⋯,tn}; in other words, if unlimited resources are invested, all areas can be reclaimed in k days.

Now Dunton has a total of m units of resources available for use. Try to calculate how many days it takes at least to reclaim n areas?

input format

Read data from standard input.

Enter a total of n+1 lines.

The first line of input contains three positive integers n, m, and k separated by spaces, respectively representing the total number of areas to be cultivated, the number of resources in Dundun's hand, and the minimum number of days for each area to be cultivated.

In the next n lines, each line contains two positive integers ti and ci separated by spaces, which respectively represent the time spent on reclamation of the i-th area and the amount of resources required to shorten the time-consuming by 1 day.

output format

output to standard output.

Output an integer, which represents the minimum time-consuming to cultivate n areas.

Sample input 1

4 9 2
6 1
5 1
6 2
7 1

Sample output 1

5

sample explanation

As shown in the table below, investing 5 resources reduces the total time to 5 days. At this time, Dun Dun still has 4 units of resources left in his hands, but no matter how he arranges it, the total time-consuming cannot be further shortened.

i Basic time-consuming ti Reduced resources required by 1 day ci The amount of resources invested Actual time consuming
1 6 1 1 5
2 5 1 0 5
3 6 2 2 5
4 7 1 2 5

Sample input 2

4 30 2
6 1
5 1
6 2
7 1

Sample output 2

2

sample explanation

Investing 20 units of resources can just shorten the reclamation time of all areas to k=2 days; limited by k, the remaining 10 units of resources cannot further shorten the time-consuming.

Subtasks

70% of the test data satisfy: 0<n,ti,ci≤100 and 0<m≤106;

All test data satisfy: 0<n,ti,ci≤105 and 0<m≤109.

Source of real question: matrix operation

 Interested students can code in this way for practice submission

Ideas explained:

This question is not difficult. Use the flag array to record the time-consuming area of ​​i days to reduce the total cost of one day, and then decrease from high to low, and finally you can get the answer.

C++ full score solution:

#include<bits/stdc++.h>
#include<iostream>
using namespace std;

int n, k;
long long int m;
map<int, int>tim, res, flag;

int main(){
    cin >> n >> m >> k;

    int max = 0;
    for(int i = 0; i < n; ++i){
        cin >> tim[i] >> res[i];
        max = max > tim[i] ? max : tim[i];
        flag[tim[i]] += res[i];     
        // flag[i]为用时i天的区域缩短一天所用时
    }
    for(int i = max; i > 0; i--){
        //cout << i << " " << flag[i] << endl;
        if(max == k)break;
        if(m > flag[i]){
            m = m - flag[i];
            flag[i - 1] += flag[i];
            max--;
        }else break;
    }
    cout << max;
    return 0;
}

 operation result:

Guess you like

Origin blog.csdn.net/weixin_53919192/article/details/131490410