#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int n,k;
vector<PII>ans;
PII v[2001],dp[2001][2001];
PII s(int i,int j){
if(dp[i][j].fi != -1)return dp[i][j];
dp[i][j] = s(i+1,j);
if(v[i].fi > j){
PII res = s(i+1,j+1);
res.fi++;
res.se+=v[i].se;
dp[i][j] = max(dp[i][j],res);
}
return dp[i][j];
}
void search(int i,int j,ll cnt,ll val){
if(sz(ans) == k)return;
if(i==n){
if(PII(cnt,val) < PII(0,0))ans.pb({cnt,val});
return;
}
if(s(i,j) < PII(cnt,val))return;
search(i+1,j,cnt,val);
if(v[i].fi > j)search(i+1,j+1,cnt-1,val-v[i].se);
}
int main()
{
cin>>n>>k;
for(int i=0;i<n;i++){
cin>>v[i].se>>v[i].fi;
v[i].se = 1e9-v[i].se;
}
sort(v,v+n);
//for(int i=0;i<n;i++)cout<<v[i].fi<<" "<<v[i].se<<'\n';
for(int i=0;i<n;i++)
for(int j=0;j<=n;j++)dp[i][j] = {-1,-1};
ll mxv = n * 1LL * 1e9 + 1;
ll l=0,r=n*mxv;
while(r>=l){
ll mid = (l+r)/2;
ll cnt = mid/mxv,val = mid%mxv;
ans.clear();
search(0,0,cnt,val);
//cout<<cnt<<" "<<val<<" "<<sz(ans)<<'\n';
if(sz(ans) >= k)l=mid+1;
else r=mid-1;
}
ll cnt = l/mxv,val = l%mxv;
ans.clear();
search(0,0,cnt,val);
while(sz(ans)<k)ans.pb({0,0});
sort(all(ans));
for(PII &x:ans){
x.fi = -x.fi + cnt;
x.se = x.fi * 1e9 + x.se - val;
}
for(auto x:ans)cout<<x.fi<<" "<<x.se<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5063 ms |
60628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5063 ms |
60628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
60640 KB |
Output is correct |
2 |
Correct |
61 ms |
63176 KB |
Output is correct |
3 |
Correct |
51 ms |
57972 KB |
Output is correct |
4 |
Correct |
50 ms |
57252 KB |
Output is correct |
5 |
Correct |
60 ms |
62540 KB |
Output is correct |
6 |
Correct |
24 ms |
57148 KB |
Output is correct |
7 |
Correct |
26 ms |
62816 KB |
Output is correct |
8 |
Correct |
23 ms |
58292 KB |
Output is correct |
9 |
Correct |
24 ms |
56916 KB |
Output is correct |
10 |
Correct |
30 ms |
59152 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
844 KB |
Output is correct |
2 |
Correct |
3 ms |
844 KB |
Output is correct |
3 |
Correct |
2 ms |
716 KB |
Output is correct |
4 |
Correct |
2 ms |
716 KB |
Output is correct |
5 |
Correct |
3 ms |
844 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
844 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5063 ms |
60628 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |