Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <sstream>
- #include <string>
- #include <iostream>
- #include <limits>
- #include <stdexcept>
- #include <unordered_set>
- #include <unordered_map>
- #include <vector>
- #include <string>
- #include <map>
- #include <set>
- #include <stack>
- #include <queue>
- #include <algorithm>
- #include <cstdlib>
- #include <numeric>
- #include <array>
- #include <iomanip> // std::setprecision
- #include <tuple>
- #include <iostream>
- #include <fstream>
- using namespace std;
- #define int int64_t
- int32_t main() { //== D. Planning
- /*
- https://codeforces.com/group/Ap6SQK7app/contest/303638/problem/D
- same as
- https://codeforces.com/group/Ap6SQK7app/contest/309423/problem/B
- https://codeforces.com/problemset/problem/853/a?locale=en
- greedy
- *1500
- */
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- int N, K;
- cin >> N >> K;
- vector< pair <int, int >> costPos(N, {-1,-1});
- set<int> delayTimeSlots;
- for( int i = 0; i < N; ++i) {
- int c;
- cin >> c;
- costPos[i] = { c, i }; //== delay_cost : original_index
- delayTimeSlots.insert(K+i);
- }
- sort( costPos.begin(), costPos.end(), greater<pair<int, int>>());
- int answer = 0;
- vector<int> reschedule(N, -1);
- for( int i = 0; i < N; ++i) { //== "i" is 0_based index
- int bestDelayTime = *delayTimeSlots.lower_bound(costPos[i].second);
- int currCost = costPos[i].first;
- answer += currCost * ( bestDelayTime - costPos[i].second );
- delayTimeSlots.erase(bestDelayTime);
- //== how to construct the reschedule sequence ??? such a MESS :(((
- reschedule[ costPos[i].second ] = bestDelayTime; //== 0_based index
- }
- cout << answer << endl;
- for( auto c: reschedule ){
- cout << c + 1 << " " ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment