1804B - Vaccination - CodeForces Solution


greedy implementation

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define all(a) begin(a), end(a)
#define sort(a) sort(all(a))
 
void setIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


void solve(){
    int n, k, d, w;
    cin >> n >> k >> d >> w;
    int amt = 0;
    int start = -1e9;
    int left = 0;
    for(int i = 0; i < n; i++){
        int T;
        cin >> T;
        if(!left || T-start>d){
            // cout << i << " opened a new packet\n";
            amt++;
            start = T+w;
            left = k-1;
        } else {
            left--;
        }
    }
    cout << amt << "\n";
}


int t;
int main(){
    setIO();
    cin >> t;
    for(int i = 0; i < t; i++){
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

742A - Arpa’s hard exam and Mehrdad’s naive cheat
1492A - Three swimmers
1360E - Polygon
1517D - Explorer Space
1230B - Ania and Minimizing
1201A - Important Exam
676A - Nicholas and Permutation
431A - Black Square
474B - Worms
987B - High School Become Human
1223A - CME
1658B - Marin and Anti-coprime Permutation
14B - Young Photographer
143A - Help Vasilisa the Wise 2
320A - Magic Numbers
1658A - Marin and Photoshoot
514A - Chewbaсca and Number
382A - Ksenia and Pan Scales
734B - Anton and Digits
1080A - Petya and Origami
1642D - Repetitions Decoding
1440A - Buy the String
1658F - Juju and Binary String
478A - Initial Bet
981A - Antipalindrome
365A - Good Number
1204B - Mislove Has Lost an Array
1409D - Decrease the Sum of Digits
1476E - Pattern Matching
1107A - Digits Sequence Dividing