Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

problem 2823 help ~

Posted by okioki007 at 2008-08-06 17:32:12 on Problem 2823
I use set but TLE...

#include <iostream>
#include <set>

using namespace std;

int n, k;
int arr[1000001];
int max_[1000001];
int min_[1000001];

int main(){
	cin >> n >> k;
	set<int> m;
	for(int i = 0; i < k; i++){
		scanf("%d", &arr[i]);
		m.insert(arr[i]);
	}
	min_[0] = *(m.begin());
	max_[0] = *(m.rbegin());
	
	for(int i = k; i < n; i++){
		scanf("%d", &arr[i]);
		m.insert(arr[i]);
		m.erase(arr[i - k]);
		min_[i-k+1] = *(m.begin());
		max_[i-k+1] = *(m.rbegin());
	}

	for(int i = 0; i < n - k + 1; i++){
		cout << min_[i];
		if(i == n - k) continue;
		cout << " ";
	}
	cout << endl;
	for(int i = 0; i < n - k + 1; i++){
		cout << max_[i];
		if(i == n - k) continue;
		cout << " ";
	}
	cout << endl;

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator