Advertisement
smatskevich

Lesson11

Dec 5th, 2020
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. bool IsCharLess(char a, char b) {
  7.   return a < b;
  8. }
  9.  
  10. // ABCDEFGabcdefg
  11. // Less
  12. // ab < ac
  13. // ab < ba
  14. // abb < ad
  15. // ab < abc
  16. // "" < "aa"
  17. // aa = aa
  18. bool LexCompare(const std::string& a, const std::string& b) {
  19.   int i = 0;
  20.   while (i < a.size() && i < b.size() && a[i] == b[i]) {
  21.     ++i;
  22.   }
  23.   if (i == b.size()) return false;
  24.   if (i == a.size()) return true;
  25.   return IsCharLess(a[i], b[i]);
  26. }
  27.  
  28. int main1() {
  29.   int n = 0;
  30.   std::cin >> n;
  31.   std::vector<std::string> strings(n);
  32.   for (int i = 0; i < n; ++i) {
  33.     std::cin >> strings[i];
  34.   }
  35.  
  36.   std::sort(strings.begin(), strings.end(), LexCompare);
  37.   for (const std::string& s: strings) {
  38.     std::cout << s << std::endl;
  39.   }
  40.   return 0;
  41. }
  42.  
  43.  
  44. struct Lesson {
  45.   int l;
  46.   int c;
  47. };
  48.  
  49. int main() {
  50.   int n, L;
  51.   std::cin >> n >> L;
  52.   std::vector<Lesson> v(n);
  53.   for (int i = 0; i < n; ++i) {
  54.     std::cin >> v[i].l;
  55.   }
  56.   for (int i = 0; i < n; ++i) {
  57.     std::cin >> v[i].c;
  58.   }
  59.  
  60.   std::string s = "sdfsdf";
  61.   std::sort(v.begin(), v.end(), [&s](const Lesson& a, const Lesson& b) -> bool {
  62.     std::cout << s << std::endl;
  63.     return a.c > b.c;
  64.   });
  65.  
  66.   int result = 0;
  67.   int l = 0;
  68.   int i = 0;
  69.   while (i < v.size() && l + v[i].l <= L) {
  70.     result += v[i].c * v[i].l;
  71.     l += v[i].l;
  72.     ++i;
  73.   }
  74.   if (i < v.size()) {
  75.     result += (L - l) * v[i].c;
  76.   }
  77.   std::cout << result;
  78.  
  79.   return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement