Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- /*
- Ordered set usage:
- order_of_key (k) : Number of items strictly smaller than k.
- find_by_order(k) : K-th element in a set (counting from zero).
- */
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace __gnu_pbds;
- #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
- const int OO = 1e9;
- const double EPS = 1e-9;
- pair<ll,ll> mem[1000][501];
- ll arr[1000],n,L,C;
- pair<ll,ll> solve(int idx, int rem) {
- if(idx == n) {
- if(rem == L) {
- return {0,0};
- }
- else {
- return {1, (rem > 10 ? (rem-10)*(rem-10):(rem >= 1 ? -1*C:0))};
- }
- }
- if(mem[idx][rem].first != -1) {
- return mem[idx][rem];
- }
- pair<ll,ll> &ret = mem[idx][rem];
- ret = {10000,1e9};
- if(rem >= arr[idx]) {
- ret = solve(idx+1,rem-arr[idx]);
- }
- if(rem < L) {
- pair<ll,ll> ch = {1, (rem > 10 ? (rem-10)*(rem-10):(rem >= 1 ? -1*C:0))};
- pair<ll,ll> nxt = solve(idx+1,L-arr[idx]);
- ch.first += nxt.first;
- ch.second += nxt.second;
- if(ch < ret) {
- ret = ch;
- }
- }
- return ret;
- }
- int main()
- {
- ios_base::sync_with_stdio(NULL);
- cin.tie(0);
- ll ti = 0;
- while(true) {
- cin >> n;
- if(!n)
- break;
- if(ti) {
- cout << "\n";
- }
- ti++;
- cin >> L >> C;
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- for(int j = 0; j <= L; j++) {
- mem[i][j] = {-1,-1};
- }
- }
- pair<ll,ll> ans = solve(0,L);
- cout << "Case " << ti << ":\n";
- cout << "Minimum number of lectures: " << ans.first << "\n";
- cout << "Total dissatisfaction index: " << ans.second << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement