/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 30ms 604.0 KiB
#3 Accepted 58ms 888.0 KiB
#4 Accepted 84ms 824.0 KiB
#5 Accepted 84ms 796.0 KiB
#6 Accepted 122ms 1.676 MiB
#7 Wrong Answer 70ms 5.445 MiB
#8 Accepted 153ms 5.383 MiB
#9 Accepted 262ms 5.516 MiB
#10 Accepted 182ms 5.652 MiB
#11 Accepted 258ms 5.512 MiB
#12 Accepted 271ms 5.516 MiB

Code

//SUST_ZadeedBoss_Fanclub
//code_korlei_life_ase
//na_korle_lifeNai

#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T> using o_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define int long long
// #define double long double
// #define all(x) x.begin(), x.end()
// #define rall(x) x.rbegin(), x.rend()
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); 

void solve ()
{

	int n, k; cin >>n >>k;
	vector <int> v(n);
	for (auto &it : v) cin >>it;
	multiset <int> baire, vitore;
	int sum = 0;
	for (int i=0; i<k; i++) {vitore.insert(v[i]); sum += v[i];}
	for (int i=k; i<n; i++) baire.insert(v[i]);
	if (n == k)
	{
		cout <<sum <<"\n";
		return;
	}


	int ans = min(sum, sum - *vitore.rbegin() + *baire.begin());
	for (int i=k; i<n; i++)
	{
		int j = i-k;
		sum -= v[j]; sum += v[i];
		vitore.erase(vitore.lower_bound(v[j]));
		baire.insert(v[j]);
		baire.erase(baire.lower_bound(v[i]));
		vitore.insert(v[i]);

		ans = min(ans, min(sum, sum - *vitore.rbegin() + *baire.begin()));
	}
	cout <<ans <<"\n";


}

signed main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	int TCASE = 1;
	cin >> TCASE;

	for (int tcase = 1; tcase <= TCASE; tcase++)
	{
		// cout <<"Case #" <<tcase <<": ";
		solve();
	}

}

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:09:05
Judged At
2024-12-09 05:09:05
Judged By
Score
90
Total Time
271ms
Peak Memory
5.652 MiB