Advertisement
soulseb

Untitled

Feb 4th, 2023
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool bestTime(const pair<long long,long long> &figure, const pair<long long,long long> &nextFigure) {
  6.     return figure.second < nextFigure.second;
  7. }
  8.  
  9. int main() {
  10.     long long number, idealWeight, timeRemaining;
  11.     cin >> number >> idealWeight >> timeRemaining;
  12.     vector<long long> timeFix(number);
  13.     long long weight;
  14.     for (long long i = 0; i < number; ++i) {
  15.         cin >> weight;
  16.         timeFix[i] = abs(idealWeight - weight);
  17.     }
  18.     vector<pair<long long, long long>> figures;
  19.     for (long long i = 0; i < number; ++i) figures.push_back(make_pair(i + 1, timeFix[i]));
  20.     sort(figures.begin(), figures.end(), bestTime);
  21.     vector<long long> bestFigures;
  22.     for (pair<long long, long long> figure: figures) {
  23.         timeRemaining -= figure.second;
  24.         if (timeRemaining >= 0) bestFigures.push_back(figure.first);
  25.     }
  26.     cout << bestFigures.size() << endl;
  27.     for (long long bestFigure: bestFigures) cout << bestFigure << ' ';
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement