Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- using namespace std;
- ifstream fi("input.inp");
- ofstream fo("output.out");
- struct khach{
- int len;
- int xuong;
- };
- khach *a;
- int n, k, mexit = 0;
- void nhap(){
- fi >> n >> k;
- a = new khach[n];
- for(int i = 0; i < n; i++) fi >> a[i].len >> a[i].xuong;
- }
- void xuly(){
- int chua_soat = 0;
- for(int i = 0; i < n; i++){
- if(chua_soat >= a[i].xuong){
- mexit = mexit + a[i].xuong;
- chua_soat = chua_soat - a[i].xuong;
- }
- else{
- mexit = mexit + chua_soat;
- chua_soat = 0;
- }
- if(i % k == 0){
- chua_soat = 0;
- }
- else{
- chua_soat = chua_soat + a[i].len;
- }
- }
- }
- int main(){
- nhap();
- xuly();
- fo <<0 << " " <<mexit;
- delete []a;
- fi.close();
- fo.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement