/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 332.0 KiB
#2 Wrong Answer 24ms 568.0 KiB
#3 Wrong Answer 33ms 600.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define Endl '\n'
#define endl '\n'
#define nl '\n'
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define cinall(v)        \
    for (auto &&itt : v) \
    cin >> itt
#define coutall(v)       \
    for (auto &&itt : v) \
    cout << itt << ' '
using namespace std;

// vector<int> primes;
// bool is_prime[(int)1e7 + 10];
// seive here
// void seive()
// {
//     is_prime[0] = is_prime[1] = 1;
//     for (int i = 4; i <= 1e7 + 10; i += 2)
//     {
//         is_prime[i] = 1;
//     }
//     for (int i = 3; i * i <= 1e7 + 10; i += 2)
//     {
//         if (is_prime[i] == 0)
//         {
//             for (int j = i + i; j <= 1e7 + 10; j += i)
//             {
//                 is_prime[j] = 1;
//             }
//         }
//     }

//     //for finding primes in a single vector
//     for (int i = 0; i <= 1e7 + 10; i++)
//     {
//         if (is_prime[i] == 0)
//         {
//             primes.push_back(i);
//         }
//     }
//     for(int i = 0; i <= 100; i++){
//         cout << primes[i] << ' ';
//     }
//     return;
// }

void solve();

ll power(ll a, ll b)
{
    if (b == 0)
        return 1;
    ll res = power(a, b / 2);
    if (b % 2)
    {
        return res * res * a;
    }
    return res * res;
}

void divsprint(ll n)
{
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
            {
                cout << i << ' ';
            }
            else
            {
                cout << i << ' ' << n / i << ' ';
            }
        }
    }
}

int myGcd(int a, int b)
{
    if (b == 0)
    {
        return a;
    }
    return myGcd(a, a % b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // seive();
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++)
    {
        // cout<<"Case "<<i<<": ";
        solve();
    }
}

void solve()
{
    int n, k; cin >> n >> k;
    vector<int> vect(n); cinall(vect);
    int curr_sum = 0;
    for(int i = 0; i < k; i++){
        curr_sum += vect[i];
    }
    // cout << "->" << curr_sum << '\n';
    int l = 0, r = k - 1;
    int res = INT32_MAX;
    curr_sum = curr_sum - vect[l];
    curr_sum -= vect[r];
    if(k == 1){
        cout << *min_element(all(vect)) << '\n';
        return;
    }
    while(1){
        curr_sum += vect[l];
        curr_sum += vect[r];
        if(r == n)break;
        int lef = curr_sum;
        int rig = curr_sum;
        if(l > 0){
            lef += vect[l - 1];
            lef -= vect[l];
            
        }
        if(r < n - 1){
            rig += vect[r + 1];
            rig -= vect[r];
            
        }
        res = min(res, (min(lef, rig)));
        curr_sum = curr_sum - vect[l];
        curr_sum -= vect[r];
        l++; r++;
    }
    cout << res << '\n';
}

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 05:32:42
Judged At
2024-12-09 05:32:42
Judged By
Score
1
Total Time
33ms
Peak Memory
600.0 KiB