Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
problem 2823 help ~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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator