Advertisement
_rashed

UVA 607

Feb 11th, 2023
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.92 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. /*
  6. Ordered set usage:
  7. order_of_key (k) : Number of items strictly smaller than k.
  8. find_by_order(k) : K-th element in a set (counting from zero).
  9. */
  10.  
  11. #include <ext/pb_ds/assoc_container.hpp>
  12. #include <ext/pb_ds/tree_policy.hpp>
  13. using namespace __gnu_pbds;
  14. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  15.  
  16. const int OO = 1e9;
  17. const double EPS = 1e-9;
  18.  
  19. pair<ll,ll> mem[1000][501];
  20. ll arr[1000],n,L,C;
  21.  
  22. pair<ll,ll> solve(int idx, int rem) {
  23.     if(idx == n) {
  24.         if(rem == L) {
  25.             return {0,0};
  26.         }
  27.         else {
  28.             return {1, (rem > 10  ? (rem-10)*(rem-10):(rem >= 1 ? -1*C:0))};
  29.         }
  30.     }
  31.     if(mem[idx][rem].first != -1) {
  32.         return mem[idx][rem];
  33.     }
  34.     pair<ll,ll> &ret = mem[idx][rem];
  35.     ret = {10000,1e9};
  36.     if(rem >= arr[idx]) {
  37.         ret = solve(idx+1,rem-arr[idx]);
  38.     }
  39.     if(rem < L) {
  40.         pair<ll,ll> ch = {1, (rem > 10  ? (rem-10)*(rem-10):(rem >= 1 ? -1*C:0))};
  41.         pair<ll,ll> nxt = solve(idx+1,L-arr[idx]);
  42.         ch.first += nxt.first;
  43.         ch.second += nxt.second;
  44.         if(ch < ret) {
  45.             ret = ch;
  46.         }
  47.     }
  48.     return ret;
  49. }
  50.  
  51. int main()
  52. {
  53.     ios_base::sync_with_stdio(NULL);
  54.     cin.tie(0);
  55.     ll ti = 0;
  56.     while(true) {
  57.         cin >> n;
  58.         if(!n)
  59.             break;
  60.         if(ti) {
  61.             cout << "\n";
  62.         }
  63.         ti++;
  64.         cin >> L >> C;
  65.         for(int i = 0; i < n; i++) {
  66.             cin >> arr[i];
  67.             for(int j = 0; j <= L; j++) {
  68.                 mem[i][j] = {-1,-1};
  69.             }
  70.         }
  71.         pair<ll,ll> ans = solve(0,L);
  72.         cout << "Case " << ti << ":\n";
  73.         cout << "Minimum number of lectures: " << ans.first << "\n";
  74.         cout << "Total dissatisfaction index: " << ans.second << "\n";
  75.     }
  76.     return 0;
  77. }
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement