Advertisement
ismaeil

E1. Reading Books (easy version)

Jun 28th, 2020
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define T first
  5. #define A second.first
  6. #define B second.second
  7. typedef long long ll;
  8. typedef pair<int, int> ii;
  9.  
  10. const int N = 2e5 + 5e2;
  11. const ll INF = 10000000000;
  12.  
  13. vector<pair<int,ii>> v;
  14. int n ,k;
  15.  
  16. ll calc(int i ,bool canStop ,int Alice ,int Bob){
  17.     if( i == n ){
  18.         if( canStop ) return 0ll;
  19.         return INF;
  20.     }
  21.  
  22.     if( canStop ) return 0ll;
  23.     ll c1 = calc(i + 1 ,(Alice >= k && Bob >= k) ,Alice ,Bob);
  24.     ll c2 = calc(i + 1 ,(Alice + v[i].A) >= k && (Bob + v[i].B) >= k ,
  25.                          Alice + (v[i].A == 1) ,Bob + (v[i].B == 1) )
  26.                          + 1ll * v[i].T;
  27.  
  28.     return min(c1 ,c2);
  29. }
  30.  
  31. int main(){
  32.     scanf("%d%d" ,&n ,&k);
  33.     v.resize(n);
  34.     for(auto&i : v)
  35.         scanf("%d%d%d" ,&i.T ,&i.A ,&i.B);
  36.  
  37.     ll Ans = calc(0 ,0 ,0 ,0);
  38.     if( Ans == INF ) Ans = -1;
  39.     printf("%I64d\n" ,Ans);
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement