1612E - Messages - CodeForces Solution


brute force dp greedy probabilities sortings *2000

Please click on ads to support us..

C++ Code:

// careful not to get high! cuz my stuff is dope
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define vi  vector<int>
#define vc  vector<char>
#define vll vector<ll>
#define vb vector<bool>
#define vp vector<pair<int,int>>
#define all(v) (v).begin()+1,(v).end()
#define pi  pair<int,int>
#define mpi  map<int,int>
#define edl '\n'
#define pyes cout<<"YES\n";
#define pno  cout<<"NO\n";
#define pb(x) push_back(x)
#define fr(i,s,e)  for(ll i = (ll)s; i < (ll)e; i++)
#define rfr(i,s,e) for(ll i = (ll)e; i >= (ll)s; i--)
#define fa(x,a) for(auto x: a)
#define read(a) for(auto &x: a) cin >> x;
#define put(a) for(auto &x: a) cout << x << " "; cout << nl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define files freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...)
#endif

#define int long long
template <typename C> void UNIQUE(vector<C> &v) { sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


void solve(){
    int n;cin>>n;
    ll num=232792560;
    vector<vp>contri(21,vp(200001,{0,0}));
    fr(i,1,21) fr(j,1,200000)contri[i][j].second = j;
    fr(i,0,n){
        int m,k;cin>>m>>k;
        fr(j,1,k+1)contri[j][m].first+=num;
        fr(j,k + 1,21)contri[j][m].first+=(num/j)*k;
    }
    int ans=-1,ind=-1;
    fr(i,1,21){
        sort(all(contri[i]));
        reverse(all(contri[i]));
        ll curr=0;
        fr(j,1,i+1)curr += contri[i][j].first;
        if(curr>=ans){
            ans = curr;
            ind = i;
        }
    }
    cout<<ind<<"\n";
    fr(j,1,ind+1)cout<<contri[ind][j].second<<" ";
    cout << "\n";
}

signed main(){
    fast;

    int tt=1;
    while(tt--){
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram
60. Permutation Sequence
42. Trapping Rain Water
32. Longest Valid Parentheses
Cutting a material
Bubble Sort
Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret