Submission #557479

#TimeUsernameProblemLanguageResultExecution timeMemory
557479new_accAkcija (COCI21_akcija)C++14
90 / 110
518 ms524288 KiB
#include<bits/stdc++.h> #define fi first #define se second #define pitem item* using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; const int N=2e3+10; const int SS=1<<19; const int INFi=2e9; const ll INFl=1e13; const ll mod2=998244353; const ll mod=1e9+7; const ll mod3=1000696969; const ll p=70032301; const ull p2=913; const int L=20; vl dp[N][N]; pair<int,int> t[N]; vl comb(vl a,vl b){ int w1=0,w2=0; vl res; while(w1<a.size() and w2<b.size()){ if(a[w1]<b[w2]) res.push_back(a[w1]),w1++; else res.push_back(b[w2]),w2++; } for(int i=w1;i<a.size();i++) res.push_back(a[i]); for(int i=w2;i<b.size();i++) res.push_back(b[i]); return res; } void solve(){ int n,k; cin>>n>>k; for(int i=1;i<=n;i++) cin>>t[i].fi>>t[i].se; sort(t+1,t+1+n,[](pair<int,int> a,pair<int,int> b){ return a.se<b.se; }); dp[0][0].push_back(0); for(int i=1;i<=n;i++){ int aktsum=0; for(int j=max(0,t[i].se-i);j<=t[i].se;j++){ if(j-(t[i].se-t[i-1].se)+1<0) continue; if(j-(t[i].se-t[i-1].se)<0){ dp[i][j]=dp[i-1][j-(t[i].se-t[i-1].se)+1]; for(auto &u:dp[i][j]) u+=(ll)t[i].fi; }else{ vl pom=dp[i-1][j-(t[i].se-t[i-1].se)+1]; for(auto &u:pom) u+=(ll)t[i].fi; dp[i][j]=comb(dp[i-1][j-(t[i].se-t[i-1].se)],pom); } aktsum+=dp[i][j].size(); while(dp[i][j].size()>k) dp[i][j].pop_back(),aktsum--; } } int xd=0; for(int i=max(0,t[n].se-n);i<=t[n].se;i++){ for(auto u:dp[n][i]){ if(xd==k) break; cout<<t[n].se-i<<" "<<u<<"\n"; xd++; } } } int main(){ ios_base::sync_with_stdio(0),cin.tie(0); int tt=1; while(tt--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'vl comb(vl, vl)':
Main.cpp:25:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     while(w1<a.size() and w2<b.size()){
      |           ~~^~~~~~~~~
Main.cpp:25:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     while(w1<a.size() and w2<b.size()){
      |                           ~~^~~~~~~~~
Main.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=w1;i<a.size();i++) res.push_back(a[i]);
      |                  ~^~~~~~~~~
Main.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=w2;i<b.size();i++) res.push_back(b[i]);
      |                  ~^~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:54:34: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |             while(dp[i][j].size()>k) dp[i][j].pop_back(),aktsum--;
      |                   ~~~~~~~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...