rembocoder

Untitled

Apr 26th, 2023
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <sstream>
  4. #include <string>
  5. #include <iostream>
  6. #include <limits>
  7. #include <stdexcept>
  8. #include <unordered_set>
  9. #include <unordered_map>
  10. #include <vector>
  11. #include <string>
  12. #include <map>
  13. #include <set>
  14. #include <stack>
  15. #include <queue>
  16. #include <algorithm>
  17. #include <cstdlib>
  18. #include <numeric>
  19. #include <array>
  20. #include <iomanip>      // std::setprecision
  21. #include <tuple>
  22. #include <iostream>
  23. #include <fstream>
  24.  
  25. using namespace std;
  26.  
  27. #define int int64_t
  28.  
  29. int32_t main() { //== D. Planning
  30.     /*
  31.      https://codeforces.com/group/Ap6SQK7app/contest/303638/problem/D
  32.      same as
  33.      https://codeforces.com/group/Ap6SQK7app/contest/309423/problem/B
  34.  
  35.      https://codeforces.com/problemset/problem/853/a?locale=en
  36.  
  37.      greedy
  38.      *1500
  39.  
  40.      */
  41.     ios_base::sync_with_stdio(false);
  42.     cin.tie(0); cout.tie(0);
  43.  
  44.     int N, K;
  45.     cin >> N >> K;
  46.     vector< pair <int, int >> costPos(N, {-1,-1});
  47.     set<int> delayTimeSlots;
  48.  
  49.     for( int i = 0; i < N; ++i) {
  50.         int c;
  51.         cin >> c;
  52.         costPos[i] = { c, i }; //== delay_cost : original_index
  53.         delayTimeSlots.insert(K+i);
  54.     }
  55.     sort( costPos.begin(), costPos.end(), greater<pair<int, int>>());
  56.     int answer = 0;
  57.     vector<int> reschedule(N, -1);
  58.  
  59.     for( int i = 0; i < N; ++i) {  //== "i" is 0_based index
  60.         int bestDelayTime = *delayTimeSlots.lower_bound(costPos[i].second);
  61.         int currCost = costPos[i].first;
  62.         answer += currCost * ( bestDelayTime - costPos[i].second );
  63.         delayTimeSlots.erase(bestDelayTime);
  64.  
  65.         //== how to construct the reschedule sequence ??? such a MESS :(((
  66.         reschedule[ costPos[i].second ] = bestDelayTime; //== 0_based index
  67.     }
  68.     cout << answer << endl;
  69.     for( auto c: reschedule ){
  70.         cout << c + 1 << " " ;
  71.     }
  72.     return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment