CSES - Datatähti 2015 loppu - Results
Submission details
Task:Urkupillit
Sender:PT
Submission time:2015-01-29 13:49:07 +0200
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:29:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < ss.str().size(); ++i) {
                    ^
input/code.cpp:30:15: error: no match for 'operator[]' (operand types are 'std::stringstream {aka std::basic_stringstream<char>}' and 'int')
     cout << ss[i] << " ";
               ^

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define N 100000
int n, k;
int t[N+1] = {0};
bool s[N+1] = {0};
deque<int> pre;
deque<int> post;

int main() {
  cin.sync_with_stdio(0);
  cin >> n >> k;
  for(int i = 1; i <= n; ++i) {
    t[i] = i;
  }
  int kk = k;
  for(int i = n; i >= 1; --i) {
    if(i - 1 <= kk) {
      pre.push_back(i);
      kk -= i - 1;
    } else {
      post.push_front(i);
    }
  }
  stringstream ss;
  for(int i : pre) ss << i;
  for(int i : post) ss << i;
  for(int i = 0; i < ss.str().size(); ++i) {
    cout << ss[i] << " ";
  }
  cout << "\n";
}