Advertisement
askarulytarlan

Untitled

Mar 25th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n, m, can[100500], prepare[10500];
  4. pair <int, int> mx[100500];
  5. bool check(int mid){
  6. int timer = 0;
  7. if(mx[m].first > mid){
  8. return 0;
  9. }
  10. for(int i = 1; i <= m; i++){
  11. timer += prepare[mx[i].second];
  12. cout << prepare[mx[i].second] << " ";
  13. cout << timer << endl;
  14. if(timer >= mx[i].first)
  15. return 0;
  16. else{
  17. timer++;
  18. }
  19. }
  20. if(timer <= mid){
  21. return 1;
  22. }
  23. else{
  24. return 0;
  25. }
  26. }
  27. int main(){
  28. cin >> n >> m;
  29. for(int i = 1; i <= n; i++){
  30. cin >> can[i];
  31. if(can[i] != 0){
  32. mx[can[i]].first = max(mx[can[i]].first, i);
  33. mx[can[i]].second = can[i];
  34. }
  35. }
  36. for(int i = 1; i <= m; i++){
  37. cin >> prepare[i];
  38. }
  39. sort(mx + 1, mx + m + 1);
  40. for(int i = 1; i <= m; i++){
  41. cout << mx[i].first << " " << mx[i].second << endl;
  42. }
  43. cout << endl;
  44. int l = 1;
  45. int r = n;
  46. while(r - l > 1){
  47. int mid = (l + r) / 2;
  48. cout << mid << "Den" << endl;
  49. if(check(mid)){
  50. r = mid;
  51. }
  52. else{
  53. l = mid;
  54. }
  55. }
  56. cout << endl;
  57. if (check(l)) cout << l;
  58. else if (check(r)) cout << r;
  59. else cout << "-1";
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement