# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1279376 | longlong5a6 | Fortune Telling 2 (JOI14_fortune_telling2) | C++20 | 3 ms | 832 KiB |
//longlong5a6
#include <bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define bit(i, x)((x >> i) & 1)
#define sobit(i) __builtin_popcount((int)(i))
#define sobitll(i) __builtin_popcountll((int)(i))
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define For(i,x,n) for(int (i)=(int)(x);(i)<=(int)(n);(i)++)
#define round(m,n) setprecision((int)m) << fixed << double(n)
#define down "\n"
#define TASK "domino"
#define int long long
#define maxn 200001
using namespace std;
int n,k;
pii a[maxn];
int t[maxn];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if (fopen("in.txt","r"))
{
freopen("in.txt","r",stdin);
}
if (fopen(TASK".INP","r"))
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
cin>>n>>k;
For(i,1,n)
{
cin>>a[i].F>>a[i].S;
}
For(i,1,k)
{
cin>>t[i];
}
if (n<=1000)
{
int res=0;
For(i,1,n)
{
int sta=0;
For(j,1,k)
{
int cur=(sta?a[i].S:a[i].F);
if (t[j]>=cur) sta=1ll-sta;
}
res+=(sta?a[i].S:a[i].F);
}
cout<<res<<down;
return 0;
}
int res=0;
vector<int> c;
For(i,1,k) c.pb(t[i]);
For(i,1,n)
{
int id1=lower_bound(all(c),a[i].F)-c.begin();
int id2=lower_bound(all(c),a[i].S)-c.begin();
if (id1<id2)
{
int cur=k-id2+1;
if (cur&1) res+=a[i].S;
else res+=a[i].F;
}
else
{
int cur=k-id1;
if (cur&1) res+=a[i].S;
else res+=a[i].F;
}
}
cout<<res;
}
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... |