首页 > 试题广场 >

寻找大富翁

[编程题]寻找大富翁
  • 热度指数:6124 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
    浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁.

输入描述:
    每个用例首先包含2个整数n(0<n<=100000)和m(0<m<=10),其中: n为镇上的人数,m为需要找出的大富翁数, 接下来一行输入镇上n个人的财富值.


输出描述:
    请输出乌镇前m个大富翁的财产数,财产多的排前面,如果大富翁不足m个,则全部输出,每组输出占一行.
示例1

输入

3 1
2 5 -1
5 3
1 2 3 4 5
0 0

输出

5
5 4 3
头像 在做毕设的鲸鱼很刻苦
发表于 2023-03-06 00:07:02
#include <iostream> #include <algorithm> using namespace std; int wealth[100000 + 1]; bool cmp(int a, int b) { return a > b; } int 展开全文
头像 烤肉__
发表于 2022-01-24 17:13:22
这题主要就是考个排序。用库函数就没意思了,这里给个简洁的快排模板。 #include <iostream> #include <algorithm> using namespace std; const int N = 1e5 + 10; int a[N]; int n, 展开全文
头像 用户抉择
发表于 2021-03-29 10:32:46
#include <stdio.h> int cmp(const void *a,const void *b) {     return *((int *)b)-*(( 展开全文
头像 MountainsHao
发表于 2024-03-31 21:20:04
#include <stdio.h> #include <stdlib.h> int cmp(const void* a, const void* b) { return *((int*)b) - *((int*)a); } int main() { in 展开全文
头像 Luka_2001
发表于 2024-03-02 11:51:51
#include <iostream> #include<queue> using namespace std; int main() { int n,m; while(cin>>n>>m){ if(!n && 展开全文
头像 给我就亿下
发表于 2023-03-19 14:50:53
#include <iostream> #include <algorithm> using namespace std; bool cmp (int x, int y){ return x > y; } int main () { int n, m; wh 展开全文
头像 路人萌Miranda
发表于 2022-03-16 14:35:25
#include <cstdio> #include <algorithm> #include <cstring> using namespace std; int main() { int n, m; while ((scanf("%d%d", & 展开全文
头像 lyw菌
发表于 2023-03-27 21:48:45
//采用优先队列,底层原理是大根堆 #include "stdio.h" #include "queue" using namespace std; int main(){ int n,m;//n为镇上人数,m为要找的大富翁数 priority_queue<int> m 展开全文
头像 chong_0428
发表于 2024-03-26 20:57:57
def quick_sort(a, l, r): if l >= r: return a first = l last = r m = a[l] while first < last: if first < 展开全文
头像 粉詹眉
发表于 2024-03-07 18:01:49
#include <iostream> #include <algorithm> using namespace std; const int N = 100010; int a[N]; int main() { int n, m; while (cin & 展开全文