Submission #1198300

#TimeUsernameProblemLanguageResultExecution timeMemory
11983004o2aK blocks (IZhO14_blocks)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define _F "test"
using namespace std;
typedef long long ll;

void solve()
{
    int n, k; cin>>n>>k;
    vector<int> val(n);
    for (int i = 0; i < n; ++i)
        cin>>val[i];
    sort(val.begin(), val.end());
    int s = n-1;
    while (s >= 0 && val[s] == val[n-1]) --s;
    ll ans = (n-s-1)*val[n-1];
    for (int i = 0; i < k - (n-s-1); ++i)
        ans += val[i];
    cout<<ans;
}

int main()
{
    if (fopen(_F".INP", "r"))
    {
        freopen(_F".INP", "r", stdin);
        //freopen(_F".OUT", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int Test = 1; //cin>>Test;
    while (Test--) solve();
}

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(_F".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...