Submission #37191709


Source Code Expand

/*

⣿⣯⣿⣟⣟⡼⣿⡼⡿⣷⣿⣿⣿⠽⡟⢋⣿⣿⠘⣼⣷⡟⠻⡿⣷⡼⣝⡿⡾⣿
⣿⣿⣿⣿⢁⣵⡇⡟⠀⣿⣿⣿⠇⠀⡇⣴⣿⣿⣧⣿⣿⡇⠀⢣⣿⣷⣀⡏⢻⣿
⣿⣿⠿⣿⣿⣿⠷⠁⠀⠛⠛⠋⠀⠂⠹⠿⠿⠿⠿⠿⠉⠁⠀⠘⠛⠛⠛⠃⢸⣯
⣿⡇⠀⣄⣀⣀⣈⣁⠈⠉⠃⠀⠀⠀⠀⠀⠀⠀⠀⠠⠎⠈⠀⣀⣁⣀⣀⡠⠈⠉
⣿⣯⣽⡿⢟⡿⠿⠛⠛⠿⣶⣄⠀⠀⠀⠀⠀⠀⠈⢠⣴⣾⠛⠛⠿⠻⠛⠿⣷⣶
⣿⣿⣿⠀⠀⠀⣿⡿⣶⣿⣫⠉⠀⠀⠀⠀⠀⠀⠀⠈⠰⣿⠿⠾⣿⡇⠀⠀⢺⣿
⣿⣿⠻⡀⠀⠀⠙⠏⠒⡻⠃⠀⠀⠀⠀⣀⠀⠀⠀⠀⠀⠐⡓⢚⠟⠁⠀⠀⡾⢫
⣿⣿⠀⠀⡀⠀⠀⡈⣉⡀⡠⣐⣅⣽⣺⣿⣯⡡⣴⣴⣔⣠⣀⣀⡀⢀⡀⡀⠀⣸
⣿⣿⣷⣿⣟⣿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢻⢾⣷⣿
⣿⣿⣟⠫⡾⠟⠫⢾⠯⡻⢟⡽⢶⢿⣿⣿⡛⠕⠎⠻⠝⠪⢖⠝⠟⢫⠾⠜⢿⣿
⣿⣿⣿⠉⠀⠀⠀⠀⠈⠀⠀⠀⠀⣰⣋⣀⣈⣢⠀⠀⠀⠀⠀⠀⠀⠀⠀⣐⢸⣿
⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⣿⣿⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⢀⣾⣿
⣿⣿⣿⣿⣦⡔⠀⠀⠀⠀⠀⠀⢻⣿⡿⣿⣿⢽⣿⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿
⣿⣿⣿⣿⣿⣿⣶⣤⣀⠀⠀⠀⠘⠛⢅⣙⣙⠿⠉⠀⠀⠀⢀⣠⣴⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⣄⣅⠀⠓⠀⠀⣀⣠⣴⣺⣿⣿⣿⣿⣿⣿⣿⣿

*/
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 200020
#define pi 3.141592653589793238462
#define r(n) ll n; cin >> n;
#define s(n) string n; cin >> n;
#define mp(i, j) make_pair(i, j)
#define pb(i) push_back(i)
#define pl pair<ll,ll>
#define f(i, s, e, inc) for(ll i = s; i < e; i+=inc) 
#define fd(i, s, e, dec) for(ll i = s; i >= e; i-=dec)
#define p(x) cout << x << '\n'
//#define MOD 1000000007
#define MOD 998244353 
#define tf(x) if(x) cout << "Yes" << '\n'; else cout << "No" << '\n';
#define L 20
/*  cout << fixed << setprecision(10);  */

void readArr(ll arr[], ll size)
{ for(ll i = 0; i < size; i++) cin >> arr[i]; }
 
void printArray(ll arr[], ll size)
{ for(ll i = 0; i < size; i++) { cout << arr[i] << " "; } cout << '\n'; }
 
void printVector(vector<ll>& v)
{ for(ll i = 0; i < v.size(); i++) cout << v[i] << " "; cout << '\n'; }
 
void printSet(set<ll>& s)
{ for(auto ptr = s.begin(); ptr!=s.end(); ptr++) cout << (*ptr) << " "; cout << '\n'; }
 
void printMap(map<ll,ll>& mp)
{ for(auto it: mp) cout << it.first << " " << it.second << '\n'; cout << '\n'; }

