D. Boboniu Chats with Du Codeforces Round #664 (Div. 2)
阿新 • • 發佈:2020-08-13
Boboniu Chats with Du
題意
給你天數n,禁言時間d,上界m,再給你n個笑話,每個笑話有個搞笑值a,當a大於m時候,會被禁言,每天可以講一個笑話,問怎麼樣可以使得搞笑值最大。
思路
根據有沒有大於m,把笑話分為倆類,然後分別從大到小排序,給不會禁言的那組求個字首。然後貪心的思路,考慮獲得儘可能多的收益,選擇字首的長度(也就是天數),然後把剩下的天數全部用去會被沉默的天數。
考慮下特殊情況,就應為沒想到wa24了,那就是全部選擇會被沉默的天數,最後max一下就可以了。
如果沒有大於m等,把所有的a加起來輸出就可以了.
語文不好,qwq,再看下程式碼理解理解
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <map> #include <stack> #include <queue> #include <vector> #include <bitset> #include <set> #include <utility> #define mem(a,b) memset(a,b,sizeof(a)) #define inf 0x3f3f3f3f #define IO ios::sync_with_stdio(false); #define ll long long #define pb push_back using namespace std; const int N=2e6+10; const ll mod=1e9+7; ll n,d,m; ll a[N]; vector<ll>tmp; vector<ll>tmpp; bool cmp(ll a,ll b) { return a>b; } void sovle() { cin>>n>>d>>m; for(int i=1; i<=n; i++) { cin>>a[i]; if(a[i]<=m) tmp.pb(a[i]); else { tmpp.pb(a[i]); } } ll ans=0; if(tmpp.size()<1) { for(int i=0; i<n; i++) ans+=tmp[i]; cout<<ans<<endl; return; } sort(tmpp.begin(),tmpp.end(),cmp); int l=0; int day=n; while(day>0) { ans+=tmpp[l]; day-=(d+1); l++; if(l>=tmpp.size()) break; } sort(tmp.begin(),tmp.end(),cmp); for(int i=1; i<tmp.size(); i++) { tmp[i]+=tmp[i-1]; } for(int i=0; i<tmp.size(); i++) { ll sum=tmp[i]; ll day=n-(i+1); ll l=0; while(day>0) { sum+=tmpp[l]; day-=(d+1); l++; if(l>=tmpp.size()) break; } ans=max(sum,ans); } cout<<ans<<endl; } int main() { // int t; // cin>>t; // while(t--) // { sovle(); // } return 0; }