1394A - Boboniu Chats with Du - CodeForces Solution


dp greedy sortings two pointers *1800

Please click on ads to support us..

C++ Code:

//i_love_aisukiuwu
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
	#include "/home/trucmai/.vim/tools.h"
	#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
	#else
	#define debug(x...)
#endif

void open(){
  if(fopen("i.inp","r")){
    freopen("i.inp","r",stdin);
    freopen("o.out","w",stdout);
  }
}

#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "

const int MN1 = 1e6 + 5,MN2 = 1e4 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n,d,m,a[MN1];

void solve(){
  vector<ll> small = {0},large = {0};
  cin>>n>>d>>m;
  for(ll i = 1;i <= n;++i){
    cin>>a[i];
    if(a[i] <= m) small.push_back(a[i]);
    else large.push_back(a[i]);
  }
  sort(small.rbegin(),small.rend()-1); 
  sort(large.rbegin(),large.rend()-1);
  ll res = 0;
  partial_sum(all(small),small.begin());
  partial_sum(all(large),large.begin());
  for(ll i = 0;i < large.size();++i){
    ll take = (i ? (i-1)*d + i : 0),
       tmp = n - take; 
    if(tmp < 0) continue;
    res = max(res,large[i] + small[min(tmp,(ll)small.size()-1)]);
  } 
  cout<<res;
}

signed main(){
  cin.tie(0) -> sync_with_stdio(0);
  open();
  ll t = 1; //cin>>t;
  while(t--) solve(); 
  
  #ifdef LOCAL
    cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}


Comments

Submit
0 Comments
More Questions

262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream
1358D - The Best Vacation
1620B - Triangles on a Rectangle
999C - Alphabetic Removals
1634C - OKEA
1368C - Even Picture
1505F - Math
1473A - Replacing Elements
959A - Mahmoud and Ehab and the even-odd game
78B - Easter Eggs
1455B - Jumps
1225C - p-binary
1525D - Armchairs
1257A - Two Rival Students
1415A - Prison Break
1271A - Suits
259B - Little Elephant and Magic Square
1389A - LCM Problem
778A - String Game