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 DescriptionDunton 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:
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 formatRead 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 formatoutput to standard output. Output an integer, which represents the minimum time-consuming to cultivate n areas. Sample input 1
Sample output 1
sample explanationAs 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.
Sample input 2
Sample output 2
sample explanationInvesting 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. Subtasks70% 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: