Raslboyy

24.12.2010

Sep 22nd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <math.h>
  5. #include <algorithm>
  6. #define mp make_pair;
  7.  
  8. using namespace std;
  9.  
  10. typedef pair<int, int> pr;
  11.  
  12. int main() {
  13.     ifstream fin("input.txt");
  14.     ofstream fout("output.txt");
  15.  
  16.     int n;
  17.     fin >> n;
  18.     vector<pr> vec(n + 1);
  19.     vec[0] = make_pair(0, 1e9);
  20.     vector<pair<int, int>> dp(n + 1);
  21.     for (int i = 1; i <= n; i++) {
  22.         int a;
  23.         fin >> vec[i].first >> a;
  24.         vec[i].second = round(1000 * (double(a) / vec[i].first));
  25.  
  26.     }
  27.     dp[0] = make_pair(0, 1);
  28.     for (int i = 1; i <= n; i++) {
  29.         for (int j = 0; j < i; j++) {
  30.             if (vec[i].first > vec[j].first && vec[i].second < vec[j].second) {
  31.                 if (dp[j].first + 1 > dp[i].first) {
  32.                     dp[i].second = dp[j].second;
  33.                     dp[i].first = dp[j].first + 1;
  34.                 }
  35.                 else if (dp[j].first + 1 == dp[i].first) {
  36.                     dp[i].second += dp[j].second;
  37.                 }
  38.             }
  39.         }
  40.     }
  41.     int maxL = (*max_element(dp.begin(), dp.end())).first;
  42.     fout << maxL << endl;
  43.     int sum = 0;
  44.     for (pair<int, int> p: dp)
  45.         if (p.first == maxL)
  46.             sum += p.second;
  47.     fout << sum << endl;
  48.    
  49.     fin.close();
  50.     fout.close();
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment