This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> pi;
typedef pair<long double, long long> pii;
long long l, n, t, v;
int dp[501][501];
pi d[501];
pii a[501];
int lcs(int al, int bl){
if(al == 0 || bl == 0) return 0;
if(dp[al][bl] != -1) return dp[al][bl];
dp[al][bl] = max(lcs(al-1, bl), lcs(al, bl-1));
if(d[al-1].second == a[bl-1].second) dp[al][bl] = max(dp[al][bl], lcs(al, bl-1)+1);
return dp[al][bl];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(dp, -1, sizeof(dp));
cin >> l >> n;
for(int i = 0; i < n; i++){
cin >> t >> v;
d[i] = pi(t, i);
a[i] = pii((long double)t+((long double)l/(long double)v), i);
}
sort(d, d+n);
sort(a, a+n);
reverse(a, a+n);
cout << lcs(n, n);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |