Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. //B8_b2_Soát vé
  2. #include<iostream>
  3. #include<fstream>
  4. using namespace std;
  5. ifstream fi("input.inp");
  6. ofstream fo("output.out");
  7.  
  8. struct khach{
  9.     int len;
  10.     int xuong;
  11. };
  12.  
  13. khach *a;
  14. int n, k, maxexit = 0, minexit = 0;
  15.  
  16. void nhap(){
  17.     fi >> n >> k;
  18.     a = new khach[n];
  19.     for(int  i = 0; i < n; i++) fi >> a[i].len >> a[i].xuong;
  20. }
  21.  
  22. void xuly(){
  23.     int chua_soat = 0;
  24.     for(int i = 0; i < n; i++){
  25.         if(chua_soat >= a[i].xuong){
  26.             maxexit = maxexit + a[i].xuong;
  27.             chua_soat = chua_soat - a[i].xuong;
  28.         }
  29.         else{
  30.             maxexit = maxexit + chua_soat;
  31.             minexit = minexit + a [i].xuong - chua_soat;
  32.             chua_soat = 0;
  33.         }
  34.         if(i % k == 0){
  35.             chua_soat = 0;
  36.         }
  37.         else{
  38.             chua_soat = chua_soat + a[i].len;
  39.         }
  40.     }
  41. }
  42.  
  43. int main(){
  44.     nhap();
  45.     xuly();
  46.     fo <<minexit << " " <<maxexit;
  47.     delete []a;
  48.     fi.close();
  49.     fo.close();
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement