#include <bits/stdc++.h> using namespace std; #define ll long long int main() {…
- User
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); freopen("cau3.inp", "r", stdin); freopen("cau3.out", "w", stdout); ll n,m; cin >> n >> m; vector<pair<ll,ll>>a(m2); for(int i = 0;i < m2; i++){ cin >> a[i].first ; a[i].second = i; } vector<pair<ll,ll>>b(m2) ; for(int i = 0;i < m2; i++){ b[i].first = a[i].first; b[i].second = a[i].second; } sort(a.begin(),a.end(),greater<>());
ll res = 0; ll d = 0; for (int i = 0; i < m*2; i++) { res+=a[i].first; d++; if(a[i].second%2 != 0){ if(b[a[i].second-1].first < a[i].first){ res+=(n-d-1)*a[i].first + b[a[i].second-1].first ; }else res+=(n-d-1)*a[i].first; break; } } cout << res << "\n"; return 0; } giải thích ý nghĩa câu lệnh - Assistant