제출 #798175

#제출 시각아이디문제언어결과실행 시간메모리
798175andecaandeciRabbit Carrot (LMIO19_triusis)C++17
100 / 100
23 ms4896 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pq priority_queue #define mp make_pair #define str string #define ll long long #define ii pair<int, int> #define pb push_back #define MOD 1000000007 using namespace std; // Feeling stuck? Scroll down for important points! Don't do nothing! // Don't forget to see constraints, and to comment the cin t if unneccessary // portal: lat soal osn 29 juli ben pres: rabbit carrot // solution idea: create b[i] = m*i - a[i] then find LIS, ans = n - LIS // why: we are finding the ones we don't need to change rather than the ones we need to change. // sample proof: 100 100 300 change middle lis is 100 300 const int N=2e5+5; int a[N], b[N], n, m; void solve() { cin >> n >> m; for (int i=1; i<=n; i++) cin >> a[i]; for (int i=1; i<=n; i++) b[i] = (m*i) - a[i]; vector<int> lis; for (int i=1; i<=n; i++) { if (b[i] < 0) continue; if (lis.empty() || lis.back() <= b[i]) lis.pb(b[i]); else { int l=0, r=lis.size()-1, res=0; while (l<=r) { int mid=(l+r)/2; if (lis[mid] > b[i]) { res=mid; r=mid-1; } else l=mid+1; } lis[res] = b[i]; } } cout << n-lis.size() << "\n"; } int main() { // your code goes here ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t=1; // comment below if no test cases! // cout << "INPUT T: " << endl; // cin>>t; while(t--) { solve(); } return 0; } // Remember to do easier subtasks for ALL problms // in IO when stuck for too long // Don't stare at the screen, nothing will come into your mind // Actively try to view problem from different perspectives // and or implement them quick if idea is doable
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...