日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

牛客第四次多校Maximum Mode

發布時間:2025/5/22 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 牛客第四次多校Maximum Mode 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

鏈接:https://www.nowcoder.com/acm/contest/142/G
來源:??途W

題目描述

The mode of an integer sequence is the value that appears most often. Chiaki has n integers a1,a2,...,an. She woud like to delete exactly m of them such that: the rest integers have only one mode and the mode is maximum.

輸入描述:

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:
The first line contains two integers n and m (1 ≤ n ≤ 10^5, 0 ≤ m < n) -- the length of the sequence and the number of integers to delete. The second line contains n integers a1,a2, ..., an(1 ≤ ai ≤ 10^9)denoting the sequence.It is guaranteed that the sum of all n does not exceed 10^6

輸出描述:

For each test case, output an integer denoting the only maximum mode, or -1 if Chiaki cannot achieve it. 示例1

輸入


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

輸出

-1 3 3 3 4 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int MAXN=1e5+10; 4 int a[MAXN]; 5 map<int, int>ma; 6 map<int ,int>mb; 7 int sum[MAXN],cnt[MAXN]; 8 int main() 9 { 10 int _; 11 scanf("%d",&_); 12 while(_--) 13 { 14 ma.clear(); 15 int n,m; 16 scanf("%d%d",&n,&m); 17 for(int i=1;i<=n;i++) 18 { 19 scanf("%d",&a[i]); 20 ma[a[i]]++; 21 sum[i]=0; 22 cnt[i]=0; 23 } 24 for(auto &i:ma) cnt[i.second]++; 25 for (int i = n-1; i ; i--) { //求出后綴和 26 cnt[i]+=cnt[i+1]; 27 sum[i]=sum[i+1]+cnt[i];//從后向前進行,如果一個數出現n次,在向前加的過程中就會加n次。保證后綴和正確 28 } 29 int MAX=-1; 30 for(auto &i:ma){ 31 if(sum[i.second]-1<=m) MAX=max(MAX,i.first);//枚舉答案,-1是因為只要保證當前這個眾數比其他的多一即可 32 } 33 printf("%d\n",MAX); 34 } 35 return 0; 36 }

?

?

轉載于:https://www.cnblogs.com/-xiangyang/p/9383562.html

總結

以上是生活随笔為你收集整理的牛客第四次多校Maximum Mode的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。