CodeForces 545 DQueue (sorting simulation)
[General idea ]:
There are n people, and each person has a waiting time. If the total waiting time for the current person exceeds the waiting time, the person will be disappointed and ask in another order, the minimum number of people who are disappointed is asked.
[Idea]: sort the order, add it, and compare it with the current one. So ..
Code:
/** Problem: CodeForces 545D * Running time: 46 MS * Complier: G ++ * Author: herongwei * Create Time: Thursday */# include
# Include
# Include
# Include using namespace std; const int N = 1e5 + 10; int arr [N]; int main () {int t; scanf (% d, & t ); for (int I = 1; I <= t; ++ I) {scanf (% d, & arr [I]);} sort (arr + 1, arr + 1 + t); int ans = 1; int temp = arr [1]; for (int I = 2; I <= t; ++ I) {if (arr [I]> = temp) {ans ++; temp + = arr [I] ;}} printf (% d, ans );}