QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645304#6416. Classical Scheduling Problemucup-team073#RE 0ms3620kbC++204.2kb2024-10-16 17:37:402024-10-16 17:37:41

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 17:37:41]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3620kb
  • [2024-10-16 17:37:40]
  • 提交

answer

#include<bits/stdc++.h>
#ifdef LOCAL
#define debug(...) printf(__VA_ARGS__)
#define edebug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#define edebug(...)
#endif
#define int ll
#define rep(i, x, y) for(int i = x; i <= y; ++i)
#define nrep(i, x, y) for(int i = x; i >= y; --i)
#define ll long long
#define pii std::pair<int,int>
#define pb emplace_back
#define fi first
#define se second
template <class T> 
inline void ckmax(T &a, T b) {
  if(a < b) a = b;
}
template <class T> 
inline void ckmin(T &a, T b) {
  if(a > b) a = b;
}
auto rt_YES = []{puts("YES");};
auto rt_Yes = []{puts("Yes");};
auto rt_NO = []{puts("NO");};
auto rt_No = []{puts("No");};
namespace IO {
#define isdigit(x) (x >= '0' && x <= '9')
  inline char gc() {
    return getchar();
  }
  inline bool blank(char ch) {
    return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
  }
  template <class T>
  inline void read(T &x) {
    double tmp = 1;
    bool sign = 0;
    x = 0;
    char ch = gc();
    for(; !isdigit(ch); ch = gc())
      if(ch == '-') sign = 1;
    for(; isdigit(ch); ch = gc())
      x = x * 10 + (ch - '0');
    if(ch == '.')
      for(ch = gc(); isdigit(ch); ch = gc())
        tmp /= 10.0, x += tmp * (ch - '0');
    if(sign) x = -x;
  }
  inline void read(char *s) {
    char ch = gc();
    for(; blank(ch); ch = gc());
    for(; !blank(ch); ch = gc())
      *s++ = ch;
    *s = 0;
  }
  inline void read(char &c) {
    for(c = gc(); blank(c); c = gc());
  }
  inline void push(const char &c) {
    putchar(c);
  }
  template <class T>
  inline void print(T x) {
    if(x < 0) {
      x = -x;
      push('-');
    }
    static T sta[35];
    T top = 0;
    do {
      sta[top++] = x % 10;
      x /= 10;
    } while(x);
    while(top)
      push(sta[--top] + '0');
  }
  template <class T>
  inline void print(T x, char lastChar) {
    print(x);
    push(lastChar);
  }
}
using namespace IO;

struct node{
  int t,b,id;
  bool operator<(node B){return t<B.t;}
}a[200010];
int n,t;
int check(int k){
  std::vector<int>A,B;
  int cura=0,curb=0,sum=0;
  rep(i,1,n){
    if(a[i].b<=k)A.pb(a[i].t);else B.pb(a[i].t);
    if(i<=k){
      sum+=a[i].t;
      if(a[i].b<=k)++cura;
      else ++curb;
    }
  }debug("%lld %lld %lld %lld\n",k,sum,cura,curb);
  if(sum>t)return -1;
  rep(i,cura,A.size()-1){
    if(curb==0)return i;
    sum=sum+A[i]-B[curb-1];
    if(sum>t)return i;
    --curb;
  }
  if(sum<=t)return A.size();
}
void Print(int k){
  debug("%lld\n",k);
  std::vector<pii>A,B;std::vector<int>ans;
  int cura=0,curb=0,sum=0;
  rep(i,1,n){
    if(a[i].b<=k)A.pb(a[i].t,a[i].id);else B.pb(a[i].t,a[i].id);
    if(i<=k){
      sum+=a[i].t;
      if(a[i].b<=k)++cura;
      else ++curb;
    }
  }
  if(curb==0){
    rep(i,0,cura-1)ans.pb(A[i].second);
    std::sort(ans.begin(),ans.end());
    for(int i:ans)print(i,' ');
    puts("");
    return;
  }
  rep(i,cura,A.size()-1){
    sum=sum+A[i].first-B[curb-1].first;
    if(sum>t){
      rep(i,0,cura-1)ans.pb(A[i].second);
      rep(i,0,curb-1)ans.pb(B[i].second);
      break;
    }
    --curb;
    if(curb<=0)break;
  }
  debug("%lld\n",sum);
  if(sum<=t){
    for(auto i:A)ans.pb(i.second);
    rep(i,0,curb-1)ans.pb(B[i].second);
  }
  std::sort(ans.begin(),ans.end());
  for(int i:ans)print(i,' ');
  puts("");
}
void solve(){
  read(n),read(t);
  rep(i,1,n)read(a[i].t),read(a[i].b),a[i].id=i;
  std::sort(a+1,a+n+1);
  int l=0,r=n;
  while(r-l>=6){
    int midl=l+(r-l)/3,midr=r-(r-l)/3;
    if(check(midl)>=check(midr))r=midr;
    else l=midl;
  }
  int maxid=0,maxans=-1;
  rep(i,l,r){
    int t=check(i);
    // print(t,' ');
    if(t>maxans)maxans=t,maxid=i;
  }
  print(maxans,'\n'),print(maxid,'\n');
  Print(maxid);
  // puts("");
}

signed main() {
  clock_t c1 = clock();
#ifdef LOCAL
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
//------------------------------------------------------------------

  int t;read(t);while(t--)solve();

//------------------------------------------------------------------
end:
  std::cerr << "Time : " << clock() - c1 << " ms" << std::endl;
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3620kb

input:

2
4 100
20 1
40 4
60 3
30 3
1 5
10 1

output:

2
3
1 2 4 
0
0


result:

ok ok, 2 test cases (2 test cases)

Test #2:

score: -100
Runtime Error

input:

10000
21 1892
174 13
604 15
170 2
413 11
899 2
531 12
651 17
553 9
429 8
837 14
937 12
577 7
532 11
19 2
173 10
165 6
762 15
221 6
945 13
302 19
7 3
54 26066
812 31
432 24
240 37
171 39
204 47
174 30
569 1
467 5
624 42
734 35
907 3
568 23
802 40
991 32
119 13
187 27
739 42
891 14
550 44
374 16
483 1...

output:


result: