Submission #575159

#TimeUsernameProblemLanguageResultExecution timeMemory
575159JANCARAPANStove (JOI18_stove)C++17
0 / 100
0 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define int long long #define F first #define S second #define vi vector<int> #define vvi vector<vi> #define pb push_back #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define read(a) for(auto &x:a) cin >> x; #define print(a) for(auto x:a) cout << x << " "; cout << "\n"; #define endl '\n' #define sz(x) (int)size(x) #define rsz(a,x) assign(a,x) const int INF = LLONG_MAX; const int MOD = 1000000007; const int MAXN = 100005; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin >> n >> k; multiset<int> m; vi a(n); for (int i=0; i<n; i++) cin >> a[i]; if (k == 1){ cout << a[n-1] << endl; return 0; } for (int i=1; i<n; i++){ if (m.size() < k-1) m.insert(a[i]-a[i-1]-1); else{ int dif = *(m.begin()); if ((a[i]-a[i-1]-1) > dif){ m.erase(0); m.insert(a[i]-a[i-1]-1); } } } int ans = 0; for (int i=1; i<n; i++){ ans++; if (m.count(a[i]-a[i-1]-1)){ m.erase(m.lower_bound(a[i]-a[i-1]-1)); } else { if (i == 1) ans++; ans += a[i]-a[i-1]-1; } } for (auto e : m){ a[n-1]-=e; } // cout << a[n-1] << endl; cout << ans+1 <<endl; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:40:22: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   40 |         if (m.size() < k-1) m.insert(a[i]-a[i-1]-1);
      |             ~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...