void solve()
{   
    ll n, m, k; cin >> n >> m >> k; 
    ll a[n]; readArr(a, n);  multiset<pl> ms;
    multiset<pl> current;
    vector<bool> used(n, false);
    f(i, 0, m, 1){
        ms.insert(mp(a[i], i));
    }
    ll sum = 0; ll need = k;
    while(need--){
        pl curr = *ms.begin();
        ms.erase(ms.begin());
        sum+=curr.first;
        used[curr.second] = true;
        current.insert(curr);
    }
    ll prevIdx = 0; cout << sum << " ";
    f(i, m, n, 1){
        ms.insert(mp(a[i], i));
        while(ms.size()>0 && (*ms.begin()).second<=prevIdx) {ms.erase(ms.begin());}
        //for(auto it: ms) cout << it.first << " " << it.second << " ";
        //cout << '\n';
        if(used[prevIdx]){
            current.erase(current.find(mp(a[prevIdx], prevIdx)));
            pl nextBest = *ms.begin();
            ms.erase(ms.begin());
            current.insert(nextBest);
            sum-=a[prevIdx]; sum+=nextBest.first;
            used[prevIdx] = false; used[nextBest.second] = true;
        }
        else{
            ll bigboi = (*current.rbegin()).first;
            ll smallboi = (*ms.begin()).first;
            if(smallboi < bigboi){
                pl bigpair = *current.rbegin();
                pl smallpair = *ms.begin();
                used[bigpair.second] = false;
                used[smallpair.second] = true;
                sum-=bigboi; sum+=smallboi;
                current.erase(current.find(bigpair));
                ms.insert(bigpair);
                current.insert(smallpair);
                ms.erase(ms.find(smallpair));
            }
        }
        prevIdx++;
        cout << sum << " ";
    }
    cout << '\n';

} 

int main()
{
  //ios::sync_with_stdio(false);
      //cin.tie(NULL);
          ll sus = 1;
              //cin >> sus;
                 f(i, 0, sus, 1) 
                            solve();
}

Submission Info

Submission Time
Task E - Least Elements
User cleanser
Language C++ (GCC 9.2.1)
Score 500
Code Size 4576 Byte
Status AC
Exec Time 184 ms
Memory 17660 KiB

Compile Error

./Main.cpp: In function ‘void printVector(std::vector<long long int>&)’:
./Main.cpp:52:19: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   52 | { for(ll i = 0; i < v.size(); i++) cout << v[i] << " "; cout << '\n'; }
      |                 ~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 21
Set Name Test Cases
Sample 00_example_00.txt, 00_example_01.txt
All 00_example_00.txt, 00_example_01.txt, 01_max_00.txt, 01_max_01.txt, 02_min_00.txt, 03_m_small_00.txt, 04_random_00.txt, 04_random_01.txt, 04_random_02.txt, 04_random_03.txt, 04_random_04.txt, 04_random_05.txt, 04_random_06.txt, 04_random_07.txt, 04_random_08.txt, 04_random_09.txt, 04_random_10.txt, 04_random_11.txt, 04_random_12.txt, 04_random_13.txt, 04_random_14.txt
Case Name Status Exec Time Memory
00_example_00.txt AC 8 ms 3600 KiB
00_example_01.txt AC 2 ms 3492 KiB
01_max_00.txt AC 146 ms 17660 KiB
01_max_01.txt AC 184 ms 14416 KiB
02_min_00.txt AC 6 ms 3492 KiB
03_m_small_00.txt AC 91 ms 5080 KiB
04_random_00.txt AC 92 ms 10552 KiB
04_random_01.txt AC 138 ms 15744 KiB
04_random_02.txt AC 87 ms 9040 KiB
04_random_03.txt AC 136 ms 7356 KiB
04_random_04.txt AC 87 ms 12112 KiB
04_random_05.txt AC 113 ms 12484 KiB
04_random_06.txt AC 62 ms 8872 KiB
04_random_07.txt AC 156 ms 15856 KiB
04_random_08.txt AC 33 ms 5952 KiB
04_random_09.txt AC 17 ms 4472 KiB
04_random_10.txt AC 92 ms 11772 KiB
04_random_11.txt AC 57 ms 6824 KiB
04_random_12.txt AC 62 ms 5964 KiB
04_random_13.txt AC 66 ms 7484 KiB
04_random_14.txt AC 12 ms 3664 KiB