# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
219078 | andreiomd | Fortune Telling 2 (JOI14_fortune_telling2) | C++11 | 5 ms | 384 KiB |
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 <iostream>
using namespace std;
typedef pair < int, int > PII;
const int NMAX = 2e5 + 5, KMAX = 2e5 + 5;
int N, K;
PII A[NMAX];
int T[KMAX];
static inline void Read ()
{
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> K;
for(int i = 1; i <= N; ++i)
cin >> A[i].first >> A[i].second;
for(int i = 1; i <= K; ++i)
cin >> T[i];
return;
}
static inline void Solve ()
{
long long ans = 0;
for(int i = 1; i <= N; ++i)
{
int Last_Index = 0;
int Min = min(A[i].first, A[i].second);
int Max = max(A[i].first, A[i].second);
for(int j = K; j >= 1 && !Last_Index; --j)
if(T[j] >= Min && T[j] < Max)
Last_Index = j;
if(Last_Index == K)
{
ans += 1LL * Max;
continue;
}
int cnt = 0;
for(int j = Last_Index + 1; j <= K; ++j)
if(T[j] >= Max)
swap(A[i].first, A[i].second);
ans += 1LL * A[i].first;
}
cout << ans << '\n';
return;
}
int main()
{
Read();
Solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |