Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n, m, can[100500], prepare[10500];
- pair <int, int> mx[100500];
- bool check(int mid){
- int timer = 0;
- if(mx[m].first > mid){
- return 0;
- }
- for(int i = 1; i <= m; i++){
- timer += prepare[mx[i].second];
- cout << prepare[mx[i].second] << " ";
- cout << timer << endl;
- if(timer >= mx[i].first)
- return 0;
- else{
- timer++;
- }
- }
- if(timer <= mid){
- return 1;
- }
- else{
- return 0;
- }
- }
- int main(){
- cin >> n >> m;
- for(int i = 1; i <= n; i++){
- cin >> can[i];
- if(can[i] != 0){
- mx[can[i]].first = max(mx[can[i]].first, i);
- mx[can[i]].second = can[i];
- }
- }
- for(int i = 1; i <= m; i++){
- cin >> prepare[i];
- }
- sort(mx + 1, mx + m + 1);
- for(int i = 1; i <= m; i++){
- cout << mx[i].first << " " << mx[i].second << endl;
- }
- cout << endl;
- int l = 1;
- int r = n;
- while(r - l > 1){
- int mid = (l + r) / 2;
- cout << mid << "Den" << endl;
- if(check(mid)){
- r = mid;
- }
- else{
- l = mid;
- }
- }
- cout << endl;
- if (check(l)) cout << l;
- else if (check(r)) cout << r;
- else cout << "-1";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement