Editorial for Sử dụng Stand
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
\(\color{#ff0000}{\text{Spoiler Alert}_{{}_{{}^{{}^{v2.5}}}}}\)
\(\color{#ff0000}{\text{Khuyến khích bạn đọc trước khi đọc phần lời giải xin hãy thử code ra thuật của mình dù nó có sai hay đúng}}\)
\(\color{#ff0000}{\text{Sau đó từ phần bài giải và thuật toán trước đó mà đối chiếu, rút nhận xét với thuật của mình và thu được bài học (không lãng phí thời gian đâu).}}\)
\(\color{#ff0000}{\text{Mình xin rút kinh nghiệm và chấn chỉnh bản thân nếu trong editorial có gì sai sót, và bạn có thể gửi feedback }}\) ở đây
\(\color{#300000}{\text{Hint 1 <Tham lam>}}\)
Ta thấy để lượng chakra tiêu tốn là ít nhất thì ta phải ưu tiên những stand có C bé nhất nên ta sẽ sắp xếp theo C rồi sau đó tìm kiếm nhị phân.
Độ phức tạp thời gian tổng thể của cách này sẽ là O(n*log(n))
\(\color{#009933}{\text{Preference Accepted Code }}\):
C++
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
#define ii pair<ll,ll>
#define fs first
#define sc second
int n,m,vt=1;
ll a[N],ans=0;
ii b[N];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+1+n);
for(int i=1;i<=m;i++)cin>>b[i].sc>>b[i].fs;
sort(b+1,b+1+m);
for(int i=1;i<=m;i++)
{
if(b[i].sc>=a[n])
{
ans+=b[i].fs*(n-vt+1);
cout<<ans;
return 0;
}
int u=upper_bound(a+vt,a+n+1,b[i].sc)-a;
ans+=b[i].fs*(u-vt);
vt=u;
}
cout<<"bin9638 da mat Nezuko";
return 0;
}
Comments