/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 768.0 KiB
#2 Wrong Answer 20ms 496.0 KiB
#3 Wrong Answer 32ms 740.0 KiB

Code

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

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pi;
typedef pair<char, ll> pci;
typedef vector<pi> vii;
typedef map<ll, ll> mi;
typedef set<ll> seti;

#define sz size()
#define ins insert
#define mp make_pair
#define pb push_back
#define nl << "\n";
#define all(x) x.begin(), x.end()
#define db(x) cout << #x << " = " << x nl
#define input(x) for (auto &a : x) cin >> a;
#define view(x) cout << #x << ": "; for (auto a : x) {cout << a << " ";} cout nl
#define viewp(x) cout << #x << ": "; for (auto &a : x) {cout << a.first << " " << a.second nl}

void solve() {
    ll n, k;
    cin >> n >> k;
    vi a(n);
    input(a);
    ll minsum = 1e10, mini = n;
    for (ll i = 0; i <= n - k; i++) {
        ll sum = 0;
        for (ll j = i; j < i + k; j++) {
            sum += a[j];
        }
        if (sum < minsum) {
            minsum = sum;
            mini = i;
        }
    }
    vi newarr;
    for (int i = mini; i < mini + k; i++) {
        newarr.pb(a[i]);
    }
    ll newsum = accumulate(all(newarr), 0);
    vi newarr2 = newarr;
    vi c = a;
    sort(all(c));
    sort(all(newarr2));
    ll newmax = newarr2[k - 1];
    for (ll i = 0; i < n; i++) {
        if (find(all(newarr), c[i]) == newarr.end()) {
            ll newsum2 = newsum;
            newsum2 -= newmax;
            newsum2 += c[i];
            if (newsum2 < newsum) {
                newsum = newsum2;
            }
            break;
        }
    }
    cout << newsum nl
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 08:38:42
Judged At
2024-12-09 08:38:42
Judged By
Score
1
Total Time
32ms
Peak Memory
768.0 KiB