Advertisement
aayyk

Untitled

Dec 10th, 2021
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <queue>
  7. #include <stack>
  8. #include <climits>
  9. #include <string>
  10. #include <set>
  11. #include <cmath>
  12. #include <map>
  13. #include <unordered_map>
  14. #include <numeric>
  15. #include <random>
  16. #include <memory>
  17. #include <chrono>
  18. #include <functional>
  19. #include <unordered_set>
  20. #include <cstring>
  21. #include <cassert>
  22. #include <bitset>
  23. #ifdef LOCAL
  24. #include "debug.h"
  25. #else
  26. #define debug(x...)
  27. #endif
  28. #define int ll
  29. //#pragma GCC optimize("Ofast")
  30.  
  31.  
  32. using namespace std;
  33. typedef long long ll;
  34. typedef long double ld;
  35. typedef pair <int, int> pii;
  36. typedef pair <ll, ll> pll;
  37. #define sz(x) int((x).size())
  38.  
  39. #ifndef LOCAL
  40.     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  41. #else
  42.     mt19937 rng(228);
  43. #endif
  44.  
  45. const int N = 1e2 + 7;
  46. const int inf = INT_MAX / 2;
  47. const ll INF = LLONG_MAX / 3;
  48. const int MOD = 998244353;
  49. const ld eps = 1e-6;
  50. const string cars[] = {"🚗", "🚕", "🚙"};
  51.  
  52. int dp[100 + 7][100 * 50 + 7];
  53. int l[5000 + 7], c[5000 + 7], n, k;
  54.  
  55.  
  56. signed main() {
  57. #ifdef LOCAL
  58.     freopen("input.txt", "r", stdin);
  59.     freopen("output.txt", "w", stdout);
  60. #endif
  61.     cout << fixed << setprecision(9);
  62.     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  63.  
  64.     cin >> n >> k;
  65.  
  66.     int len = 0;
  67.     for (int i = 1; i <= n; i++) {
  68.         cin >> l[i] >> c[i];
  69.         len += l[i];
  70.  
  71.         dp[c[i]][0] = 1;
  72.         for (int j = 100 * 50 + 6 - l[i]; j >= 0; j--) {
  73.             if (dp[c[i]][j] && !dp[c[i]][j + l[i]]) {
  74.                 dp[c[i]][j + l[i]] = i;
  75.             }
  76.         }
  77.     }
  78.     assert(len % k == 0);
  79.     len /= k;
  80.  
  81.     int s = -1;
  82.     for (int i = len - 1; i > 0; i--) {
  83.         bool flag = true;
  84.         for (int j = 1; j <= k; j++) {
  85.             if (!dp[j][i]) {
  86.                 flag = false;
  87.                 break;
  88.             }
  89.         }
  90.  
  91.         if (flag) {
  92.             s = len - i;
  93.             break;
  94.         }
  95.     }
  96.  
  97.     if (s == -1) {
  98.         return cout << "NO\n", 0;
  99.     }
  100.     cout << "YES\n";
  101.     for (int i = 1; i <= k; i++) {
  102.         int j = s;
  103.         while (j > 0) {
  104.             cout << dp[i][j] << " ";
  105.             j -= l[dp[i][j]];
  106.         }
  107.     }
  108.    
  109.     cout << endl;
  110.  
  111.     return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement