Submission #37197574


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define p_qu priority_queue
#define p_qu_less priority_queue<int, vector<int>, greater<int> >
#define C_in(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define C_out(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "
#define SUM(a,n,sum) sum[0]=a[0];for(int i=1;i<n;i++) sum[i]=sum[i-1]+a[i];
#define SUM2(a,n,m,sum) sum[0][0]=a[0][0]; for(int i=0;i<n;i++) for(int j=0;j<m;j++) sum[i][j]=(i!=0?sum[i-1][j]:0)+(j!=0?sum[i][j-1]:0)+a[i][j]-(i!=0 && j!=0?sum[i-1][j-1]:0)
#define all(a) a.begin(),a.end()
#define l_b lower_bound
#define u_b upper_bound
#define pb push_back
#define max_3(a,b,c) max(max(a,b),c)
#define max_4(a,b,c,d) max(a,max_3(b,c,d))
#define min_3(a,b,c) min(min(a,b),c)
#define min_4(a,b,c,d) min(a,min_3(b,c,d))
#define zero(a) memset(a, 0, sizeof(a))
#define msit multiset<int>::iterator
#define setit set<int>::iterator
#define int long long
const int N=500005;
const int MAX=(1<<31)-1;
multiset<int> s,t;
int n,m,k;
int a[N];
int ans;
signed main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>m>>k;
	C_in(a,n);
	for(int i=0;i<m;i++)
	{
		t.insert(a[i]);
	}
	for(int i=0;i<k;i++)
	{
		s.insert(*t.begin());
		ans+=*t.begin();
		t.erase(t.begin());
	}
	cout<<ans<<" ";
	for(int i=1;i<=n-m;i++)
	{
		bool cc=false;
		if(a[i-1]>=*t.begin())
		{
			t.erase(t.find(a[i-1]));
		}
		else
		{
			s.erase(s.find(a[i-1]));
			ans-=a[i-1];
			cc=true;
		}
		int now=a[i+m-1];
		t.insert(now);
		if(cc)
		{
			s.insert(*t.begin());
			ans+=*t.begin();
			t.erase(t.begin());
		}
		else
		{
			if(*t.begin()<*s.rbegin())
			{
				ans-=*s.rbegin();
				ans+=*t.begin();
				msit j=s.end();
				j--;
				t.insert(*j);
				s.erase(j);
				msit i=t.begin();
				t.erase(i);
				s.insert(*i);
			}
		}
		cout<<ans<<" ";
	}
	return 0;
}

Submission Info

Submission Time
Task E - Least Elements
User Jack2022
Language C++ (GCC 9.2.1)
Score 0
Code Size 1887 Byte
Status TLE
Exec Time 2205 ms
Memory 14508 KiB

Compile Error

./Main.cpp:22:22: warning: integer overflow in expression of type ‘int’ results in ‘2147483647’ [-Woverflow]
   22 | const int MAX=(1<<31)-1;
      |               ~~~~~~~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 20
TLE × 1
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 3396 KiB
00_example_01.txt AC 3 ms 3512 KiB
01_max_00.txt AC 135 ms 14508 KiB
01_max_01.txt AC 174 ms 9684 KiB
02_min_00.txt AC 4 ms 3400 KiB
03_m_small_00.txt TLE 2205 ms 4856 KiB
04_random_00.txt AC 81 ms 4464 KiB
04_random_01.txt AC 136 ms 6724 KiB
04_random_02.txt AC 84 ms 6312 KiB
04_random_03.txt AC 128 ms 5744 KiB
04_random_04.txt AC 84 ms 9724 KiB
04_random_05.txt AC 116 ms 7308 KiB
04_random_06.txt AC 61 ms 7608 KiB
04_random_07.txt AC 146 ms 12408 KiB
04_random_08.txt AC 28 ms 5360 KiB
04_random_09.txt AC 19 ms 4256 KiB
04_random_10.txt AC 90 ms 9708 KiB
04_random_11.txt AC 58 ms 5752 KiB
04_random_12.txt AC 59 ms 4756 KiB
04_random_13.txt AC 66 ms 5484 KiB
04_random_14.txt AC 13 ms 3724 KiB